diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/command.go | 6 | ||||
-rw-r--r-- | main/main_test.go | 19 |
2 files changed, 21 insertions, 4 deletions
diff --git a/main/command.go b/main/command.go index e795333..bbbb036 100644 --- a/main/command.go +++ b/main/command.go @@ -143,10 +143,14 @@ type FullMergeCommand struct { } func (cmd FullMergeCommand) exec(state *ProgramState) { _, notOk := runSubex(cmd.subex, state.value) - if notOk || state.end { + if notOk { state.pc++ return } + if !state.start { + state.pc += 2 + return + } for { item, err := state.Read() diff --git a/main/main_test.go b/main/main_test.go index 94e1f04..3d10c48 100644 --- a/main/main_test.go +++ b/main/main_test.go @@ -5,9 +5,10 @@ import ( "testing" ) -var miscInput string = `{"something":{"nested":"Here is my test value"},"array":["Hello","world","these","are","values"],"people":[{"first_name":"Charlie","last_name":"Johnson","age":22},{"first_name":"Tom","last_name":"Johnson","age":18},{"first_name":"Charlie","last_name":"Chaplin","age":122},{"first_name":"John","last_name":"Johnson","age":48}]}` +const miscInput string = `{"something":{"nested":"Here is my test value"},"array":["Hello","world","these","are","values"],"people":[{"first_name":"Charlie","last_name":"Johnson","age":22},{"first_name":"Tom","last_name":"Johnson","age":18},{"first_name":"Charlie","last_name":"Chaplin","age":122},{"first_name":"John","last_name":"Johnson","age":48}]}` +const mixedArray string = `{"array":["first",{"name":"second"},"third"]}` -func TestMain(t *testing.T) { +func TestSpecificCases(t *testing.T) { type test struct { name string program string @@ -102,7 +103,7 @@ func TestMain(t *testing.T) { }, { name: "Short concat array values", - program: "M/#( \"array\" :(): )#/{ s/#( \"array\"$_ :( .{-0} )- )-/ s/-( ~(.{-0}` `)-{-0} ~(.{-0})- )~/p }", + program: "M/#( \"array\" :(): )#/{ s/#( \"array\"$_ :( .{-0} )- )-/ s/-( ~(.{-0}` `)-{-0} ~(.{-0})- )~/p }", quiet: true, input: miscInput, expected: `"Hello world these are values"`, @@ -120,6 +121,18 @@ func TestMain(t *testing.T) { expected: `{"something":{"nested":"Here is my test value"},"array":["Hello","world","these","are","values"],"people":[{"first_name":"Charlie","last_name":"Johnson","age":22},{"first_name":"Tom","last_name":"Johnson","age":18},{"first_name":"Charlie","last_name":"Chaplin","age":122}]}`, }, { + name: "Drop last element of simple array", + program: `s/#( "array" @( . . )@ )#/{ Ed }`, + input: miscInput, + expected: `{"something":{"nested":"Here is my test value"},"array":["Hello","world","these","are"],"people":[{"first_name":"Charlie","last_name":"Johnson","age":22},{"first_name":"Tom","last_name":"Johnson","age":18},{"first_name":"Charlie","last_name":"Chaplin","age":122},{"first_name":"John","last_name":"Johnson","age":48}]}`, + }, + { + name: "Drop last element of mixed array", + program: `M/#( "array" @( . (~[.]~|@()@|#()#) )@ )#/{ Ed }`, + input: mixedArray, + expected: `{"array":["first",{"name":"second"}]}`, + }, + { name: "Prepend to array", program: "as/#( \"array\" :( `\"First\"` ): )#/", input: miscInput, |