Permalink
Browse files

Additional tests and matching

  • Loading branch information...
1 parent 62e06b1 commit 3aa50a7360a9ef9d81d6272ceee1ba5b11fa4631 @tnm committed Jul 8, 2012
Showing with 11 additions and 3 deletions.
  1. +0 −1 lib/pygments/mentos.py
  2. +1 −1 lib/pygments/popen.rb
  3. +10 −1 test/test_pygments.rb
View
@@ -81,7 +81,6 @@ def highlight_text(self, code, formatter_name, args, kwargs):
_format_name = "html"
# Return a lexer object
- args += code
lexer = self.return_lexer(args, kwargs)
# Make sure we sucessfuly got a lexer
View
@@ -168,7 +168,7 @@ def highlight(code, opts={})
opts[:options][:outencoding] ||= 'utf-8'
# Get back the string from mentos and force encoding if we can
- str = mentos(:highlight, [], opts, code)
+ str = mentos(:highlight, code, opts, code)
str.force_encoding(opts[:options][:outencoding]) if str.respond_to?(:force_encoding)
str
end
View
@@ -25,7 +25,7 @@ def test_highlight_works_with_larger_files
assert_match '>used_memory_peak_human<', code
end
- def test_highlight_markdown_compatible_html
+ def test_highlight_markdown_compatible_html
code = P.highlight(RUBY_CODE)
assert_no_match %r{</pre></div>\Z}, code
end
@@ -94,6 +94,11 @@ def test_highlight_works_with_trailing_cr
code = P.highlight(RUBY_CODE_TRAILING_NEWLINE + "\r")
assert_match '<span class="c">#!/usr/bin/ruby</span>', code
end
+
+ def test_highlight_still_works_with_invalid_code
+ code = P.highlight("importr python; wat?", :lexer => 'py')
+ assert_match ">importr</span>", code
+ end
end
class PygmentsLexerTest < Test::Unit::TestCase
@@ -105,14 +110,18 @@ def test_lexer_by_content
def test_lexer_by_mimetype
assert_equal 'rb', P.lexer_name_for(:mimetype => 'text/x-ruby')
+ assert_equal 'json', P.lexer_name_for(:mimetype => 'application/json')
end
def test_lexer_by_filename
assert_equal 'rb', P.lexer_name_for(:filename => 'test.rb')
+ assert_equal 'scala', P.lexer_name_for(:filename => 'test.scala')
end
def test_lexer_by_name
assert_equal 'rb', P.lexer_name_for(:lexer => 'ruby')
+ assert_equal 'python', P.lexer_name_for(:lexer => 'python')
+ assert_equal 'c', P.lexer_name_for(:lexer => 'c')
end
def test_lexer_by_filename_and_content

0 comments on commit 3aa50a7

Please sign in to comment.