Skip to content

Commit

Permalink
Test for compiling all lexer patterns.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Sep 27, 2021
1 parent 23160b3 commit 07a127d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lexers/lexers_test.go
Expand Up @@ -9,13 +9,15 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma/formatters"
"github.com/alecthomas/chroma/lexers"
"github.com/alecthomas/chroma/lexers/a"
"github.com/alecthomas/chroma/lexers/x"
"github.com/alecthomas/chroma/styles"
"github.com/stretchr/testify/assert"
)

func TestCompileAllRegexes(t *testing.T) {
Expand All @@ -39,6 +41,21 @@ func TestGet(t *testing.T) {
})
}

func TestGlobs(t *testing.T) {
filename := "main.go"
for _, lexer := range lexers.Registry.Lexers {
config := lexer.Config()
for _, glob := range config.Filenames {
_, err := filepath.Match(glob, filename)
require.NoError(t, err)
}
for _, glob := range config.AliasFilenames {
_, err := filepath.Match(glob, filename)
require.NoError(t, err)
}
}
}

func BenchmarkGet(b *testing.B) {
for i := 0; i < b.N; i++ {
lexers.Get("go")
Expand Down

0 comments on commit 07a127d

Please sign in to comment.