<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/main_test.go
blob: a7a7795d077229009a5ed9fbc2fc04b89f8453b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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())
		}
	}
}