Add XML strategy

This commit is contained in:
Lauris BH
2020-11-15 15:43:37 +02:00
parent 0fb4b8a768
commit 6d8f15af5b
2 changed files with 65 additions and 4 deletions

View File

@ -23,6 +23,7 @@ type EnryTestSuite struct {
tmpLinguist string
needToClone bool
samplesDir string
testFixturesDir string
}
func (s *EnryTestSuite) TestRegexpEdgeCases() {
@ -72,6 +73,9 @@ func (s *EnryTestSuite) SetupSuite() {
s.samplesDir = filepath.Join(s.tmpLinguist, "samples")
s.T().Logf("using samples from %s", s.samplesDir)
s.testFixturesDir = filepath.Join(s.tmpLinguist, "test", "fixtures")
s.T().Logf("using test fixtures from %s", s.samplesDir)
cwd, err := os.Getwd()
assert.NoError(s.T(), err)
@ -314,6 +318,31 @@ func (s *EnryTestSuite) TestGetLanguagesByManpage() {
}
}
func (s *EnryTestSuite) TestGetLanguagesByXML() {
tests := []struct {
name string
filename string
candidates []string
expected []string
}{
{name: "TestGetLanguagesByXML_1", filename: filepath.Join(s.testFixturesDir, "XML/app.config"), expected: []string{"XML"}},
{name: "TestGetLanguagesByXML_2", filename: filepath.Join(s.testFixturesDir, "XML/AssertionIDRequestOptionalAttributes.xml.svn-base"), expected: []string{"XML"}},
// no XML header so should not be identified by this strategy
{name: "TestGetLanguagesByXML_3", filename: filepath.Join(s.samplesDir, "XML/libsomething.dll.config"), expected: nil},
{name: "TestGetLanguagesByXML_4", filename: filepath.Join(s.samplesDir, "Eagle/Eagle.sch"), candidates: []string{"Eagle"}, expected: []string{"Eagle"}},
}
for _, test := range tests {
content, err := ioutil.ReadFile(test.filename)
assert.NoError(s.T(), err)
languages := GetLanguagesByXML(test.filename, content, test.candidates)
assert.Equal(s.T(), test.expected, languages, fmt.Sprintf("%v: languages = %v, expected: %v", test.name, languages, test.expected))
}
}
func (s *EnryTestSuite) TestGetLanguagesByClassifier() {
test := []struct {
name string