1 package chroma
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestTokenTypeClassifiers(t *testing.T) {
10 assert.True(t, GenericDeleted.InCategory(Generic))
11 assert.True(t, LiteralStringBacktick.InSubCategory(String))
12 assert.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick")
13 }
14
15 func TestSimpleLexer(t *testing.T) {
16 lexer, err := NewLexer(
17 &Config{
18 Name: "INI",
19 Aliases: []string{"ini", "cfg"},
20 Filenames: []string{"*.ini", "*.cfg"},
21 },
22 map[string][]Rule{
23 "root": {
24 {`\s+`, Whitespace, nil},
25 {`;.*?$`, Comment, nil},
26 {`\[.*?\]$`, Keyword, nil},
27 {`(.*?)(\s*)(=)(\s*)(.*?)$`, ByGroups(Name, Whitespace, Operator, Whitespace, String), nil},
28 },
29 },
30 )
31 assert.NoError(t, err)
32 actual, err := Tokenise(lexer, nil, `
33 ; this is a comment
34 [section]
35 a = 10
36 `)
37 assert.NoError(t, err)
38 expected := []Token{
39 {Whitespace, "\n\t"},
40 {Comment, "; this is a comment"},
41 {Whitespace, "\n\t"},
42 {Keyword, "[section]"},
43 {Whitespace, "\n\t"},
44 {Name, "a"},
45 {Whitespace, " "},
46 {Operator, "="},
47 {Whitespace, " "},
48 {LiteralString, "10"},
49 {Whitespace, "\n"},
50 }
51 assert.Equal(t, expected, actual)
52 }
53
View as plain text