diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 15:27:36 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-07 15:27:36 +0100 |
commit | 658900fcae610caace83a112ac0ee865108ebc92 (patch) | |
tree | 4d7b6bebe0d192abf62970ca4324ef1ff274e3c8 /main/main_test.go | |
parent | 81925b6ad5212512d27365b8224b76095191431f (diff) | |
download | stred-go-658900fcae610caace83a112ac0ee865108ebc92.tar |
Change output subex internals to allow structures
Also add substitute register syntactic sugar
Diffstat (limited to 'main/main_test.go')
-rw-r--r-- | main/main_test.go | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/main/main_test.go b/main/main_test.go index a7a7795..7aa90aa 100644 --- a/main/main_test.go +++ b/main/main_test.go @@ -5,6 +5,8 @@ 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}]}` + func TestMain(t *testing.T) { type test struct { program string @@ -17,9 +19,51 @@ func TestMain(t *testing.T) { { program: `s/#(~(people)~$_@(1$_#(~(first_name)~$_.|(..$_){-0})-|(..$_){-0})-|(..$_){-0})-/p`, quiet: true, - input: `{"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}]}`, + input: miscInput, + expected: `"Tom"`, + }, + { + program: `s/#("people"$_ @(1 $_#("first_name"$_ .)-)-)-/p`, + quiet: true, + input: miscInput, + expected: `"Tom"`, + }, + { + program: "s/#(\"people\" @(1 #(\"first_name\" (.$a))-)-)-$_ `$a`/p", + quiet: true, + input: miscInput, expected: `"Tom"`, }, + { + program: "s/#(\"people\" @(2 (.$a))-)-$_ `$a`/p", + quiet: true, + input: miscInput, + expected: `{"first_name":"Charlie","last_name":"Chaplin","age":122}`, + }, + { + program: "s/#(\"people\"$_ :(#(\"age\"$_ .)-):)-/p", + quiet: true, + input: miscInput, + expected: `[22,18,122,48]`, + }, + { + program: "aX/#(\"people\" :(#()#):)#$_ `1`/o es/#()#/{ xs/.{-0}+/p }", + quiet: true, + input: miscInput, + expected: "4", + }, + { + program: "s/#(\"people\"$_ .)-/{ s/:():/p as/:(#()#):/{ xdx } s/:(#((\"first_name\" | \"last_name\") .)#)-/X es/@(.#()-)-/{ xs/(#(\"first_name\" \".{-0}$a\")# | #(\"last_name\" \".{-0}$b\")# | .){-0}$_ `\"$a $b\"`/Xxs/-(..)@/p } }", + quiet: true, + input: miscInput, + expected: `["Charlie Johnson","Tom Johnson","Charlie Chaplin","John Johnson"]`, + }, + { + program: "s/#(\"people\"$_ .)-/{ s/:():/p as/:(#()#):/{ xdx } X/:(#((\"first_name\" | \"last_name\") .)#)-/o es/@(.#()-)-/{ xX/(#(\"first_name\" \".{-0}$a\")# | #(\"last_name\" \".{-0}$b\")# | .){-0}$_ `\"$a $b\"`/xs/-(..)@/p } }", + quiet: true, + input: miscInput, + expected: `["Charlie Johnson","Tom Johnson","Charlie Chaplin","John Johnson"]`, + }, } for i, test := range tests { |