mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Merge pull request #68 from github/pygments.rb
Replace Lexer with Pygments::Lexer
This commit is contained in:
		@@ -2,10 +2,13 @@ require 'linguist/file_blob'
 | 
			
		||||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
require 'mime/types'
 | 
			
		||||
require 'pygments'
 | 
			
		||||
 | 
			
		||||
class TestBlob < Test::Unit::TestCase
 | 
			
		||||
  include Linguist
 | 
			
		||||
 | 
			
		||||
  Lexer = Pygments::Lexer
 | 
			
		||||
 | 
			
		||||
  def fixtures_path
 | 
			
		||||
    File.expand_path("../fixtures", __FILE__)
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +1,13 @@
 | 
			
		||||
require 'linguist/language'
 | 
			
		||||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
require 'pygments'
 | 
			
		||||
 | 
			
		||||
class TestLanguage < Test::Unit::TestCase
 | 
			
		||||
  include Linguist
 | 
			
		||||
 | 
			
		||||
  Lexer = Pygments::Lexer
 | 
			
		||||
 | 
			
		||||
  def test_ambiguous_extensions
 | 
			
		||||
    assert Language.ambiguous?('.h')
 | 
			
		||||
    assert_equal Language['C'], Language.find_by_extension('h')
 | 
			
		||||
@@ -311,26 +314,4 @@ class TestLanguage < Test::Unit::TestCase
 | 
			
		||||
</div>
 | 
			
		||||
    HTML
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_colorize_without_wrapper
 | 
			
		||||
    assert_equal <<-HTML, Language['Text'].colorize_without_wrapper("Hello")
 | 
			
		||||
Hello
 | 
			
		||||
    HTML
 | 
			
		||||
 | 
			
		||||
    assert_equal <<-HTML, Language['Ruby'].colorize_without_wrapper("def foo\n  'foo'\nend\n")
 | 
			
		||||
<span class="k">def</span> <span class="nf">foo</span>
 | 
			
		||||
  <span class="s1">'foo'</span>
 | 
			
		||||
<span class="k">end</span>
 | 
			
		||||
    HTML
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_colorize_doesnt_strip_newlines
 | 
			
		||||
    assert_equal <<-HTML, Language['Ruby'].colorize_without_wrapper("\n\n# Foo\ndef 'foo'\nend\n")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<span class="c1"># Foo</span>
 | 
			
		||||
<span class="k">def</span> <span class="s1">'foo'</span>
 | 
			
		||||
<span class="k">end</span>
 | 
			
		||||
    HTML
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,91 +0,0 @@
 | 
			
		||||
require 'linguist/lexer'
 | 
			
		||||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
 | 
			
		||||
class TestLexer < Test::Unit::TestCase
 | 
			
		||||
  include Linguist
 | 
			
		||||
 | 
			
		||||
  def test_find_by_name
 | 
			
		||||
    assert_equal Lexer['Ruby'], Lexer.find_by_name('Ruby')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_all_by_name
 | 
			
		||||
    Lexer.all.each do |lexer|
 | 
			
		||||
      assert_equal lexer, Lexer.find_by_name(lexer.name)
 | 
			
		||||
      assert_equal lexer, Lexer[lexer.name]
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_by_alias
 | 
			
		||||
    assert_equal Lexer['Ruby'], Lexer.find_by_alias('rb')
 | 
			
		||||
    assert_equal Lexer['Ruby'], Lexer.find_by_alias('ruby')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_all_by_alias
 | 
			
		||||
    Lexer.all.each do |lexer|
 | 
			
		||||
      lexer.aliases.each do |name|
 | 
			
		||||
        assert_equal lexer, Lexer.find_by_alias(name)
 | 
			
		||||
        assert_equal lexer, Lexer[name]
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_by_mimetype
 | 
			
		||||
    assert_equal Lexer['Ruby'], Lexer.find_by_mimetype('text/x-ruby')
 | 
			
		||||
    assert_equal Lexer['Ruby'], Lexer.find_by_mimetype('application/x-ruby')
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_find_all_by_mimetype
 | 
			
		||||
    Lexer.all.each do |lexer|
 | 
			
		||||
      lexer.mimetypes.each do |type|
 | 
			
		||||
        assert_equal lexer, Lexer.find_by_mimetype(type)
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_name
 | 
			
		||||
    assert_equal 'Ruby',   Lexer['Ruby'].name
 | 
			
		||||
    assert_equal 'Python', Lexer['Python'].name
 | 
			
		||||
    assert_equal 'Perl',   Lexer['Perl'].name
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_aliases
 | 
			
		||||
    assert_equal ['rb', 'ruby', 'duby'], Lexer['Ruby'].aliases
 | 
			
		||||
    assert_equal ['python', 'py'],       Lexer['Python'].aliases
 | 
			
		||||
    assert_equal ['perl', 'pl'],         Lexer['Perl'].aliases
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_eql
 | 
			
		||||
    assert Lexer['Ruby'].eql?(Lexer['Ruby'])
 | 
			
		||||
    assert !Lexer['Ruby'].eql?(Lexer['Python'])
 | 
			
		||||
    assert !Lexer['Ruby'].eql?(Lexer.new('Ruby'))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_colorize
 | 
			
		||||
    assert_equal <<-HTML, Lexer['Text only'].colorize("Hello")
 | 
			
		||||
<div class="highlight"><pre>Hello
 | 
			
		||||
</pre>
 | 
			
		||||
</div>
 | 
			
		||||
    HTML
 | 
			
		||||
 | 
			
		||||
    assert_equal <<-HTML, Lexer['Ruby'].colorize("def foo\n  'foo'\nend\n")
 | 
			
		||||
<div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span>
 | 
			
		||||
  <span class="s1">'foo'</span>
 | 
			
		||||
<span class="k">end</span>
 | 
			
		||||
</pre>
 | 
			
		||||
</div>
 | 
			
		||||
    HTML
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_colorize_without_wrapper
 | 
			
		||||
    assert_equal <<-HTML, Lexer['Text only'].colorize_without_wrapper("Hello")
 | 
			
		||||
Hello
 | 
			
		||||
    HTML
 | 
			
		||||
 | 
			
		||||
    assert_equal <<-HTML, Lexer['Ruby'].colorize_without_wrapper("def foo\n  'foo'\nend\n")
 | 
			
		||||
<span class="k">def</span> <span class="nf">foo</span>
 | 
			
		||||
  <span class="s1">'foo'</span>
 | 
			
		||||
<span class="k">end</span>
 | 
			
		||||
    HTML
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@@ -1,10 +1,13 @@
 | 
			
		||||
require 'linguist/pathname'
 | 
			
		||||
 | 
			
		||||
require 'test/unit'
 | 
			
		||||
require 'pygments'
 | 
			
		||||
 | 
			
		||||
class TestPathname < Test::Unit::TestCase
 | 
			
		||||
  include Linguist
 | 
			
		||||
 | 
			
		||||
  Lexer = Pygments::Lexer
 | 
			
		||||
 | 
			
		||||
  def test_to_s
 | 
			
		||||
    assert_equal "file.rb", Pathname.new("file.rb").to_s
 | 
			
		||||
  end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user