summaryrefslogtreecommitdiff
path: root/lexer/lexer_test.go
diff options
context:
space:
mode:
authorMichael Tews <git@tews.dev>2024-06-10 04:15:24 +0200
committerMichael Tews <git@tews.dev>2024-06-10 04:15:24 +0200
commitf9adcb8bc1ae18bf0d91df951b33d4eeac26e965 (patch)
tree657b125484733bde591615f747a4b2f80860622b /lexer/lexer_test.go
parent0181ac9aa71b0f8b06fa50ae9d60fc003a72847f (diff)
test: adds TestNextToken
this tests the NextToken function
Diffstat (limited to 'lexer/lexer_test.go')
-rw-r--r--lexer/lexer_test.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go
new file mode 100644
index 0000000..c7816b3
--- /dev/null
+++ b/lexer/lexer_test.go
@@ -0,0 +1,42 @@
+package lexer
+
+import (
+ "testing"
+
+ "github.com/mewsen/interpreter/token"
+)
+
+func TestNextToken(t *testing.T) {
+ input := `=+(){},;`
+
+ tests := []struct {
+ expectedType token.TokenType
+ expectedLiteral string
+ }{
+ {token.ASSIGN, "="},
+ {token.PLUS, "+"},
+ {token.LPAREN, "("},
+ {token.RPAREN, ")"},
+ {token.LBRACE, "{"},
+ {token.RBRACE, "}"},
+ {token.COMMA, ","},
+ {token.SEMICOLON, ";"},
+ {token.EOF, ""},
+ }
+
+ l := New(input)
+
+ for i, tt := range tests {
+ tok := l.NextToken()
+
+ if tok.Type != tt.expectedType {
+ t.Fatalf("tests[%d] - tokentype wrong, expected=%v, got=%v",
+ i, tt.expectedType, tok.Type)
+ }
+
+ if tok.Literal != tt.expectedLiteral {
+ t.Fatalf("tests[%d] - literal wrong, expected=%v, got=%v",
+ i, tt.expectedLiteral, tok.Literal)
+ }
+ }
+}