Sha256: 8089b5dac54e2aa7eaa9991943b98f646ef70b33632b057a6bcd0770bae8fd09

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 KB

Contents

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
    it "should not highlight source if options[:no_highlight] is set" do
      should_receive(:options).and_return(:no_highlight => true)
      html_syntax_highlight("def x\nend").should == "def x\nend"
    end
    
    it "should highlight source (ruby18)" do
      should_receive(:options).and_return(:no_highlight => false)
      expect = "<span class='def def kw'>def</span><span class='x identifier id'>x</span>
        <span class='string val'>'x'</span><span class='plus op'>+</span>
        <span class='regexp val'>/x/i</span><span class='end end kw'>end</span>"
      result = html_syntax_highlight("def x\n  'x' + /x/i\nend")
      html_equals_string(result, expect)
    end if RUBY18

    it "should highlight source (ruby19)" do
      should_receive(:options).and_return(:no_highlight => false)
      expect = "<span class='kw'>def</span> <span class='id x'>x</span>  
        <span class='tstring'><span class='tstring_beg'>'</span>
        <span class='tstring_content'>x</span><span class='tstring_end'>'</span>
        </span> <span class='op'>+</span> <span class='tstring'>
        <span class='regexp_beg'>/</span><span class='tstring_content'>x</span>
        <span class='regexp_end'>/i</span></span>\n<span class='kw'>end</span>"
      result = html_syntax_highlight("def x\n  'x' + /x/i\nend")
      html_equals_string(result, expect)
    end if RUBY19
    
    it "should return escaped unhighlighted source if a syntax error is found (ruby19)" do
      should_receive(:options).and_return(:no_highlight => false)
      html_syntax_highlight("def &x; ... end").should == "def &amp;x; ... end"
    end if RUBY19
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
yard-0.5.8 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.7 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.6 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.5 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.4 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.3 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.2 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.1p1 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.1 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.5.0 spec/templates/helpers/html_syntax_highlight_helper_spec.rb
yard-0.4.0 spec/templates/helpers/html_syntax_highlight_helper_spec.rb