mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Allow delimiting by comma in the language name
This commit is contained in:
@@ -150,7 +150,7 @@ module Linguist
|
||||
#
|
||||
# Returns the Language or nil if none was found.
|
||||
def self.find_by_name(name)
|
||||
name && @name_index[name.downcase]
|
||||
name && (@name_index[name.downcase] || @name_index[name.split(',').first.downcase])
|
||||
end
|
||||
|
||||
# Public: Look up Language by one of its aliases.
|
||||
@@ -164,7 +164,7 @@ module Linguist
|
||||
#
|
||||
# Returns the Language or nil if none was found.
|
||||
def self.find_by_alias(name)
|
||||
name && @alias_index[name.downcase]
|
||||
name && (@alias_index[name.downcase] || @alias_index[name.split(',').first.downcase])
|
||||
end
|
||||
|
||||
# Public: Look up Languages by filename.
|
||||
@@ -240,7 +240,7 @@ module Linguist
|
||||
#
|
||||
# Returns the Language or nil if none was found.
|
||||
def self.[](name)
|
||||
name && @index[name.downcase]
|
||||
name && (@index[name.downcase] || @index[name.split(',').first.downcase])
|
||||
end
|
||||
|
||||
# Public: A List of popular languages
|
||||
|
||||
@@ -263,6 +263,18 @@ class TestLanguage < Minitest::Test
|
||||
assert_equal 'AGS Script', Language.find_by_alias('AGS').name
|
||||
end
|
||||
|
||||
def test_find_ignores_comma
|
||||
assert_equal 'Rust', Language['rust,no_run'].name
|
||||
end
|
||||
|
||||
def test_find_by_name_ignores_comma
|
||||
assert_equal Language['Rust'], Language.find_by_name('rust,no_run')
|
||||
end
|
||||
|
||||
def test_find_by_alias_ignores_comma
|
||||
assert_equal Language['Rust'], Language.find_by_alias('rust,no_run')
|
||||
end
|
||||
|
||||
def test_name
|
||||
assert_equal 'Perl', Language['Perl'].name
|
||||
assert_equal 'Python', Language['Python'].name
|
||||
|
||||
Reference in New Issue
Block a user