diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-21 17:16:01 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2024-04-21 17:16:01 +0100 |
commit | 1e66aaece6ea7cd3c705ca56ce5558e8f87681b8 (patch) | |
tree | 2fff87e4abfb0727e028854c006577eccfeee370 /main/main_test.go | |
parent | 7162ae8c641314846f0b565d7614ac8d71dbd628 (diff) | |
download | stred-go-1e66aaece6ea7cd3c705ca56ce5558e8f87681b8.tar |
Add substitute next commands
Diffstat (limited to 'main/main_test.go')
-rw-r--r-- | main/main_test.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/main/main_test.go b/main/main_test.go index 74f179b..be439a3 100644 --- a/main/main_test.go +++ b/main/main_test.go @@ -9,6 +9,7 @@ var miscInput string = `{"something":{"nested":"Here is my test value"},"array": func TestMain(t *testing.T) { type test struct { + name string program string quiet bool input string @@ -17,62 +18,78 @@ func TestMain(t *testing.T) { tests := []test { { + name: "Verbose Extract", program: `s/#(~(people)~$_@(1$_#(~(first_name)~$_.|(..$_){-0})-|(..$_){-0})-|(..$_){-0})-/p`, quiet: true, input: miscInput, expected: `"Tom"`, }, { + name: "Extract", program: `s/#("people"$_ @(1 $_#("first_name"$_ .)-)-)-/p`, quiet: true, input: miscInput, expected: `"Tom"`, }, { + name: "Simple Extract", program: "s/#(\"people\" @(1 #(\"first_name\" (.$a))-)-)-$_ `$a`/p", quiet: true, input: miscInput, expected: `"Tom"`, }, { + name: "Larger Extract", program: "s/#(\"people\" @(2 (.$a))-)-$_ `$a`/p", quiet: true, input: miscInput, expected: `{"first_name":"Charlie","last_name":"Chaplin","age":122}`, }, { + name: "Extract ages", program: "s/#(\"people\"$_ :(#(\"age\"$_ .)-):)-/p", quiet: true, input: miscInput, expected: `[22,18,122,48]`, }, { + name: "Low memory count people", program: "aX/#(\"people\" :(#()#):)#$_ `1`/o es/#()#/{ xs/.{-0}+/p }", quiet: true, input: miscInput, expected: "4", }, { + name: "Get full names", 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"]`, }, { + name: "Get full names 2", 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"]`, }, { + name: "Change full names in place", program: "s/#(\"people\" @(. #(\"first_name\" .)#)@)#/{ ms/#(\"people\" @(. (#(\"first_name\" \".{-0}$a\" \"last_name\" \".{-0}$b\")#$_) `#(\"name\" \"$a $b\")#`)@)#/ }", input: miscInput, expected: `{"something":{"nested":"Here is my test value"},"array":["Hello","world","these","are","values"],"people":[{"name":"Charlie Johnson","age":22},{"name":"Tom Johnson","age":18},{"name":"Charlie Chaplin","age":122},{"name":"John Johnson","age":48}]}`, }, + { + name: "Get full names with substitute next command", + program: "s/#( \"people\"$_ :( #( \"first_name\"$_ . )- )- )-/{ N/#( \"people\"$_ :( #( \"last_name\"$_ . )- )- )-/{ s/-( -( ~(.{-0}` `)- ~(.{-0})- )~ ):/p }}", + quiet: true, + input: miscInput, + expected: `["Charlie Johnson","Tom Johnson","Charlie Chaplin","John Johnson"]`, + }, } - for i, test := range tests { - t.Logf("Running test: %d", i) + for _, test := range tests { + t.Logf("Running test: %s", test.name) var output strings.Builder run(config { |