token: add Type enum, Token struct, and String() method
diff --git a/token/token_test.go b/token/token_test.go
new file mode 100644
index 0000000..05045b0
--- /dev/null
+++ b/token/token_test.go
@@ -0,0 +1,25 @@
+package token
+
+import "testing"
+
+func TestTypeString(t *testing.T) {
+ tests := []struct {
+ typ Type
+ want string
+ }{
+ {Number, "Number"},
+ {Plus, "+"},
+ {Minus, "-"},
+ {Star, "*"},
+ {Slash, "/"},
+ {LParen, "("},
+ {RParen, ")"},
+ {EOF, "EOF"},
+ {Type(99), "Unknown(99)"},
+ }
+ for _, tc := range tests {
+ if got := tc.typ.String(); got != tc.want {
+ t.Errorf("Type(%d).String() = %q, want %q", int(tc.typ), got, tc.want)
+ }
+ }
+}