-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer_test.go
42 lines (34 loc) · 924 Bytes
/
lexer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package rhombifer
import (
"testing"
"github.com/racg0092/rhombifer/lexer"
"github.com/racg0092/rhombifer/tokens"
)
func TestNextToken(t *testing.T) {
input := `proxy set --name cool --lang go -p --url go.codeh.io`
tests := []tokens.Token{
{tokens.IDENT, "proxy"},
{tokens.IDENT, "set"},
{tokens.DOUBLE_DASH, "--"},
{tokens.IDENT, "name"},
{tokens.IDENT, "cool"},
{tokens.DOUBLE_DASH, "--"},
{tokens.IDENT, "lang"},
{tokens.IDENT, "go"},
{tokens.DASH, "-"},
{tokens.IDENT, "p"},
{tokens.DOUBLE_DASH, "--"},
{tokens.IDENT, "url"},
{tokens.IDENT, "go.codeh.io"},
}
l := lexer.New(input)
for i, tt := range tests {
tok := l.NextToken()
if tok.Type != tt.Type {
t.Fatalf("test[%d] - tokentype wrong. expected=%q, got=%q", i, tt.Type, tok.Type)
}
if tok.Literal != tt.Literal {
t.Fatalf("test[%d] - literal wrong. expected=%q, got=%q", i, tt.Literal, tok.Literal)
}
}
}