fixed GetLanguageType to return Unknown when language is not found in languagesType map

This commit is contained in:
Manuel Carmona 2017-05-03 10:42:31 +02:00
parent 664afe48d4
commit cbf44205e0
6 changed files with 18 additions and 42 deletions

View File

@ -17,7 +17,11 @@ const (
// GetLanguageType returns the given language's type.
func GetLanguageType(language string) (langType Type) {
langType, _ = languagesType[language]
langType, ok := languagesType[language]
if !ok {
langType = Unknown
}
return langType
}

View File

@ -1,11 +0,0 @@
package slinguist
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator
// THIS FILE SHOULD NOT BE EDITED BY HAND
// Extracted from github/linguist commit: {{ getCommit }}
var languagesByExtension = map[string][]string{
{{range $extension, $languages := . -}}
"{{ $extension }}": { {{- $languages | formatStringSlice -}} },
{{end -}}
}

View File

@ -17,7 +17,11 @@ const (
// GetLanguageType returns the given language's type.
func GetLanguageType(language string) (langType Type) {
langType, _ = languagesType[language]
langType, ok := languagesType[language]
if !ok {
langType = Unknown
}
return langType
}

View File

@ -1,28 +0,0 @@
package slinguist
// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/simple-linguist.v1/internal/code-generator
// THIS FILE SHOULD NOT BE EDITED BY HAND
// Extracted from github/linguist commit: {{ getCommit }}
type Type int
const (
// Language's type. Either data, programming, markup, prose, or unknown.
Unknown Type = iota
Data
Programming
Markup
Prose
)
// GetLanguageType returns the given language's type.
func GetLanguageType(language string) (langType Type) {
langType, _ = languagesType[language]
return langType
}
var languagesType = map[string]Type{
{{range $language, $type := . -}}
"{{ $language }}": {{ $type -}},
{{end -}}
}

View File

@ -17,7 +17,11 @@ const (
// GetLanguageType returns the given language's type.
func GetLanguageType(language string) (langType Type) {
langType, _ = languagesType[language]
langType, ok := languagesType[language]
if !ok {
langType = Unknown
}
return langType
}

View File

@ -29,4 +29,7 @@ func (s *TSuite) TestGetLanguageType(c *C) {
langType = GetLanguageType("Textile")
c.Assert(langType, Equals, Prose)
langType = GetLanguageType("Whatever")
c.Assert(langType, Equals, Unknown)
}