From 41e1b7bd4e68261aa33ab425b30ee815e6247259 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Fri, 6 Feb 2015 22:14:22 +0100 Subject: [PATCH] Detection by extension made case-insensitive --- lib/linguist/file_blob.rb | 2 +- lib/linguist/language.rb | 8 +-- lib/linguist/languages.yml | 23 +------- samples/Eiffel/application.e | 44 ++++++++++++++ samples/Eiffel/book_collection.e | 82 +++++++++++++++++++++++++++ samples/Eiffel/git_checkout_command.e | 41 ++++++++++++++ test/test_pedantic.rb | 2 +- test/test_samples.rb | 4 +- 8 files changed, 176 insertions(+), 30 deletions(-) create mode 100644 samples/Eiffel/application.e create mode 100644 samples/Eiffel/book_collection.e create mode 100644 samples/Eiffel/git_checkout_command.e diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 04441935..cf142ef5 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -67,7 +67,7 @@ module Linguist # # Returns an Array def extensions - basename, *segments = File.basename(name).split(".") + basename, *segments = File.basename(name).downcase.split(".") segments.map.with_index do |segment, index| "." + segments[index..-1].join(".") diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 7fbf8a96..21cfc6ff 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -80,7 +80,7 @@ module Linguist raise ArgumentError, "Extension is missing a '.': #{extension.inspect}" end - @extension_index[extension] << language + @extension_index[extension.downcase] << language end language.interpreters.each do |interpreter| @@ -198,7 +198,7 @@ module Linguist # Returns all matching Languages or [] if none were found. def self.find_by_extension(extname) extname = ".#{extname}" unless extname.start_with?(".") - @extension_index[extname] + @extension_index[extname.downcase] end # DEPRECATED @@ -535,8 +535,8 @@ module Linguist if extnames = extensions[name] extnames.each do |extname| - if !options['extensions'].index { |x| x.end_with? extname } - warn "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" unless extname == '.script!' + if !options['extensions'].index { |x| x.downcase.end_with? extname.downcase } + warn "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" unless extname == '.script!' options['extensions'] << extname end end diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index e899046e..bf4b6660 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -204,7 +204,6 @@ Assembly: - nasm extensions: - .asm - - .ASM - .a51 tm_scope: source.asm.x86 ace_mode: assembly_x86 @@ -349,8 +348,6 @@ C: color: "#555" extensions: - .c - - .C - - .H - .cats - .h - .idc @@ -429,8 +426,6 @@ COBOL: type: programming extensions: - .cob - - .COB - - .CPY - .cbl - .ccp - .cobol @@ -867,14 +862,6 @@ FORTRAN: color: "#4d41b1" extensions: - .f90 - - .F - - .F03 - - .F08 - - .F77 - - .F90 - - .F95 - - .FOR - - .FPP - .f - .f03 - .f08 @@ -918,9 +905,7 @@ Forth: color: "#341708" extensions: - .fth - - .4TH - .4th - - .F - .f - .for - .forth @@ -969,7 +954,6 @@ GAS: group: Assembly extensions: - .s - - .S tm_scope: source.asm.x86 ace_mode: assembly_x86 @@ -1127,7 +1111,6 @@ Graphviz (DOT): tm_scope: source.dot extensions: - .dot - - .DOT - .gv ace_mode: text @@ -2210,7 +2193,6 @@ Perl: color: "#0298c3" extensions: - .pl - - .PL - .cgi - .fcgi - .perl @@ -2442,8 +2424,6 @@ R: - splus extensions: - .r - - .R - - .Rd - .rd - .rsx filenames: @@ -2496,7 +2476,6 @@ RMarkdown: ace_mode: markdown extensions: - .rmd - - .Rmd tm_scope: none Racket: @@ -3201,11 +3180,11 @@ XML: - .svg - .targets - .tmCommand + - .tml - .tmLanguage - .tmPreferences - .tmSnippet - .tmTheme - - .tml - .ts - .ui - .urdf diff --git a/samples/Eiffel/application.e b/samples/Eiffel/application.e new file mode 100644 index 00000000..16426905 --- /dev/null +++ b/samples/Eiffel/application.e @@ -0,0 +1,44 @@ +note + description : "nino application root class" + date : "$Date$" + revision : "$Revision$" + +class + APPLICATION + +inherit + ARGUMENTS + + HTTP_SERVER_SHARED_CONFIGURATION + +create + make + +feature {NONE} -- Initialization + + make + -- Run application. + local + l_server : HTTP_SERVER + l_cfg: HTTP_SERVER_CONFIGURATION + l_http_handler : HTTP_HANDLER + do + create l_cfg.make + l_cfg.http_server_port := 9_000 + l_cfg.document_root := default_document_root + set_server_configuration (l_cfg) + debug ("nino") + l_cfg.set_is_verbose (True) + end + + create l_server.make (l_cfg) + create {APPLICATION_CONNECTION_HANDLER} l_http_handler.make (l_server) + l_server.setup (l_http_handler) + end + +feature -- Access + + default_document_root: STRING = "webroot" + +end + diff --git a/samples/Eiffel/book_collection.e b/samples/Eiffel/book_collection.e new file mode 100644 index 00000000..8959455a --- /dev/null +++ b/samples/Eiffel/book_collection.e @@ -0,0 +1,82 @@ +class + BOOK_COLLECTION + +create + make + +feature {NONE} -- Initialization + + make (a_name: STRING_32) + -- Create a book collection with `a_name' as `name'. + do + set_name (a_name) + create book_index.make (10) + ensure + name_set: name = a_name + end + +feature -- Access + + name: STRING_32 + -- Name. + + books: LIST [BOOK] + -- collection of book. + do + create {LINKED_LIST [BOOK]} Result.make + across + book_index as it + loop + Result.append (it.item) + end + end + + books_by_author (a_author: STRING_32): LIST [BOOK] + -- Books wrote by `a_author' in this collection. + do + if attached book_index [a_author] as l_result then + Result := l_result + else + create {LINKED_LIST [BOOK]} Result.make + end + end + +feature -- Change + + set_name (a_name: STRING_32) + -- Set `name' with `a_name'. + do + name := a_name + ensure + name_set: name = a_name + end + + add_book (a_book: BOOK) + -- Extend collection with `a_book'. + local + l: detachable LIST [BOOK] + do + l := book_index.at (a_book.author.name) + if l = Void then + create {LINKED_LIST [BOOK]} l.make + book_index.put (l, a_book.author.name) + end + l.force (a_book) + end + + add_books (book_list: like books) + -- Append collection with `book_list'. + do + across + book_list as it + loop + add_book (it.item) + end + end + +feature {NONE} -- Implementation + + book_index: HASH_TABLE [LIST [BOOK], STRING_32] + -- Association of author name and its books. + +end -- class BOOK_COLLECTION diff --git a/samples/Eiffel/git_checkout_command.e b/samples/Eiffel/git_checkout_command.e new file mode 100644 index 00000000..f78747d2 --- /dev/null +++ b/samples/Eiffel/git_checkout_command.e @@ -0,0 +1,41 @@ +note + description: "Git checkout command." + author: "Olivier Ligot" + +class + GIT_CHECKOUT_COMMAND + +inherit + GIT_COMMAND + +create + make, + make_master + +feature {NONE} -- Initialization + + make (a_branch: STRING) + -- Checkout the branch `a_branch'. + do + initialize + arguments.force_last (a_branch) + branch := a_branch + ensure + branch_set: branch = a_branch + end + + make_master + -- Checkout the master branch. + do + make ("master") + end + +feature -- Access + + branch: STRING + -- Branch to checkout + + name: STRING = "checkout" + -- Git subcommand name + +end diff --git a/test/test_pedantic.rb b/test/test_pedantic.rb index 0861b8d8..29b673ab 100644 --- a/test/test_pedantic.rb +++ b/test/test_pedantic.rb @@ -12,7 +12,7 @@ class TestPedantic < Minitest::Test def test_extensions_are_sorted LANGUAGES.each do |name, language| extensions = language['extensions'] - assert_sorted extensions[1..-1] if extensions && extensions.size > 1 + assert_sorted extensions[1..-1].map(&:downcase) if extensions && extensions.size > 1 end end diff --git a/test/test_samples.rb b/test/test_samples.rb index 0b0722dc..6de1c7e9 100644 --- a/test/test_samples.rb +++ b/test/test_samples.rb @@ -43,7 +43,7 @@ class TestSamples < Minitest::Test if extnames = Samples.cache['extnames'][name] extnames.each do |extname| next if extname == '.script!' - assert options['extensions'].index { |x| x.end_with? extname }, "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml" + assert options['extensions'].index { |x| x.downcase.end_with? extname.downcase }, "#{name} has a sample with extension (#{extname.downcase}) that isn't explicitly defined in languages.yml" end end @@ -67,7 +67,7 @@ class TestSamples < Minitest::Test if language_matches.length > 1 language_matches.each do |match| samples = "samples/#{match.name}/*#{extension}" - assert Dir.glob(samples).any?, "Missing samples in #{samples.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md" + assert Dir.glob(samples, File::FNM_CASEFOLD).any?, "Missing samples in #{samples.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md" end end end