-
Notifications
You must be signed in to change notification settings - Fork 1
/
tokenize_test.go
52 lines (44 loc) · 1.62 KB
/
tokenize_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
43
44
45
46
47
48
49
50
51
52
package liquid
import (
"reflect"
"testing"
)
func checkTokens(t *testing.T, tpl string, want []string) {
tokenizer := NewTokenizer(tpl)
var got []string
for {
token, err := tokenizer.Next()
if token != "" {
got = append(got, token)
}
if err != nil {
break
}
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Token list lengths didn't match, want: %v, got: %v", want, got)
}
}
func TestTokenizeStrings(t *testing.T) {
checkTokens(t, " ", []string{" "})
checkTokens(t, "hello world", []string{"hello world"})
}
func TestTokenizeVariables(t *testing.T) {
checkTokens(t, "{{funk}}", []string{"{{funk}}"})
checkTokens(t, " {{funk}} ", []string{" ", "{{funk}}", " "})
checkTokens(t, " {{funk}} {{so}} {{brother}} ", []string{" ", "{{funk}}", " ", "{{so}}", " ", "{{brother}}", " "})
checkTokens(t, " {{ funk }} ", []string{" ", "{{ funk }}", " "})
}
func TestTokenizeBlocks(t *testing.T) {
checkTokens(t, "{%comment%}", []string{"{%comment%}"})
checkTokens(t, " {%comment%} ", []string{" ", "{%comment%}", " "})
checkTokens(t, " {%comment%} {%endcomment%} ", []string{" ", "{%comment%}", " ", "{%endcomment%}", " "})
checkTokens(t, " {% comment %} {% endcomment %} ", []string{" ", "{% comment %}", " ", "{% endcomment %}", " "})
}
func TestCalculateLineNumbersPerTokenWithProfiling(t *testing.T) {
t.Skip("line numbers not implemented")
// assert_equal [1], tokenize_line_numbers("{{funk}}")
// assert_equal [1, 1, 1], tokenize_line_numbers(" {{funk}} ")
// assert_equal [1, 2, 2], tokenize_line_numbers("\n{{funk}}\n")
// assert_equal [1, 1, 3], tokenize_line_numbers(" {{\n funk \n}} ")
}