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

@ -157,7 +157,7 @@ var LanguagesByFilename = map[string][]string{
"Gemfile.lock": {"Gemfile.lock"}, "Gemfile.lock": {"Gemfile.lock"},
"Gopkg.lock": {"TOML"}, "Gopkg.lock": {"TOML"},
"Guardfile": {"Ruby"}, "Guardfile": {"Ruby"},
"HOSTS": {"INI", "Hosts File"}, "HOSTS": {"Hosts File", "INI"},
"INSTALL": {"Text"}, "INSTALL": {"Text"},
"INSTALL.mysql": {"Text"}, "INSTALL.mysql": {"Text"},
"JUSTFILE": {"Just"}, "JUSTFILE": {"Just"},
@ -277,7 +277,7 @@ var LanguagesByFilename = map[string][]string{
"gradlew": {"Shell"}, "gradlew": {"Shell"},
"gvimrc": {"Vim Script"}, "gvimrc": {"Vim Script"},
"haproxy.cfg": {"HAProxy"}, "haproxy.cfg": {"HAProxy"},
"hosts": {"INI", "Hosts File"}, "hosts": {"Hosts File", "INI"},
"httpd.conf": {"ApacheConf"}, "httpd.conf": {"ApacheConf"},
"initial_sids": {"SELinux Policy"}, "initial_sids": {"SELinux Policy"},
"inputrc": {"Readline Config"}, "inputrc": {"Readline Config"},

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"text/template" "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 { func executeFilenamesTemplate(out io.Writer, languagesByFilename map[string][]string, tmplPath, tmplName, commit string) error {
fmap := template.FuncMap{ 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) return executeTemplate(out, tmplName, tmplPath, commit, fmap, languagesByFilename)
} }