Case-sensitive lexer name lookup

This commit is contained in:
Joshua Peek
2011-06-18 20:19:34 -05:00
parent cfb952b867
commit 80473e5849
2 changed files with 6 additions and 8 deletions

View File

@@ -33,7 +33,7 @@ module Linguist
# Public: Look up Lexer by its proper name. # Public: Look up Lexer by its proper name.
# #
# name - The case-insensitive String name of the Lexer # name - The String name of the Lexer
# #
# Examples # Examples
# #
@@ -42,12 +42,12 @@ module Linguist
# #
# Returns the Lexer or nil if none was found. # Returns the Lexer or nil if none was found.
def self.find_by_name(name) def self.find_by_name(name)
@name_index[name.downcase] @name_index[name]
end end
# Public: Look up Lexer by one of its aliases. # Public: Look up Lexer by one of its aliases.
# #
# name - A case-sensitive String alias of the Lexer # name - A String alias of the Lexer
# #
# Examples # Examples
# #
@@ -75,7 +75,7 @@ module Linguist
# Public: Look up Lexer by name or alias. # Public: Look up Lexer by name or alias.
# #
# name - A case-insensitive String name or alias # name - A String name or alias
# #
# Lexer['Ruby'] # Lexer['Ruby']
# => #<Lexer name="Ruby"> # => #<Lexer name="Ruby">
@@ -133,11 +133,11 @@ module Linguist
@lexers << lexer @lexers << lexer
# All Lexer names should be unique. Warn if there is a duplicate. # All Lexer names should be unique. Warn if there is a duplicate.
if @name_index.key?(lexer.name.downcase) if @name_index.key?(lexer.name)
warn "Duplicate lexer name: #{lexer.name}" warn "Duplicate lexer name: #{lexer.name}"
end end
@name_index[lexer.name.downcase] = lexer @name_index[lexer.name] = lexer
lexer.aliases.each do |name| lexer.aliases.each do |name|
# All Lexer aliases should be unique. Warn if there is a duplicate. # All Lexer aliases should be unique. Warn if there is a duplicate.

View File

@@ -7,8 +7,6 @@ class TestLexer < Test::Unit::TestCase
def test_find_by_name def test_find_by_name
assert_equal Lexer['Ruby'], Lexer.find_by_name('Ruby') assert_equal Lexer['Ruby'], Lexer.find_by_name('Ruby')
assert_equal Lexer['Ruby'], Lexer.find_by_name('ruby')
assert_equal Lexer['Ruby'], Lexer.find_by_name('RUBY')
end end
def test_find_all_by_name def test_find_all_by_name