1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-01-14 02:23:16 +02:00
chroma/lexer_test.go
2017-07-20 00:01:29 -07:00

54 lines
1.2 KiB
Go

package chroma
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTokenTypeClassifiers(t *testing.T) {
require.True(t, GenericDeleted.InCategory(Generic))
require.True(t, LiteralStringBacktick.InSubCategory(String))
require.Equal(t, LiteralStringBacktick.String(), "LiteralStringBacktick")
}
func TestSimpleLexer(t *testing.T) {
lexer, err := NewLexer(
&Config{
Name: "INI",
Aliases: []string{"ini", "cfg"},
Filenames: []string{"*.ini", "*.cfg"},
},
map[string][]Rule{
"root": {
{`\s+`, Whitespace, nil},
{`;.*?$`, Comment, nil},
{`\[.*?\]$`, Keyword, nil},
{`(.*?)(\s*)(=)(\s*)(.*?)$`, ByGroups(Name, Whitespace, Operator, Whitespace, String), nil},
},
},
)
require.NoError(t, err)
actual, err := Tokenise(lexer, nil, `
; this is a comment
[section]
a = 10
`)
require.NoError(t, err)
expected := []*Token{
{Whitespace, "\n\t"},
{Comment, "; this is a comment"},
{Whitespace, "\n\t"},
{Keyword, "[section]"},
{Whitespace, "\n\t"},
{Name, "a"},
{Whitespace, " "},
{Operator, "="},
{Whitespace, " "},
{LiteralString, "10"},
{Whitespace, "\n"},
{EOF, ""},
}
require.Equal(t, expected, actual)
}