44 lines
859 B
Go
44 lines
859 B
Go
package schema
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/matryer/is"
|
|
)
|
|
|
|
//go:embed testdata
|
|
var testdata embed.FS
|
|
|
|
func TestLint(t *testing.T) {
|
|
tt := []struct {
|
|
Name string
|
|
NumErr int
|
|
}{
|
|
{Name: "catppuccin"},
|
|
{Name: "minimal"},
|
|
{Name: "bad", NumErr: 8},
|
|
}
|
|
|
|
for _, tc := range tt {
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
assert := is.New(t)
|
|
|
|
fi, err := testdata.Open(fmt.Sprintf("testdata/%s.chroma.json", tc.Name))
|
|
assert.NoErr(err) // Should open file
|
|
defer fi.Close()
|
|
|
|
ok, err := Lint(fi)
|
|
if tc.NumErr > 0 {
|
|
assert.True(!ok) // Linter should fail
|
|
errs, ok := err.(ResultErrors)
|
|
assert.True(ok) // err should be of type ResultErrors
|
|
assert.Equal(tc.NumErr, len(errs)) // Number of errors should be consistent
|
|
} else {
|
|
assert.NoErr(err) // Linter should pass
|
|
}
|
|
})
|
|
}
|
|
}
|