diff options
| author | Dan Allen <dallen@redhat.com> | 2013-04-20 12:49:51 -0600 |
|---|---|---|
| committer | Dan Allen <dallen@redhat.com> | 2013-04-22 12:26:48 -0600 |
| commit | efeda152d248735bc2ccfcb580010fa7a5dfac92 (patch) | |
| tree | 4510aa744f70541ee09f52e939c90278aeb0fedb /test | |
| parent | 7705123f8dc9e89468ac5b86ce4862809d46d5a3 (diff) | |
resolves #187 complete masquerade functionality for blocks & paragraphs
- rework block parsing
- move block creation to a separate method
- add method to assign or generate block caption
- add set_attr method to block
- use sets where appropriate to improve speed
- cleanup two-line section matching
- optimize reader operations
- add flags to control compliance w/ AsciiDoc
- tests for masquerading, captions and other compliance
Diffstat (limited to 'test')
| -rw-r--r-- | test/attributes_test.rb | 46 | ||||
| -rw-r--r-- | test/blocks_test.rb | 60 | ||||
| -rw-r--r-- | test/lists_test.rb | 49 | ||||
| -rw-r--r-- | test/paragraphs_test.rb | 226 | ||||
| -rw-r--r-- | test/sections_test.rb | 17 | ||||
| -rw-r--r-- | test/substitutions_test.rb | 4 | ||||
| -rw-r--r-- | test/tables_test.rb | 15 | ||||
| -rw-r--r-- | test/test_helper.rb | 4 |
8 files changed, 380 insertions, 41 deletions
diff --git a/test/attributes_test.rb b/test/attributes_test.rb index c2152d44..6dff6b6f 100644 --- a/test/attributes_test.rb +++ b/test/attributes_test.rb @@ -403,10 +403,10 @@ of the attribute named foo in your document. end - context "Block attributes" do - test "Position attributes assigned to block" do + context 'Block attributes' do + test 'Positional attributes assigned to block' do input = <<-EOS -[quote, Name, Source] +[quote, author, source] ____ A famous quote. ____ @@ -415,13 +415,13 @@ ____ qb = doc.blocks.first assert_equal 'quote', qb.attributes['style'] assert_equal 'quote', qb.attr(:style) - assert_equal 'Name', qb.attributes['attribution'] - assert_equal 'Source', qb.attributes['citetitle'] + assert_equal 'author', qb.attributes['attribution'] + assert_equal 'source', qb.attributes['citetitle'] end - test "Normal substitutions are performed on single-quoted attributes" do + test 'Normal substitutions are performed on single-quoted attributes' do input = <<-EOS -[quote, Name, 'http://wikipedia.org[Source]'] +[quote, author, 'http://wikipedia.org[source]'] ____ A famous quote. ____ @@ -430,8 +430,36 @@ ____ qb = doc.blocks.first assert_equal 'quote', qb.attributes['style'] assert_equal 'quote', qb.attr(:style) - assert_equal 'Name', qb.attributes['attribution'] - assert_equal '<a href="http://wikipedia.org">Source</a>', qb.attributes['citetitle'] + assert_equal 'author', qb.attributes['attribution'] + assert_equal '<a href="http://wikipedia.org">source</a>', qb.attributes['citetitle'] + end + + test 'attribute list may begin with space' do + input = <<-EOS +[ quote] +____ +A famous quote. +____ + EOS + + doc = document_from_string input + qb = doc.blocks.first + assert_equal 'quote', qb.attributes['style'] + end + + test 'attribute list may begin with comma' do + input = <<-EOS +[, author, source] +____ +A famous quote. +____ + EOS + + doc = document_from_string input + qb = doc.blocks.first + assert_equal 'quote', qb.attributes['style'] + assert_equal 'author', qb.attributes['attribution'] + assert_equal 'source', qb.attributes['citetitle'] end test "Attribute substitutions are performed on attribute list before parsing attributes" do diff --git a/test/blocks_test.rb b/test/blocks_test.rb index 54c37c50..340bf515 100644 --- a/test/blocks_test.rb +++ b/test/blocks_test.rb @@ -558,8 +558,8 @@ Block content end end - context "Images" do - test "can render block image with alt text" do + context 'Images' do + test 'can render block image with alt text define in macro' do input = <<-EOS image::images/tiger.png[Tiger] EOS @@ -568,6 +568,26 @@ image::images/tiger.png[Tiger] assert_xpath '//*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1 end + test 'can render block image with alt text defined in above macro' do + input = <<-EOS +[Tiger] +image::images/tiger.png[] + EOS + + output = render_string input + assert_xpath '//*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1 + end + + test 'alt text in macro overrides alt text above macro' do + input = <<-EOS +[Alt Text] +image::images/tiger.png[Tiger] + EOS + + output = render_string input + assert_xpath '//*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1 + end + test "can render block image with auto-generated alt text" do input = <<-EOS image::images/tiger.png[] @@ -608,6 +628,42 @@ image::images/tiger.png[Tiger] assert_equal 1, doc.attributes['figure-number'] end + test 'can render block image with explicit caption' do + input = <<-EOS +[caption="Voila! "] +.The AsciiDoc Tiger +image::images/tiger.png[Tiger] + EOS + + doc = document_from_string input + output = doc.render + assert_xpath '//*[@class="imageblock"]//img[@src="images/tiger.png"][@alt="Tiger"]', output, 1 + assert_xpath '//*[@class="imageblock"]/*[@class="title"][text() = "Voila! The AsciiDoc Tiger"]', output, 1 + assert !doc.attributes.has_key?('figure-number') + end + + test 'drops line if image target is missing attribute reference' do + input = <<-EOS +image::{bogus}[] + EOS + + output = render_embedded_string input + assert output.strip.empty? + end + + test 'dropped image does not break processing of following section' do + input = <<-EOS +image::{bogus}[] + +== Section Title + EOS + + output = render_embedded_string input + assert_css 'img', output, 0 + assert_css 'h2', output, 1 + assert !output.include?('== Section Title') + end + test 'should pass through image that is a uri reference' do input = <<-EOS :imagesdir: images diff --git a/test/lists_test.rb b/test/lists_test.rb index 11e7e855..10ead704 100644 --- a/test/lists_test.rb +++ b/test/lists_test.rb @@ -2666,6 +2666,55 @@ para assert_xpath '//*[@class="dlist"]//dd/*[@class="paragraph"]', output, 1 assert_xpath '//*[@class="dlist"]//dd/*[@class="paragraph"]/p[text()="para"]', output, 1 end + + test 'attached paragraph does not break on adjacent nested labeled list term' do + input = <<-EOS +term1:: def ++ +more definition +not a term::: def + EOS + + output = render_embedded_string input + assert_css '.dlist > dl > dt', output, 1 + assert_css '.dlist > dl > dd', output, 1 + assert_css '.dlist > dl > dd > .paragraph', output, 1 + assert output.include?('not a term::: def') + end + + # FIXME pending +=begin + test 'attached paragraph does not break on adjacent sibling labeled list term' do + input = <<-EOS +term1:: def ++ +more definition +not a term:: def + EOS + + output = render_embedded_string input + assert_css '.dlist > dl > dt', output, 1 + assert_css '.dlist > dl > dd', output, 1 + assert_css '.dlist > dl > dd > .paragraph', output, 1 + assert output.include?('not a term:: def') + end +=end + + test 'attached styled paragraph does not break on adjacent nested labeled list term' do + input = <<-EOS +term1:: def ++ +[quote] +more definition +not a term::: def + EOS + + output = render_embedded_string input + assert_css '.dlist > dl > dt', output, 1 + assert_css '.dlist > dl > dd', output, 1 + assert_css '.dlist > dl > dd > .quoteblock', output, 1 + assert output.include?('not a term::: def') + end test 'appends line as paragraph if attached by continuation following blank line and line comment when term has no inline definition' do input = <<-EOS diff --git a/test/paragraphs_test.rb b/test/paragraphs_test.rb index 0360f165..796bdfe4 100644 --- a/test/paragraphs_test.rb +++ b/test/paragraphs_test.rb @@ -1,21 +1,53 @@ require 'test_helper' -context "Paragraphs" do +context 'Paragraphs' do context 'Normal' do - test "rendered correctly" do - assert_xpath "//p", render_string("Plain text for the win.\n\nYes, plainly."), 2 + test 'should treat plain text separated by blank lines as paragraphs' do + input = <<-EOS +Plain text for the win! + +Yep. Text. Plain and simple. + EOS + output = render_embedded_string input + assert_css 'p', output, 2 + assert_xpath '(//p)[1][text() = "Plain text for the win!"]', output, 1 + assert_xpath '(//p)[2][text() = "Yep. Text. Plain and simple."]', output, 1 end - test "with title" do - rendered = render_string(".Titled\nParagraph.\n\nWinning") + test 'should associate block title with paragraph' do + input = <<-EOS +.Titled +Paragraph. + +Winning. + EOS + output = render_embedded_string input - assert_xpath "//div[@class='title']", rendered - assert_xpath "//p", rendered, 2 + assert_css 'p', output, 2 + assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"]', output, 1 + assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"][text() = "Titled"]', output, 1 + assert_xpath '(//p)[2]/preceding-sibling::*[@class = "title"]', output, 0 end - test "no duplicate block before next section" do - rendered = render_string("Title\n=====\n\nPreamble.\n\n== First Section\n\nParagraph 1\n\nParagraph 2\n\n\n== Second Section\n\nLast words") - assert_xpath '//p[text()="Paragraph 2"]', rendered, 1 + test 'no duplicate block before next section' do + input = <<-EOS += Title + +Preamble + +== First Section + +Paragraph 1 + +Paragraph 2 + +== Second Section + +Last words + EOS + + output = render_string input + assert_xpath '//p[text() = "Paragraph 2"]', output, 1 end test 'does not treat wrapped line as a list item' do @@ -40,6 +72,62 @@ paragraph assert_xpath %(//p[text()="paragraph\n.wrapped line"]), output, 1 end + test 'interprets normal paragraph style as normal paragraph' do + input = <<-EOS +[normal] +Normal paragraph. +Nothing special. + EOS + + output = render_embedded_string input + assert_css 'p', output, 1 + end + + test 'normal paragraph terminates at block attribute list' do + input = <<-EOS +normal text +[literal] +literal text + EOS + output = render_embedded_string input + assert_css '.paragraph:root', output, 1 + assert_css '.literalblock:root', output, 1 + end + + test 'normal paragraph terminates at block delimiter' do + input = <<-EOS +normal text +-- +text in open block +-- + EOS + output = render_embedded_string input + assert_css '.paragraph:root', output, 1 + assert_css '.openblock:root', output, 1 + end + + test 'normal paragraph terminates at list continuation' do + input = <<-EOS +normal text ++ + EOS + output = render_embedded_string input + assert_css '.paragraph:root', output, 2 + assert_xpath %((/*[@class="paragraph"])[1]/p[text() = "normal text"]), output, 1 + assert_xpath %((/*[@class="paragraph"])[2]/p[text() = "+"]), output, 1 + end + + test 'normal style turns literal paragraph into normal paragraph' do + input = <<-EOS +[normal] + normal paragraph, + despite the leading indent + EOS + + output = render_embedded_string input + assert_css '.paragraph:root > p', output, 1 + end + test 'expands index term macros in DocBook backend' do input = <<-EOS Here is an index entry for ((tigers)). @@ -93,12 +181,20 @@ Note that multi-entry terms generate separate index entries. end end - context "code" do - test "single-line literal paragraphs" do - assert_xpath "//pre", render_string(" LITERALS\n\n ARE LITERALLY\n\n AWESOMMMME.") + context 'Literal' do + test 'single-line literal paragraphs' do + input = <<-EOS + LITERALS + + ARE LITERALLY + + AWESOME! + EOS + output = render_embedded_string input + assert_xpath '//pre', output, 3 end - test "multi-line literal paragraph" do + test 'multi-line literal paragraph' do input = <<-EOS Install instructions: @@ -107,29 +203,95 @@ Install instructions: You're good to go! EOS - output = render_string(input) - assert_xpath "//pre", output, 1 - assert_match(/^gem install asciidoctor/, output, "Indentation should be trimmed from literal block") + output = render_embedded_string input + assert_xpath '//pre', output, 1 + # indentation should be trimmed from literal block + assert_xpath %(//pre[text() = "yum install ruby rubygems\ngem install asciidoctor"]), output, 1 + end + + test 'literal paragraph' do + input = <<-EOS +[literal] +this text is literally literal + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="literalblock"]//pre[text()="this text is literally literal"]), output, 1 + end + + test 'should read content below literal style verbatim' do + input = <<-EOS +[literal] +image::not-an-image-block[] + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="literalblock"]//pre[text()="image::not-an-image-block[]"]), output, 1 + assert_css 'img', output, 0 + end + + test 'listing paragraph' do + input = <<-EOS +[listing] +this text is a listing + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="listingblock"]//pre[text()="this text is a listing"]), output, 1 + end + + test 'source paragraph' do + input = <<-EOS +[source] +use the source, luke! + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="listingblock"]//pre[@class="highlight"]/code[text()="use the source, luke!"]), output, 1 end - test "literal paragraph" do - assert_xpath "//*[@class='literalblock']//pre[text()='blah blah blah']", render_string("[literal]\nblah blah blah") + test 'source code paragraph with language' do + input = <<-EOS +[source, perl] +die 'zomg perl sucks'; + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="listingblock"]//pre[@class="highlight"]/code[@class="perl"][text()="die 'zomg perl sucks';"]), output, 1 end - test "listing paragraph" do - assert_xpath "//*[@class='listingblock']//pre[text()='blah blah blah']", render_string("[listing]\nblah blah blah") + test 'literal paragraph terminates at block attribute list' do + input = <<-EOS + literal text +[normal] +normal text + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="literalblock"]), output, 1 + assert_xpath %(/*[@class="paragraph"]), output, 1 end - test "source code paragraph" do - assert_xpath "//pre[@class='highlight']/code", render_string("[source]\nblah blah blah") + test 'literal paragraph terminates at block delimiter' do + input = <<-EOS + literal text +-- +normal text +-- + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="literalblock"]), output, 1 + assert_xpath %(/*[@class="openblock"]), output, 1 end - test "source code paragraph with language" do - assert_xpath "//pre[@class='highlight']/code[@class='perl']", render_string("[source, perl]\ndie 'zomg perl sucks';") + test 'literal paragraph terminates at list continuation' do + input = <<-EOS + literal text ++ + EOS + output = render_embedded_string input + assert_xpath %(/*[@class="literalblock"]), output, 1 + assert_xpath %(/*[@class="literalblock"]//pre[text() = "literal text"]), output, 1 + assert_xpath %(/*[@class="paragraph"]), output, 1 + assert_xpath %(/*[@class="paragraph"]/p[text() = "+"]), output, 1 end end - context "quote" do + context 'Quote' do test "quote block" do output = render_string("____\nFamous quote.\n____") assert_xpath '//*[@class = "quoteblock"]', output, 1 @@ -157,6 +319,18 @@ You're good to go! assert_xpath '//*[@class = "quoteblock"]//*[contains(text(), "Famous quote.")]', output, 1 end + test 'quote paragraph terminates at list continuation' do + input = <<-EOS +[quote] +A famouse quote. ++ + EOS + output = render_embedded_string input + assert_css '.quoteblock:root', output, 1 + assert_css '.paragraph:root', output, 1 + assert_xpath %(/*[@class="paragraph"]/p[text() = "+"]), output, 1 + end + test "verse paragraph" do output = render_string("[verse]\nFamous verse.") assert_xpath '//*[@class = "verseblock"]', output, 1 diff --git a/test/sections_test.rb b/test/sections_test.rb index cd881d47..4bf2891f 100644 --- a/test/sections_test.rb +++ b/test/sections_test.rb @@ -257,6 +257,23 @@ not in section assert floatingtitle.is_a?(Asciidoctor::Block) assert !floatingtitle.is_a?(Asciidoctor::Section) assert_equal :floating_title, floatingtitle.context + assert_equal '_plain_ol_heading', floatingtitle.id + assert doc.references[:ids].has_key?('_plain_ol_heading') + end + + test 'can assign explicit id to floating title' do + input = <<-EOS +[[unchained]] +[float] +=== Plain Ol' Heading + +not in section + EOS + + doc = document_from_string input + floating_title = doc.blocks.first + assert_equal 'unchained', floating_title.id + assert doc.references[:ids].has_key?('unchained') end test 'should not include floating title in toc' do diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb index 4db8146f..c720f828 100644 --- a/test/substitutions_test.rb +++ b/test/substitutions_test.rb @@ -255,8 +255,8 @@ context 'Substitutions' do end test 'multi-line superscript chars' do - para = block_from_string(%Q{x^(n\n+\n1)^}) - assert_equal "x<sup>(n\n+\n1)</sup>", para.sub_quotes(para.buffer.join) + para = block_from_string(%Q{x^(n\n-\n1)^}) + assert_equal "x<sup>(n\n-\n1)</sup>", para.sub_quotes(para.buffer.join) end test 'single-line subscript chars' do diff --git a/test/tables_test.rb b/test/tables_test.rb index b8e15783..8980ce90 100644 --- a/test/tables_test.rb +++ b/test/tables_test.rb @@ -43,6 +43,21 @@ context 'Tables' do assert_xpath '/table/caption/following-sibling::colgroup', output, 1 end + test 'renders explicit caption on simple psv table' do + input = <<-EOS +[caption="All the Data. "] +.Simple psv table +|======= +|A |B |C +|a |b |c +|1 |2 |3 +|======= + EOS + output = render_embedded_string input + assert_xpath '/table/caption[@class="title"][text()="All the Data. Simple psv table"]', output, 1 + assert_xpath '/table/caption/following-sibling::colgroup', output, 1 + end + test 'ignores escaped separators' do input = <<-EOS |=== diff --git a/test/test_helper.rb b/test/test_helper.rb index 9e5f63bb..b3653f01 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -67,8 +67,8 @@ class Test::Unit::TestCase xmlnodes_at_path(:css, css, content) end - def xmlnodes_at_xpath(css, content, count = nil) - xmlnodes_at_path(:xpath, css, content) + def xmlnodes_at_xpath(xpath, content, count = nil) + xmlnodes_at_path(:xpath, xpath, content) end def xmlnodes_at_path(type, path, content, count = nil) |
