mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	* origin/master: (30 commits) Add byebug Link to Lightshow in CONTRIBUTING.md Switch to a better F# grammar Bump Rugged again Checkout the master for testing Rugged 0.22.0b3 Reordering Bump version to 4.0.3 Add some docs for tm_scope Change NONE to none Checking other case for Chart.jS Test that all languages have grammars Fix RHTML's tm_scope Chart JS is vendored Switch to a better grammar for Bro reorder again… put cjsx at the top Use a SQF grammar for SQF files move cjsx before iced move cjsx before iced ... Conflicts: lib/linguist/languages.yml
		
			
				
	
	
		
			91 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
| require_relative "./helper"
 | |
| require "tempfile"
 | |
| 
 | |
| class TestSamples < Test::Unit::TestCase
 | |
|   include Linguist
 | |
| 
 | |
|   def test_up_to_date
 | |
|     assert serialized = Samples.cache
 | |
|     assert latest = Samples.data
 | |
| 
 | |
|     # Just warn, it shouldn't scare people off by breaking the build.
 | |
|     if serialized['md5'] != latest['md5']
 | |
|       warn "Samples database is out of date. Run `bundle exec rake samples`."
 | |
| 
 | |
|       expected = Tempfile.new('expected.json')
 | |
|       expected.write Yajl.dump(serialized, :pretty => true)
 | |
|       expected.close
 | |
| 
 | |
|       actual = Tempfile.new('actual.json')
 | |
|       actual.write Yajl.dump(latest, :pretty => true)
 | |
|       actual.close
 | |
| 
 | |
|       expected.unlink
 | |
|       actual.unlink
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_verify
 | |
|     assert data = Samples.cache
 | |
| 
 | |
|     assert_equal data['languages_total'], data['languages'].inject(0) { |n, (_, c)| n += c }
 | |
|     assert_equal data['tokens_total'], data['language_tokens'].inject(0) { |n, (_, c)| n += c }
 | |
|     assert_equal data['tokens_total'], data['tokens'].inject(0) { |n, (_, ts)| n += ts.inject(0) { |m, (_, c)| m += c } }
 | |
|     assert !data["interpreters"].empty?
 | |
|   end
 | |
| 
 | |
|   # Check that there aren't samples with extensions or interpreters that
 | |
|   # aren't explicitly defined in languages.yml
 | |
|   languages_yml = File.expand_path("../../lib/linguist/languages.yml", __FILE__)
 | |
|   YAML.load_file(languages_yml).each do |name, options|
 | |
|     define_method "test_samples_have_parity_with_languages_yml_for_#{name}" do
 | |
|       options['extensions'] ||= []
 | |
|       if extnames = Samples.cache['extnames'][name]
 | |
|         extnames.each do |extname|
 | |
|           next if extname == '.script!'
 | |
|           assert options['extensions'].include?(extname), "#{name} has a sample with extension (#{extname}) that isn't explicitly defined in languages.yml"
 | |
|         end
 | |
|       end
 | |
| 
 | |
|       options['interpreters'] ||= []
 | |
|       if interpreters = Samples.cache['interpreters'][name]
 | |
|         interpreters.each do |interpreter|
 | |
|           # next if extname == '.script!'
 | |
|           assert options['interpreters'].include?(interpreter), "#{name} has a sample with an interpreter (#{interpreter}) that isn't explicitly defined in languages.yml"
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   # If a language extension isn't globally unique then make sure there are samples
 | |
|   Linguist::Language.all.each do |language|
 | |
|     define_method "test_#{language.name}_has_samples" do
 | |
|       language.extensions.each do |extension|
 | |
|         language_matches = Language.find_by_extension(extension)
 | |
| 
 | |
|         # Check for samples if more than one language matches the given extension.
 | |
|         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"
 | |
|           end
 | |
|         end
 | |
|       end
 | |
| 
 | |
|       language.filenames.each do |filename|
 | |
|         # Check for samples if more than one language matches the given filename
 | |
|         if Language.find_by_filename(filename).size > 1
 | |
|           sample = "samples/#{language.name}/filenames/#{filename}"
 | |
|           assert File.exists?(sample),
 | |
|             "Missing sample in #{sample.inspect}. See https://github.com/github/linguist/blob/master/CONTRIBUTING.md"
 | |
|         end
 | |
|       end
 | |
|     end
 | |
|   end
 | |
| 
 | |
|   def test_shebang
 | |
|     assert_equal "crystal", Linguist.interpreter_from_shebang("#!/usr/bin/env bin/crystial")
 | |
|     assert_equal "python2", Linguist.interpreter_from_shebang("#!/usr/bin/python2.4")
 | |
|   end
 | |
| end
 |