<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/main_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'main/main_test.go')
-rw-r--r--main/main_test.go19
1 files changed, 16 insertions, 3 deletions
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,