diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:35:31 -0500 |
commit | 9c17b97cd0f83be3fff9fa4e87fd1d29052ea616 (patch) | |
tree | 0d97030a0d0c3ad983be281ce89f80571338887f /internal/cpe/token_test.go | |
parent | 92400d731546557d110c9c3cc3906d700f83dda8 (diff) | |
download | cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.tar.bz2 cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.zip |
rename to github.com/pablotron/cvez, remove internal libs
Diffstat (limited to 'internal/cpe/token_test.go')
-rw-r--r-- | internal/cpe/token_test.go | 149 |
1 files changed, 0 insertions, 149 deletions
diff --git a/internal/cpe/token_test.go b/internal/cpe/token_test.go deleted file mode 100644 index 595df2c..0000000 --- a/internal/cpe/token_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package cpe - -import ( - "reflect" - "testing" -) - -func TestTokenTypeString(t *testing.T) { - tests := []struct { - val tokenType - exp string - } { - { anyToken, "any" }, - { naToken, "na" }, - { valToken, "val" }, - { tokenType(255), "tokenType(255)" }, - } - - for _, test := range(tests) { - t.Run(test.exp, func(t *testing.T) { - got := test.val.String() - if got != test.exp { - t.Errorf("got \"%s\", exp \"%s\"", got, test.exp) - } - }) - } -} - -func TestNewToken(t *testing.T) { - passTests := []struct { - name string - val string - exp token - } { - { "any", "*", token { Type: anyToken } }, - { "na", "-", token { Type: naToken } }, - { "empty", "", token { Type: valToken } }, - { "foo", "foo", token { Type: valToken, Val: "foo" } }, - } - - for _, test := range(passTests) { - t.Run(test.name, func(t *testing.T) { - got := newToken([]byte(test.val)) - if got.Type != test.exp.Type { - t.Errorf("token: got %s, exp %s", got.Type, test.exp.Type) - } else if got.Type == valToken && got.Val != test.exp.Val { - t.Errorf("value: got \"%s\", exp \"%s\"", got.Val, test.exp.Val) - } - }) - } -} - -func TestTokenize(t *testing.T) { - passTests := []struct { - val string - exp []token - } {{ - val: "foo", - exp: []token { token { Type: valToken, Val: "foo" } }, - }, { - val: "foo:bar", - exp: []token { - token { Type: valToken, Val: "foo" }, - token { Type: valToken, Val: "bar" }, - }, - }, { - val: "*", - exp: []token { token { Type: anyToken } }, - }, { - val: "-", - exp: []token { token { Type: naToken } }, - }, { - val: "*:bar", - exp: []token { - token { Type: anyToken }, - token { Type: valToken, Val: "bar" }, - }, - }, { - val: "foo:*", - exp: []token { - token { Type: valToken, Val: "foo" }, - token { Type: anyToken }, - }, - }, { - val: "-:bar", - exp: []token { - token { Type: naToken }, - token { Type: valToken, Val: "bar" }, - }, - }, { - val: "foo:-", - exp: []token { - token { Type: valToken, Val: "foo" }, - token { Type: naToken }, - }, - }, { - val: "foo\\*:-", - exp: []token { - token { Type: valToken, Val: "foo*" }, - token { Type: naToken }, - }, - }} - - for _, test := range(passTests) { - t.Run(test.val, func(t *testing.T) { - // tokenize, check for error - got, err := tokenize([]byte(test.val)) - if err != nil { - t.Error(err) - return - } - - if !reflect.DeepEqual(got, test.exp) { - t.Errorf("token: got %v, exp %v", got, test.exp) - return - } - }) - } - - failTests := []struct { - id string - val string - exp string - } {{ - id: "invalid escape", - val: "foo\\.", - exp: "invalid escape byte: 0x2e", - }, { - id: "invalid byte", - val: "\n", - exp: "invalid byte: 0x0a", - }, { - id: "unterminated escape", - val: "\\", - exp: "unterminated escape at end of buffer", - }} - - for _, test := range(failTests) { - t.Run(test.id, func(t *testing.T) { - // tokenize, check for error - got, err := tokenize([]byte(test.val)) - if err == nil { - t.Errorf("got %v, exp error", got) - } else if err.Error() != test.exp { - t.Errorf("got \"%s\", exp \"%s\"", err.Error(), test.exp) - } - }) - } -} |