diff options
Diffstat (limited to 'subex/main_test.go')
-rw-r--r-- | subex/main_test.go | 238 |
1 files changed, 237 insertions, 1 deletions
diff --git a/subex/main_test.go b/subex/main_test.go index 78a62c4..fb6f152 100644 --- a/subex/main_test.go +++ b/subex/main_test.go @@ -61,6 +61,15 @@ func TestSubexMain(t *testing.T) { }, }, { + subex: `~(.)~`, + input: []walk.Value { + walk.StringValue("a"), + }, + expected: []walk.Value { + walk.StringValue("a"), + }, + }, + { subex: `~(.$_(.{-0}))~`, input: []walk.Value { walk.StringValue("hello"), @@ -70,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 { @@ -182,9 +206,221 @@ func TestSubexMain(t *testing.T) { }, }, }, + { + subex: "-(`0`.)@", + input: []walk.Value { + walk.NumberValue(4), + }, + expected: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.NumberValue(4), + }, + }, + }, + }, + { + subex: `@(.$_~(.{-0})-{-0})~`, + input: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.StringValue("ab"), + }, + { + Index: 1, + Value: walk.StringValue("cd"), + }, + { + Index: 2, + Value: walk.StringValue("efg"), + }, + { + Index: 3, + Value: walk.StringValue(""), + }, + { + Index: 4, + Value: walk.StringValue("hijklm"), + }, + }, + }, + expected: []walk.Value { + walk.StringValue("abcdefghijklm"), + }, + }, + { + subex: ":(.)-", + input: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.NullValue{}, + }, + }, + }, + expected: []walk.Value { + walk.NullValue{}, + }, + }, + { + subex: ":(.{-0}+)-", + input: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.NumberValue(4), + }, + { + Index: 1, + Value: walk.NumberValue(-123), + }, + { + Index: 2, + Value: walk.NumberValue(124), + }, + }, + }, + expected: []walk.Value { + walk.NumberValue(5), + }, + }, + { + subex: "~(-(.)~{-0}):", + input: []walk.Value { + walk.StringValue("abc"), + }, + expected: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.StringValue("a"), + }, + { + Index: 0, + Value: walk.StringValue("b"), + }, + { + Index: 0, + Value: walk.StringValue("c"), + }, + }, + }, + }, + { + subex: "#(.(.$_){-0}):", + input: []walk.Value { + walk.MapValue { + { + Key: "a", + Value: walk.NullValue{}, + }, + { + Key: "b", + Value: walk.NumberValue(4), + }, + { + Key: "c", + Value: walk.StringValue("hello"), + }, + }, + }, + expected: []walk.Value { + walk.ArrayValue { + { + Index: 0, + Value: walk.StringValue("a"), + }, + { + Index: 0, + Value: walk.StringValue("b"), + }, + { + Index: 0, + Value: walk.StringValue("c"), + }, + }, + }, + }, + { + 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{}, + }, + }, + }, + }, + { + subex: ".{-0}`\"hello\"`", + input: []walk.Value { + walk.NumberValue(1), + walk.NumberValue(2), + }, + expected: []walk.Value { + walk.NumberValue(1), + walk.NumberValue(2), + walk.StringValue("hello"), + }, + }, } - for _, test := range tests { + for i, test := range tests { + t.Logf("Running test: %d", i) lexer := NewStringRuneReader(test.subex) ast := Parse(lexer) transducer := CompileTransducer(ast) |