From f141d2d07f0c1da27cc044cae11583413bfa5808 Mon Sep 17 00:00:00 2001 From: Emmanuel Di Pretoro Date: Wed, 18 Mar 2026 21:59:49 +0100 Subject: [PATCH] Adding tests about the lexer --- lexer/lexer_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lexer/lexer_test.go diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go new file mode 100644 index 0000000..81dd6d6 --- /dev/null +++ b/lexer/lexer_test.go @@ -0,0 +1,42 @@ +package lexer + +import ( + "testing" + + "github.com/edipretoro/waiig_monkey/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.Fatal("tests[%d] - tokentype wrong. expected=%q, got=%q", + i, tt.expectedType, tok.Type) + } + + if tok.Literal != tt.expectedLiteral { + t.Fatalf("tests[%d] - literal wrong. expected=%q, got=%q", + i, tt.expectedLiteral, tok.Literal) + } + + } +}