From 22ccb0c370cf2690f1b1a80fe003e05c6ba5e5ed Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Thu, 2 May 2024 21:34:53 +0100 Subject: Fix FullMerge command so it can work on non-structure values --- main/main_test.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'main/main_test.go') 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"`, @@ -119,6 +120,18 @@ func TestMain(t *testing.T) { input: miscInput, 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\"` ): )#/", -- cgit v1.2.3