mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Deprecate find_by_shebang
This class doesn’t need to know about shebangs.
This commit is contained in:
		| @@ -199,18 +199,9 @@ module Linguist | ||||
|       @extension_index[extname] | ||||
|     end | ||||
|  | ||||
|     # Public: Look up Languages by shebang line. | ||||
|     # | ||||
|     # data - Array of tokens or String data to analyze. | ||||
|     # | ||||
|     # Examples | ||||
|     # | ||||
|     #   Language.find_by_shebang("#!/bin/bash\ndate;") | ||||
|     #   # => [#<Language name="Bash">] | ||||
|     # | ||||
|     # Returns the matching Language | ||||
|     # DEPRECATED | ||||
|     def self.find_by_shebang(data) | ||||
|       @interpreter_index[Linguist.interpreter_from_shebang(data)] | ||||
|       @interpreter_index[Shebang.interpreter(data)] | ||||
|     end | ||||
|  | ||||
|     # Public: Look up Languages by interpreter. | ||||
|   | ||||
| @@ -223,34 +223,21 @@ class TestLanguage < Test::Unit::TestCase | ||||
|     assert_equal [Language['Chapel']], Language.find_by_filename('examples/hello.chpl') | ||||
|   end | ||||
|  | ||||
|   def test_find_by_shebang | ||||
|     assert_equal 'ruby', Linguist.interpreter_from_shebang("#!/usr/bin/ruby\n# baz") | ||||
|     { []         => ["", | ||||
|                      "foo", | ||||
|                      "#bar", | ||||
|                      "#baz", | ||||
|                      "///", | ||||
|                      "\n\n\n\n\n", | ||||
|                      " #!/usr/sbin/ruby", | ||||
|                      "\n#!/usr/sbin/ruby"], | ||||
|       ['Ruby']   => ["#!/usr/bin/env ruby\n# baz", | ||||
|                      "#!/usr/sbin/ruby\n# bar", | ||||
|                      "#!/usr/bin/ruby\n# foo", | ||||
|                      "#!/usr/sbin/ruby", | ||||
|                      "#!/usr/sbin/ruby foo bar baz\n"], | ||||
|       ['R']      => ["#!/usr/bin/env Rscript\n# example R script\n#\n"], | ||||
|       ['Shell']  => ["#!/usr/bin/bash\n", "#!/bin/sh"], | ||||
|       ['Python'] => ["#!/bin/python\n# foo\n# bar\n# baz", | ||||
|                      "#!/usr/bin/python2.7\n\n\n\n", | ||||
|                      "#!/usr/bin/python3\n\n\n\n"], | ||||
|       ["Common Lisp"] => ["#!/usr/bin/sbcl --script\n\n"] | ||||
|     }.each do |languages, bodies| | ||||
|       bodies.each do |body| | ||||
|         assert_equal([body, languages.map{|l| Language[l]}], | ||||
|                      [body, Language.find_by_shebang(body)]) | ||||
|   def test_find_by_interpreter | ||||
|     { | ||||
|       "ruby" => "Ruby", | ||||
|       "Rscript" => "R", | ||||
|       "sh" => "Shell", | ||||
|       "bash" => "Shell", | ||||
|       "python" => "Python", | ||||
|       "python2" => "Python", | ||||
|       "python3" => "Python", | ||||
|       "sbcl" => "Common Lisp" | ||||
|     }.each do |interpreter, language| | ||||
|       assert_equal [Language[language]], Language.find_by_interpreter(interpreter) | ||||
|     end | ||||
|  | ||||
|       end | ||||
|     end | ||||
|     assert_equal [], Language.find_by_interpreter(nil) | ||||
|   end | ||||
|  | ||||
|   def test_find | ||||
|   | ||||
		Reference in New Issue
	
	Block a user