require File.dirname(__FILE__) + '/../spec_helper'
describe YARD::Templates::Helpers::HtmlSyntaxHighlightHelper do
include YARD::Templates::Helpers::HtmlHelper
include YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
describe '#html_syntax_highlight' do
before do
stub!(:object).and_return Registry.root
Registry.root.source_type = :ruby
end
it "should not highlight source if options.highlight is false" do
should_receive(:options).and_return(Options.new.update(:highlight => false))
html_syntax_highlight("def x\nend").should == "def x\nend"
end
it "should highlight source (legacy)" do
type = Parser::SourceParser.parser_type
Parser::SourceParser.parser_type = :ruby18
should_receive(:options).and_return(Options.new.update(:highlight => true))
expect = "defx
'x'+
/x/iend"
result = html_syntax_highlight("def x\n 'x' + /x/i\nend")
html_equals_string(result, expect)
Parser::SourceParser.parser_type = type
end
it "should highlight source (ripper)" do
should_receive(:options).and_return(Options.new.update(:highlight => true))
Parser::SourceParser.parser_type = :ruby
expect = "def x
'
x'
+
/x
/i\nend"
result = html_syntax_highlight("def x\n 'x' + /x/i\nend")
html_equals_string(result, expect)
end if HAVE_RIPPER
it "should return escaped unhighlighted source if a syntax error is found (ripper)" do
should_receive(:options).and_return(Options.new.update(:highlight => true))
html_syntax_highlight("def &x; ... end").should == "def &x; ... end"
end if HAVE_RIPPER
end
end