<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/main_test.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-03-31 21:23:17 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2024-03-31 21:23:17 +0100
commit81925b6ad5212512d27365b8224b76095191431f (patch)
treef625a8eddb556a58c45c7e16a205df1ed6b92d3a /subex/main_test.go
parent256450cc3dcdd9a9b92a33642739f7143526e9b9 (diff)
downloadstred-go-81925b6ad5212512d27365b8224b76095191431f.tar
Add " shorthand for string destructure
Diffstat (limited to 'subex/main_test.go')
-rw-r--r--subex/main_test.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/subex/main_test.go b/subex/main_test.go
index 9c1819a..8e98798 100644
--- a/subex/main_test.go
+++ b/subex/main_test.go
@@ -79,6 +79,21 @@ func TestSubexMain(t *testing.T) {
},
},
{
+ subex: `#(".".{-0})-`,
+ input: []walk.Value {
+ walk.MapValue {
+ {
+ Key: "a",
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ expected: []walk.Value {
+ walk.StringValue("a"),
+ walk.NullValue{},
+ },
+ },
+ {
subex: "@(..$a`$a$a`{-0})@",
input: []walk.Value {
walk.ArrayValue {
@@ -328,6 +343,68 @@ func TestSubexMain(t *testing.T) {
},
},
},
+ {
+ subex: ":(.`null`{-0})#",
+ input: []walk.Value {
+ walk.ArrayValue {
+ {
+ Index: 0,
+ Value: walk.StringValue("a"),
+ },
+ {
+ Index: 1,
+ Value: walk.StringValue("b"),
+ },
+ {
+ Index: 2,
+ Value: walk.StringValue("c"),
+ },
+ },
+ },
+ expected: []walk.Value {
+ walk.MapValue {
+ {
+ Key: "a",
+ Value: walk.NullValue{},
+ },
+ {
+ Key: "b",
+ Value: walk.NullValue{},
+ },
+ {
+ Key: "c",
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ },
+ {
+ subex: `#(".$_(.{-0})".{-0})#`,
+ input: []walk.Value {
+ walk.MapValue {
+ {
+ Key: "hello",
+ Value: walk.NullValue{},
+ },
+ {
+ Key: "world",
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ expected: []walk.Value {
+ walk.MapValue {
+ {
+ Key: "ello",
+ Value: walk.NullValue{},
+ },
+ {
+ Key: "orld",
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ },
}
for i, test := range tests {