mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
require 'linguist/samples'
 | 
						|
require 'tempfile'
 | 
						|
require 'yajl'
 | 
						|
 | 
						|
require 'test/unit'
 | 
						|
 | 
						|
class TestSamples < Test::Unit::TestCase
 | 
						|
  include Linguist
 | 
						|
 | 
						|
  def test_up_to_date
 | 
						|
    assert serialized = Samples::DATA
 | 
						|
    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::Encoder.encode(serialized, :pretty => true)
 | 
						|
      expected.close
 | 
						|
 | 
						|
      actual = Tempfile.new('actual.json')
 | 
						|
      actual.write Yajl::Encoder.encode(latest, :pretty => true)
 | 
						|
      actual.close
 | 
						|
 | 
						|
      warn `diff #{expected.path} #{actual.path}`
 | 
						|
 | 
						|
      expected.unlink
 | 
						|
      actual.unlink
 | 
						|
    end
 | 
						|
  end
 | 
						|
 | 
						|
  def test_verify
 | 
						|
    assert data = Samples::DATA
 | 
						|
 | 
						|
    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 } }
 | 
						|
  end
 | 
						|
end
 |