aboutsummaryrefslogtreecommitdiff
path: root/cpe/part_test.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-04 00:35:31 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-04 00:35:31 -0500
commit9c17b97cd0f83be3fff9fa4e87fd1d29052ea616 (patch)
tree0d97030a0d0c3ad983be281ce89f80571338887f /cpe/part_test.go
parent92400d731546557d110c9c3cc3906d700f83dda8 (diff)
downloadcvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.tar.bz2
cvez-9c17b97cd0f83be3fff9fa4e87fd1d29052ea616.zip
rename to github.com/pablotron/cvez, remove internal libs
Diffstat (limited to 'cpe/part_test.go')
-rw-r--r--cpe/part_test.go108
1 files changed, 108 insertions, 0 deletions
diff --git a/cpe/part_test.go b/cpe/part_test.go
new file mode 100644
index 0000000..269d16e
--- /dev/null
+++ b/cpe/part_test.go
@@ -0,0 +1,108 @@
+package cpe
+
+import (
+ "testing"
+)
+
+func TestNewPart(t *testing.T) {
+ passTests := []struct {
+ name string
+ val token
+ exp Part
+ } {{
+ name: "any",
+ val: token { Type: anyToken },
+ exp: AnyPart,
+ }, {
+ name: "na",
+ val: token { Type: naToken },
+ exp: NAPart,
+ }, {
+ name: "a",
+ val: token { Type: valToken, Val: "a" },
+ exp: ApplicationPart,
+ }, {
+ name: "h",
+ val: token { Type: valToken, Val: "h" },
+ exp: HardwarePart,
+ }, {
+ name: "o",
+ val: token { Type: valToken, Val: "o" },
+ exp: OperatingSystemPart,
+ }}
+
+ for _, test := range(passTests) {
+ t.Run(test.name, func(t *testing.T) {
+ if got, err := newPart(test.val); err != nil {
+ t.Error(err)
+ } else if got != test.exp {
+ t.Errorf("got %s, exp %s", got, test.exp)
+ }
+ })
+ }
+
+ failTests := []struct {
+ name string
+ val token
+ exp string
+ } {{
+ name: "invalid token",
+ val: token { Type: valToken, Val: "foo" },
+ exp: "unknown part: \"foo\"",
+ }, {
+ name: "empty token",
+ val: token { Type: valToken },
+ exp: "unknown part: \"\"",
+ }, {
+ name: "unknown token type",
+ val: token { Type: tokenType(255) },
+ exp: "unknown token type: 0xff",
+ }}
+
+ for _, test := range(failTests) {
+ t.Run(test.name, func(t *testing.T) {
+ // tokenize, check for error
+ got, err := newPart(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)
+ }
+ })
+ }
+}
+
+func TestPartString(t *testing.T) {
+ tests := []struct {
+ val Part
+ exp string
+ } {{
+ val: AnyPart,
+ exp: "*",
+ }, {
+ val: NAPart,
+ exp: "-",
+ }, {
+ val: ApplicationPart,
+ exp: "a",
+ }, {
+ val: HardwarePart,
+ exp: "h",
+ }, {
+ val: OperatingSystemPart,
+ exp: "o",
+ }, {
+ val: Part(255),
+ exp: "Part(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)
+ }
+ })
+ }
+}