From 9d82785f46949151b783d83648b39ce9ba40c615 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 30 Mar 2024 09:42:00 +0000 Subject: Add none structures and allow mismatched destructuring --- subex/main_test.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'subex/main_test.go') diff --git a/subex/main_test.go b/subex/main_test.go index 78a62c4..d7424b3 100644 --- a/subex/main_test.go +++ b/subex/main_test.go @@ -60,6 +60,15 @@ func TestSubexMain(t *testing.T) { }}, }, }, + { + subex: `~(.)~`, + input: []walk.Value { + walk.StringValue("a"), + }, + expected: []walk.Value { + walk.StringValue("a"), + }, + }, { subex: `~(.$_(.{-0}))~`, input: []walk.Value { @@ -182,9 +191,54 @@ 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"), + }, + }, } - 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) -- cgit v1.2.3