# encoding: utf-8 require 'test/helper' class Nanoc3::Filters::ColorizeSyntaxTest < MiniTest::Unit::TestCase include Nanoc3::TestHelpers def test_coderay_simple if_have 'coderay' 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_more_classes
if_have 'coderay' 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 `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 = %r{^# comment\n?
$}
# Run filter
actual_output = filter.run(input, :colorizers => { :ruby => :pygmentize })
assert_match(expected_output, actual_output)
end
def test_colorize_syntax_with_missing_executables
if_have 'nokogiri' 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
begin
input = 'puts "foo"
'
actual_output = filter.run(
input,
:colorizers => { :ruby => :pygmentize })
flunk "expected colorizer to raise if no executable is available"
rescue => e
assert_match /No such file or directory/, e.message
end
ensure
ENV['PATH'] = original_path
end
end
end
end