Fix tests

This commit is contained in:
Jesse Portnoy
2023-07-18 04:06:03 +01:00
parent 07420a4df2
commit 01852470c7
+7 -8
View File
@@ -5,24 +5,23 @@ import (
"io/ioutil"
"testing"
"github.com/jessp01/gohighlight"
)
func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string) *highlight.Def {
var def *highlight.Def
func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string) *Def {
var def *Def
syn_dir := "./syntax_files"
var defs []*highlight.Def
lerr := highlight.ParseSyntaxFiles(syn_dir, &defs)
var defs []*Def
lerr := ParseSyntaxFiles(syn_dir, &defs)
if lerr != nil {
t.Errorf("Couldn't get defs from '%s', error: %v\n", syn_dir, lerr)
}
highlight.ResolveIncludes(defs)
ResolveIncludes(defs)
// Always try to auto detect the best lexer:was
if def == nil {
def = highlight.DetectFiletype(defs, filename, bytes.Split(data, []byte("\n"))[0])
def = DetectFiletype(defs, filename, bytes.Split(data, []byte("\n"))[0])
}
// if a specific lexer was requested by setting the ENV var, try to load it
@@ -30,7 +29,7 @@ func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string)
syntaxFile, lerr := ioutil.ReadFile(syn_dir + "/" + highlight_lexer + ".yaml")
if lerr == nil {
// Parse it into a `*highlight.Def`
def, _ = highlight.ParseDef(syntaxFile)
def, _ = ParseDef(syntaxFile)
}
}