ebnf/token: Add initial TokenType

This commit is contained in:
2014-10-30 00:51:47 +01:00
parent 2797253a96
commit 33dbfec54a
2 changed files with 45 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
package token
// types of Token
type TokenType int
const (
TokenError TokenType = iota + 1
TokenEOF
)
func (typ TokenType) String() string {
switch typ {
case TokenError:
return "ERROR"
case TokenEOF:
return "EOF"
default:
return "UNDEFINED"
}
}
+25
View File
@@ -0,0 +1,25 @@
package token
import (
"fmt"
"testing"
)
func TestTokenTypeToString(t *testing.T) {
var foo TokenType
for _, o := range []struct {
typ TokenType
str string
}{
{foo, "UNDEFINED"},
{TokenError, "ERROR"},
{TokenEOF, "EOF"},
{1234, "UNDEFINED"},
} {
str := fmt.Sprintf("%s", o.typ)
if str != o.str {
t.Errorf("TokenType:%v stringified as %s instead of %s.", int(o.typ), str, o.str)
}
}
}