39 lines
974 B
Go
39 lines
974 B
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/alecthomas/chroma/v2/lexers"
|
|
)
|
|
|
|
func TestLexerForPathUsesCompleteFilename(t *testing.T) {
|
|
tests := []struct {
|
|
path string
|
|
want string
|
|
}{
|
|
{"Dockerfile", "Docker"},
|
|
{"Makefile", "Makefile"},
|
|
{"src/component.tsx", "TypeScript"},
|
|
{"scripts/check.py", "Python"},
|
|
{".github/workflows/test.yml", "YAML"},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.path, func(t *testing.T) {
|
|
got := lexerForPath(test.path)
|
|
lexer := lexers.Get(got)
|
|
if lexer == nil {
|
|
t.Fatalf("lexerForPath(%q) = %q, which is not registered", test.path, got)
|
|
}
|
|
if lexer.Config().Name != test.want {
|
|
t.Fatalf("lexerForPath(%q) selected %q, want %q", test.path, lexer.Config().Name, test.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLexerForUnknownPathAllowsContentAnalysis(t *testing.T) {
|
|
if got := lexerForPath("LICENSE.unknown-extension"); got != "" {
|
|
t.Fatalf("unknown path selected %q instead of allowing content analysis", got)
|
|
}
|
|
}
|