1+ package stringutils
2+
3+ import (
4+ "github.com/stretchr/testify/assert"
5+ "testing"
6+ )
7+
8+ func TestTokenizeCaseSensitive (t * testing.T ) {
9+ assertions := assert .New (t )
10+
11+ tokenTypes := []TokenType {}
12+ tokenTypes = append (tokenTypes , TokenType {
13+ Type : "keyword" ,
14+ Words : []string {"if" , "for" },
15+ CaseSensitive : true ,
16+ })
17+ result := Tokenize ("if" , tokenTypes )
18+ assertions .Equal ("if" , result [0 ].Text )
19+ assertions .Equal (0 , result [0 ].Position )
20+ assertions .Equal ("keyword" , result [0 ].Type )
21+ }
22+
23+ func TestTokenizeCaseInsensitive (t * testing.T ) {
24+ assertions := assert .New (t )
25+
26+ tokenTypes := []TokenType {}
27+ tokenTypes = append (tokenTypes , TokenType {
28+ Type : "keyword" ,
29+ Words : []string {"if" , "for" },
30+ CaseSensitive : false ,
31+ })
32+ result := Tokenize ("IF" , tokenTypes )
33+ assertions .Equal ("IF" , result [0 ].Text )
34+ assertions .Equal (0 , result [0 ].Position )
35+ assertions .Equal ("keyword" , result [0 ].Type )
36+ }
37+
38+ func TestTokenizeWord (t * testing.T ) {
39+ assertions := assert .New (t )
40+
41+ tokenTypes := []TokenType {}
42+ tokenTypes = append (tokenTypes , TokenType {
43+ Type : "keyword" ,
44+ Words : []string {"if" , "for" },
45+ CaseSensitive : true ,
46+ })
47+ result := TokenizeWord ("if" , 0 , tokenTypes )
48+ assertions .Equal ("if" , result .Text )
49+ assertions .Equal (0 , result .Position )
50+ assertions .Equal ("keyword" , result .Type )
51+ }
52+
53+ func TestLookupType (t * testing.T ) {
54+ assertions := assert .New (t )
55+
56+ tokenTypes := []TokenType {}
57+ tokenTypes = append (tokenTypes , TokenType {
58+ Type : "keyword" ,
59+ Words : []string {"if" , "for" },
60+ CaseSensitive : false ,
61+ })
62+
63+ result := LookupType ("for" , tokenTypes )
64+ assertions .Equal ("keyword" , result .Type )
65+ assertions .Equal ([]string {"if" , "for" }, result .Words )
66+ assertions .Equal (false , result .CaseSensitive )
67+ }
0 commit comments