-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer_test.go
More file actions
76 lines (63 loc) · 1.81 KB
/
lexer_test.go
File metadata and controls
76 lines (63 loc) · 1.81 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package stringutils
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestTokenizeCaseSensitive(t *testing.T) {
assertions := assert.New(t)
var tokenTypes []TokenType
tokenTypes = append(tokenTypes, TokenType{
Type: "keyword",
Words: []string{"if", "for"},
})
result := Tokenize("if", tokenTypes)
assertions.Equal("if", result[0].Text)
assertions.Equal(0, result[0].Position)
assertions.Equal("keyword", result[0].Type)
}
func TestTokenizeCaseInsensitive(t *testing.T) {
assertions := assert.New(t)
var tokenTypes []TokenType
tokenTypes = append(tokenTypes, TokenType{
Type: "keyword",
Words: []string{"if", "for"},
})
result := Tokenize("IF", tokenTypes)
assertions.Equal("IF", result[0].Text)
assertions.Equal(0, result[0].Position)
assertions.Equal("keyword", result[0].Type)
}
func TestTokenizeWord(t *testing.T) {
assertions := assert.New(t)
var tokenTypes []TokenType
tokenTypes = append(tokenTypes, TokenType{
Type: "keyword",
Words: []string{"if", "for"},
})
result := TokenizeWord("if", 0, tokenTypes)
assertions.Equal("if", result.Text)
assertions.Equal(0, result.Position)
assertions.Equal("keyword", result.Type)
}
func TestLookupType(t *testing.T) {
assertions := assert.New(t)
var tokenTypes []TokenType
tokenTypes = append(tokenTypes, TokenType{
Type: "keyword",
Words: []string{"if", "for"},
})
result := LookupType("for", tokenTypes)
assertions.Equal("keyword", result.Type)
assertions.Equal([]string{"if", "for"}, result.Words)
}
func TestLookupTypeNotFound(t *testing.T) {
assertions := assert.New(t)
var tokenTypes []TokenType
tokenTypes = append(tokenTypes, TokenType{
Type: "keyword",
Words: []string{"if", "for"},
})
result := LookupType("var", tokenTypes)
assertions.Equal("", result.Type)
assertions.Equal([]string{""}, result.Words)
}