<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/main_test.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-03-30 22:15:57 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2024-03-30 22:15:57 +0000
commit256450cc3dcdd9a9b92a33642739f7143526e9b9 (patch)
tree149e1e681a5834187c395fb3b13e45291fce0828 /main/main_test.go
parentfd79fd18c6c32884e757e91b8629c87af4cbf34e (diff)
downloadstred-go-256450cc3dcdd9a9b92a33642739f7143526e9b9.tar
Add main tests
Diffstat (limited to 'main/main_test.go')
-rw-r--r--main/main_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/main/main_test.go b/main/main_test.go
new file mode 100644
index 0000000..a7a7795
--- /dev/null
+++ b/main/main_test.go
@@ -0,0 +1,40 @@
+package main
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestMain(t *testing.T) {
+ type test struct {
+ program string
+ quiet bool
+ input string
+ expected string
+ }
+
+ tests := []test {
+ {
+ 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}]}`,
+ expected: `"Tom"`,
+ },
+ }
+
+ for i, test := range tests {
+ t.Logf("Running test: %d", i)
+
+ var output strings.Builder
+ run(config {
+ quiet: test.quiet,
+ program: test.program,
+ in: strings.NewReader(test.input),
+ out: &output,
+ })
+
+ if output.String() != test.expected {
+ t.Errorf("Ran '%s' and expected %s but got %s", test.program, test.expected, output.String())
+ }
+ }
+}