Skip to content

Commit

Permalink
Merge pull request #26 from mcarmonaa/modelines
Browse files Browse the repository at this point in the history
Added Modeline detection strategy
  • Loading branch information
smola authored May 22, 2017
2 parents 1cb715a + 3d867ab commit 708f2e4
Show file tree
Hide file tree
Showing 25 changed files with 1,532 additions and 546 deletions.
15 changes: 15 additions & 0 deletions alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package slinguist

import "strings"

// GetLanguageByAlias returns the language related to the given alias or Otherlanguage otherwise.
func GetLanguageByAlias(alias string) (lang string) {
a := strings.Split(alias, `,`)[0]
a = strings.ToLower(a)
lang, ok := languagesByAlias[a]
if !ok {
lang = OtherLanguage
}

return
}
26 changes: 26 additions & 0 deletions alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package slinguist

import . "gopkg.in/check.v1"

func (s *TSuite) TestGetLanguageByAlias(c *C) {
tests := []struct {
alias string
expectedLang string
}{
{alias: "BestLanguageEver", expectedLang: OtherLanguage},
{alias: "aspx-vb", expectedLang: "ASP"},
{alias: "C++", expectedLang: "C++"},
{alias: "c++", expectedLang: "C++"},
{alias: "objc", expectedLang: "Objective-C"},
{alias: "golang", expectedLang: "Go"},
{alias: "GOLANG", expectedLang: "Go"},
{alias: "bsdmake", expectedLang: "Makefile"},
{alias: "xhTmL", expectedLang: "HTML"},
{alias: "python", expectedLang: "Python"},
}

for _, test := range tests {
lang := GetLanguageByAlias(test.alias)
c.Assert(lang, Equals, test.expectedLang)
}
}
Loading

0 comments on commit 708f2e4

Please sign in to comment.