# encoding: utf-8 class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase include Nanoc3::TestHelpers def test_coderay_simple if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '
# comment
' expected_output = '
# comment
' # Run filter actual_output = filter.run(input) assert_equal(expected_output, actual_output) end end def test_coderay_with_comment if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = %[
#!ruby\n# comment
] expected_output = '
# comment
' # Run filter actual_output = filter.run(input) assert_equal(expected_output, actual_output) end end def test_coderay_with_comment_and_class if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = %[
#!ruby\n# comment
] expected_output = %[
#!ruby\n# comment
] # Run filter actual_output = filter.run(input) assert_equal(expected_output, actual_output) end end def test_coderay_with_more_classes if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '
# comment
' expected_output = '
# comment
' # Run filter actual_output = filter.run(input) assert_equal(expected_output, actual_output) end end def test_pygmentize if_have 'nokogiri', 'systemu' do if `which pygmentize`.strip.empty? skip "could not find pygmentize" end # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '
# comment
' expected_output = '
# comment
' # Run filter actual_output = filter.run(input, :colorizers => { :ruby => :pygmentize }) assert_equal(expected_output, actual_output) end end def test_simon_highlight if_have 'nokogiri', 'systemu' do if `which highlight`.strip.empty? skip "could not find `highlight`" end # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = %Q[
\n# comment\n
] expected_output = '
# comment
' # Run filter actual_output = filter.run(input, :default_colorizer => :simon_highlight) assert_equal(expected_output, actual_output) end end def test_colorize_syntax_with_unknown_syntax if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Run filter assert_raises RuntimeError do filter.run('

whatever

', :syntax => :kasflwafhaweoineurl) end end end def test_colorize_syntax_with_xml if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '

foo
bar

' expected_output = '

foo
bar

' # Run filter actual_output = filter.run(input, :syntax => :xml) assert_equal(expected_output, actual_output) end end def test_colorize_syntax_with_xhtml if_have 'coderay', 'nokogiri' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '

foo
bar

' expected_output = '

foo
bar

' # Run filter actual_output = filter.run(input, :syntax => :xhtml) assert_equal(expected_output, actual_output) end end def test_colorize_syntax_with_default_colorizer if `which pygmentize`.strip.empty? skip 'no pygmentize found, which is required for this test' return end if_have 'nokogiri', 'systemu' do # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '
puts "foo"
' expected_output = '
puts "foo"
' # Run filter actual_output = filter.run(input, :default_colorizer => :pygmentize) assert_equal(expected_output, actual_output) end end def test_colorize_syntax_with_missing_executables if_have 'nokogiri', 'systemu' do begin original_path = ENV['PATH'] ENV['PATH'] = './blooblooblah' # Create filter filter = ::Nanoc3::Filters::ColorizeSyntax.new # Get input and expected output input = '
puts "foo"
' # Run filter [ :pygmentize, :simon_highlight ].each do |colorizer| begin input = '
puts "foo"
' actual_output = filter.run( input, :colorizers => { :ruby => colorizer }) flunk "expected colorizer to raise if no executable is available" rescue => e end end ensure ENV['PATH'] = original_path end end end end