LanguagesByFilename: fix language order in generated code

Otherwise, generator tests are flaky

test plan
 * make code-generate
 * go test -run '^TestGetLanguagesByFilename$' github.com/go-enry/go-enry/v2
This commit is contained in:
Alex Bezzubov
2023-09-22 14:58:53 +02:00
parent bd3630419c
commit dc1110e30c
2 changed files with 7 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"text/template"
@ -91,7 +92,10 @@ func buildFilenameLanguageMap(languages map[string]*languageInfo) map[string][]s
func executeFilenamesTemplate(out io.Writer, languagesByFilename map[string][]string, tmplPath, tmplName, commit string) error {
fmap := template.FuncMap{
"formatStringSlice": func(slice []string) string { return `"` + strings.Join(slice, `","`) + `"` },
"formatStringSlice": func(slice []string) string {
sort.Strings(slice)
return `"` + strings.Join(slice, `","`) + `"`
},
}
return executeTemplate(out, tmplName, tmplPath, commit, fmap, languagesByFilename)
}