1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
require 'pathname'
require(Pathname.new(__FILE__).parent + 'lib/common.rb')
describe 'Specified Header ID:' do
before(:each) do
@bf = BlueFeather::Parser.new
@html = @bf.parse_text(@src)
@doc = Nokogiri(@html)
end
describe 'basic:' do
before(:all) do
@src = '## h2 ## {#test-id}'
end
specify 'correct id' do
@doc.should have_element('h2#test-id')
end
end
describe 'use span transform format:' do
before(:all) do
@src = '## h2 ## {#the_test_id}'
end
specify 'correct id' do
@doc.should have_element('h2#the_test_id')
end
end
end
describe 'Auto Generated Header ID:' do
before(:each) do
@bf = BlueFeather::Parser.new
@rs = BlueFeather::Parser::RenderState.new
@rs.header_id_type = @header_id_type if @header_id_type
@html, @rs = @bf.parse_text_with_render_state('# h1/header 1 #', @rs)
@doc = Nokogiri("<div>" + @html + "</div>")
end
describe 'default (=md5):' do
specify 'pattern matched' do
@doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
@rs.warnings.size.should == 0
end
end
describe 'md5:' do
before(:all) do
@header_id_type = 'md5'
end
specify 'pattern matched' do
@doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
@rs.warnings.size.should == 0
end
end
describe 'escape:' do
before(:all) do
@header_id_type = 'escape'
end
specify 'pattern matched' do
@doc.at('h1')['id'].should == 'h1.2Fheader_1'
@rs.warnings.size.should == 0
end
end
describe 'illegel type:' do
before(:all) do
@header_id_type = '*illegal*'
end
specify 'pattern matched' do
@doc.at('h1')['id'].should =~ /^bfheader-[0-9a-f]{32}$/
@rs.warnings.size.should == 1
end
end
end
describe "Document Header (Header-ID-Type:)" do
%w(md5 MD5).each do |value|
specify value do
doc = BlueFeather::Document.new({'Header-ID-Type' => value})
doc.header_id_type.should == BlueFeather::HeaderIDType::MD5
end
end
%w(escape Escape ESCAPE).each do |value|
specify value do
doc = BlueFeather::Document.new({'Header-ID-Type' => value})
doc.header_id_type.should == BlueFeather::HeaderIDType::ESCAPE
end
end
end
describe 'Anchor Briefing Link:' do
specify 'equal' do
BlueFeather.parse_text('[FooBar](#)').should == BlueFeather.parse_text('[FooBar](#FooBar)')
end
end
|