summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-01-03 05:43:43 -0700
committerDan Allen <dan.j.allen@gmail.com>2013-01-03 05:43:43 -0700
commitfe13ace9ad2bef848a7105f86290d3e4b09a5be2 (patch)
tree8871027042c1322e54c61e8863e19ddc6023a6a4 /test
parentc8251210e324053a26c4884d8d86341c12dc8f88 (diff)
Add DocBook backend templates + loads of improvements
- make templates for docbook45 backend - move backend templates to backends/ folder - load backend templates lazily (based on backend attribute) - namespace backend templates to avoid conflicts - extend backend templates from a base template - add view property to template class - change InlineLink to InlineAnchor and assign type (:link or :xref) - simplify shorthand methods (e.g., define attribute) in template classes - set default backend to html5 - set backend attribute family (backend-*, basebackend, etc) - set docdate and doctime attributes (match local* w/o file ref) - prevent Reader from overriding attributes passed to Document.new - fix list continuation bug in outline and labeled lists - fold first paragraph properly in outline lists; document in TomDoc - add convenience methods to String (trim, nuke) - add TomDoc to methods added to String - add tests for String monkeypatches - fix compliance of attribute continuations in Reader - perform attribute substitutions on document attributes and attribute lists - apply normal subs to single-quoted attribute values - cleanup how substitutions are called - don't need Asciidoctor:: prefix in Substituter - honor line pass: macro in document attribute value - move regexs in Reader to Asciidoctor module - use %r{} syntax to make some regex easier to read - fix order of replacements - add ellipsis and single quote replacements - add space, quot and apos to instrinsics - move Substituters mixin to AbstractBlock - make Document an AbstractBlock - use blocks instance variable in Document instead of elements - document should store text of reference to match how docbook works - allow Document.new to be called w/ no arguments - rename level* regex to section* - loads of tests to verify numerous compliance checks and for new functionality - more TomDoc
Diffstat (limited to 'test')
-rw-r--r--test/attributes_test.rb349
-rw-r--r--test/blocks_test.rb2
-rw-r--r--test/document_test.rb215
-rw-r--r--test/headers_test.rb2
-rw-r--r--test/lexer_test.rb10
-rw-r--r--test/lists_test.rb48
-rw-r--r--test/paragraphs_test.rb26
-rw-r--r--test/preamble_test.rb2
-rw-r--r--test/reader_test.rb154
-rw-r--r--test/string_test.rb63
-rw-r--r--test/substitutions_test.rb25
-rw-r--r--test/test_helper.rb17
-rw-r--r--test/text_test.rb20
13 files changed, 717 insertions, 216 deletions
diff --git a/test/attributes_test.rb b/test/attributes_test.rb
index 88882882..ff781b06 100644
--- a/test/attributes_test.rb
+++ b/test/attributes_test.rb
@@ -1,104 +1,236 @@
require 'test_helper'
-context "Attributes" do
- test "creates an attribute" do
- doc = document_from_string(":frog: Tanglefoot")
- assert_equal doc.attributes['frog'], 'Tanglefoot'
- end
+context 'Attributes' do
+ context 'Assignment' do
+ test 'creates an attribute' do
+ doc = document_from_string(':frog: Tanglefoot')
+ assert_equal 'Tanglefoot', doc.attributes['frog']
+ end
- test "creates an attribute by fusing a multi-line value" do
- str = <<-EOS
+ test 'creates an attribute by fusing a multi-line value' do
+ str = <<-EOS
:description: This is the first +
Ruby implementation of +
AsciiDoc.
- EOS
- doc = document_from_string(str)
- assert_equal doc.attributes['description'], 'This is the first Ruby implementation of AsciiDoc.'
- end
+ EOS
+ doc = document_from_string(str)
+ assert_equal 'This is the first Ruby implementation of AsciiDoc.', doc.attributes['description']
+ end
- test "deletes an attribute" do
- doc = document_from_string(":frog: Tanglefoot\n:frog!:")
- assert_equal nil, doc.attributes['frog']
- end
+ test 'deletes an attribute' do
+ doc = document_from_string(":frog: Tanglefoot\n:frog!:")
+ assert_equal nil, doc.attributes['frog']
+ end
- test "doesn't choke when deleting a non-existing attribute" do
- doc = document_from_string(":frog!:")
- assert_equal nil, doc.attributes['frog']
- end
+ test "doesn't choke when deleting a non-existing attribute" do
+ doc = document_from_string(':frog!:')
+ assert_equal nil, doc.attributes['frog']
+ end
- test "render properly with simple names" do
- html = render_string(":frog: Tanglefoot\nYo, {frog}!")
- result = Nokogiri::HTML(html)
- assert_equal 'Yo, Tanglefoot!', result.css("p").first.content.strip
- end
+ test "replaces special characters in attribute value" do
+ doc = document_from_string(":xml-busters: <>&")
+ assert_equal '&lt;&gt;&amp;', doc.attributes['xml-busters']
+ end
- test "render properly with single character name" do
- html = render_string(":r: Ruby\n\nR is for {r}!")
- result = Nokogiri::HTML(html)
- assert_equal 'R is for Ruby!', result.css("p").first.content.strip
- end
+ test "performs attribute substitution on attribute value" do
+ doc = document_from_string(":version: 1.0\n:release: Asciidoctor {version}")
+ assert_equal 'Asciidoctor 1.0', doc.attributes['release']
+ end
- test "convert multi-word names and render" do
- html = render_string("Main Header\n===========\n:My frog: Tanglefoot\n\nYo, {myfrog}!")
- result = Nokogiri::HTML(html)
- assert_equal 'Yo, Tanglefoot!', result.css("p").first.content.strip
- end
+ test "assigns attribute to empty string if substitution fails to resolve attribute" do
+ doc = document_from_string(":release: Asciidoctor {version}")
+ assert_equal '', doc.attributes['release']
+ end
- test "ignores lines with bad attributes" do
- html = render_string("This is\nblah blah {foobarbaz}\nall there is.")
- result = Nokogiri::HTML(html)
- assert_no_match /blah blah/m, result.css("p").first.content.strip
- end
+ test "assigns multi-line attribute to empty string if substitution fails to resolve attribute" do
+ doc = document_from_string(":release: Asciidoctor +\n {version}")
+ assert_equal '', doc.attributes['release']
+ end
- # See above - AsciiDoc says we're supposed to delete lines with bad
- # attribute refs in them. AsciiDoc is strange.
- #
- # test "Unknowns" do
- # html = render_string("Look, a {gobbledygook}")
- # result = Nokogiri::HTML(html)
- # assert_equal("Look, a {gobbledygook}", result.css("p").first.content.strip)
- # end
-
- test "substitutes inside unordered list items" do
- html = render_string(":foo: bar\n* snort at the {foo}\n* yawn")
- result = Nokogiri::HTML(html)
- assert_match /snort at the bar/, result.css("li").first.content.strip
- end
+ test "apply custom substitutions to text in passthrough macro and assign to attribute" do
+ doc = document_from_string(":xml-busters: pass:[<>&]")
+ assert_equal '<>&', doc.attributes['xml-busters']
+ doc = document_from_string(":xml-busters: pass:none[<>&]")
+ assert_equal '<>&', doc.attributes['xml-busters']
+ doc = document_from_string(":xml-busters: pass:specialcharacters[<>&]")
+ assert_equal '&lt;&gt;&amp;', doc.attributes['xml-busters']
+ end
- test "substitutes inside heading" do
- output = render_string(":prefix: Cool\n\n== {prefix} Title\n\ncontent")
- result = Nokogiri::HTML(output)
- assert_match /Cool Title/, result.css('h2').first.content
- assert_match /_cool_title/, result.css('h2').first.attr('id')
- end
+ test "attribute is treated as defined until it's not" do
+ input = <<-EOS
+:holygrail:
+ifdef::holygrail[]
+The holy grail has been found!
+endif::holygrail[]
+
+:holygrail!:
+ifndef::holygrail[]
+Buggers! What happened to the grail?
+endif::holygrail[]
+ EOS
+ output = render_string input
+ assert_xpath '//p', output, 2
+ assert_xpath '(//p)[1][text() = "The holy grail has been found!"]', output, 1
+ assert_xpath '(//p)[2][text() = "Buggers! What happened to the grail?"]', output, 1
+ end
- test "renders attribute until it's deleted" do
- pending "Not working yet (will require adding element-specific attributes or early attr substitution during parsing)"
- # html = render_string(":foo: bar\nCrossing the {foo}\n\n:foo!:\nBelly up to the {foo}")
- # result = Nokogiri::HTML(html)
- # assert_match /Crossing the bar/, result.css("p").first.content.strip
- # assert_no_match /Belly up to the bar/, result.css("p").last.content.strip
- end
+ # Validates requirement: "Header attributes are overridden by command-line attributes."
+ test 'attribute defined in document options overrides attribute in document' do
+ doc = document_from_string(':cash: money', :attributes => {'cash' => 'heroes'})
+ assert_equal 'heroes', doc.attributes['cash']
+ end
- test "doesn't disturb attribute-looking things escaped with backslash" do
- html = render_string(":foo: bar\nThis is a \\{foo} day.")
- result = Nokogiri::HTML(html)
- assert_equal 'This is a {foo} day.', result.css('p').first.content.strip
- end
+ test 'attribute defined in document options cannot be unassigned in document' do
+ doc = document_from_string(':cash!:', :attributes => {'cash' => 'heroes'})
+ assert_equal 'heroes', doc.attributes['cash']
+ end
+
+ test 'attribute undefined in document options cannot be assigned in document' do
+ doc = document_from_string(':cash: money', :attributes => {'cash!' => 1 })
+ assert_equal nil, doc.attributes['cash']
+ doc = document_from_string(':cash: money', :attributes => {'cash' => nil })
+ assert_equal nil, doc.attributes['cash']
+ end
+
+ test 'backend attributes are updated if backend attribute is defined in document' do
+ doc = document_from_string(':backend: docbook45')
+ assert_equal 'docbook45', doc.attributes['backend']
+ assert doc.attributes.has_key? 'backend-docbook45'
+ assert_equal 'docbook', doc.attributes['basebackend']
+ assert doc.attributes.has_key? 'basebackend-docbook'
+ end
+
+ test 'backend attributes defined in document options overrides backend attribute in document' do
+ doc = document_from_string(':backend: docbook45', :attributes => {'backend' => 'html5'})
+ assert_equal 'html5', doc.attributes['backend']
+ assert doc.attributes.has_key? 'backend-html5'
+ assert_equal 'html', doc.attributes['basebackend']
+ assert doc.attributes.has_key? 'basebackend-html'
+ end
- test "doesn't disturb attribute-looking things escaped with literals" do
- #html = render_string(":foo: bar\nThis is a +++{foo}+++ day.")
- #result = Nokogiri::HTML(html)
- #assert_equal 'This is a {foo} day.', result.css('p').first.content.strip
- pending "Don't yet have inline passthrough working"
end
- test "doesn't substitute attributes inside code blocks" do
- pending "whut?"
+ context 'Interpolation' do
+
+ test "render properly with simple names" do
+ html = render_string(":frog: Tanglefoot\n:my_super-hero: Spiderman\n\nYo, {frog}!\nBeat {my_super-hero}!")
+ result = Nokogiri::HTML(html)
+ assert_equal "Yo, Tanglefoot!\nBeat Spiderman!", result.css("p").first.content.strip
+ end
+
+ test "render properly with single character name" do
+ html = render_string(":r: Ruby\n\nR is for {r}!")
+ result = Nokogiri::HTML(html)
+ assert_equal 'R is for Ruby!', result.css("p").first.content.strip
+ end
+
+ test "convert multi-word names and render" do
+ html = render_string("Main Header\n===========\n:My frog: Tanglefoot\n\nYo, {myfrog}!")
+ result = Nokogiri::HTML(html)
+ assert_equal 'Yo, Tanglefoot!', result.css("p").first.content.strip
+ end
+
+ test "ignores lines with bad attributes" do
+ html = render_string("This is\nblah blah {foobarbaz}\nall there is.")
+ result = Nokogiri::HTML(html)
+ assert_no_match /blah blah/m, result.css("p").first.content.strip
+ end
+
+ test "attribute value gets interpretted when rendering" do
+ doc = document_from_string(":google: http://google.com[Google]\n\n{google}")
+ assert_equal 'http://google.com[Google]', doc.attributes['google']
+ output = doc.render
+ assert_xpath '//a[@href="http://google.com"][text() = "Google"]', output, 1
+ end
+
+ # See above - AsciiDoc says we're supposed to delete lines with bad
+ # attribute refs in them. AsciiDoc is strange.
+ #
+ # test "Unknowns" do
+ # html = render_string("Look, a {gobbledygook}")
+ # result = Nokogiri::HTML(html)
+ # assert_equal("Look, a {gobbledygook}", result.css("p").first.content.strip)
+ # end
+
+ test "substitutes inside unordered list items" do
+ html = render_string(":foo: bar\n* snort at the {foo}\n* yawn")
+ result = Nokogiri::HTML(html)
+ assert_match /snort at the bar/, result.css("li").first.content.strip
+ end
+
+ test "substitutes inside heading" do
+ output = render_string(":prefix: Cool\n\n== {prefix} Title\n\ncontent")
+ result = Nokogiri::HTML(output)
+ assert_match /Cool Title/, result.css('h2').first.content
+ assert_match /_cool_title/, result.css('h2').first.attr('id')
+ end
+
+ test 'renders attribute until it is deleted' do
+ pending 'This requires that we consume attributes as the document is being lexed, not up front'
+ #output = render_string(":foo: bar\n\nCrossing the {foo}\n\n:foo!:\nBelly up to the {foo}")
+ # result = Nokogiri::HTML(html)
+ # assert_match /Crossing the bar/, result.css("p").first.content.strip
+ # assert_no_match /Belly up to the bar/, result.css("p").last.content.strip
+ end
+
+ test 'does not disturb attribute-looking things escaped with backslash' do
+ html = render_string(":foo: bar\nThis is a \\{foo} day.")
+ result = Nokogiri::HTML(html)
+ assert_equal 'This is a {foo} day.', result.css('p').first.content.strip
+ end
+
+ test 'does not disturb attribute-looking things escaped with literals' do
+ html = render_string(":foo: bar\nThis is a +++{foo}+++ day.")
+ result = Nokogiri::HTML(html)
+ assert_equal 'This is a {foo} day.', result.css('p').first.content.strip
+ end
+
+ test 'does not substitute attributes inside listing blocks' do
+ input = <<-EOS
+:forecast: snow
+
+----
+puts 'The forecast for today is {forecast}'
+----
+ EOS
+ output = render_string(input)
+ assert_match /\{forecast\}/, output
+ end
+
+ test 'does not substitute attributes inside literal blocks' do
+ input = <<-EOS
+:foo: bar
+
+....
+You insert the text {foo} to expand the value
+of the attribute named foo in your document.
+....
+ EOS
+ output = render_string(input)
+ assert_match /\{foo\}/, output
+ end
end
- test "doesn't substitute attributes inside literal blocks" do
- pending "whut?"
+ context "Intrinsic attributes" do
+
+ test "substitute intrinsics" do
+ Asciidoctor::INTRINSICS.each_pair do |key, value|
+ html = render_string("Look, a {#{key}} is here")
+ # can't use Nokogiri because it interprets the HTML entities and we can't match them
+ assert_match /Look, a #{Regexp.escape(value)} is here/, html
+ end
+ end
+
+ test "don't escape intrinsic substitutions" do
+ html = render_string('happy{nbsp}together')
+ assert_match /happy&#160;together/, html
+ end
+
+ test "escape special characters" do
+ html = render_string('<node>&</node>')
+ assert_match /&lt;node&gt;&amp;&lt;\/node&gt;/, html
+ end
+
end
context "Block attributes" do
@@ -131,13 +263,40 @@ A famous quote.
____
EOS
doc = document_from_string(input)
- qb = doc.elements.first
+ 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']
end
+ test "Normal substitutions are performed on single-quoted attributes" do
+ input = <<-EOS
+[quote, Name, 'http://wikipedia.org[Source]']
+____
+A famous quote.
+____
+ EOS
+ doc = document_from_string(input)
+ 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']
+ end
+
+ test "Attribute substitutions are performed on attribute list before parsing attributes" do
+ input = <<-EOS
+:lead: role="lead"
+
+[{lead}]
+A paragraph
+ EOS
+ doc = document_from_string(input)
+ para = doc.blocks.first
+ assert_equal 'lead', para.attributes['role']
+ end
+
test "Block attributes are additive" do
input = <<-EOS
[id='foo']
@@ -145,7 +304,7 @@ ____
A paragraph.
EOS
doc = document_from_string(input)
- para = doc.elements.first
+ para = doc.blocks.first
assert_equal 'foo', para.id
assert_equal 'lead', para.attributes['role']
end
@@ -195,36 +354,14 @@ block comment
content
EOS
doc = document_from_string(input)
- section_one = doc.elements.first
+ section_one = doc.blocks.first
assert_equal 'one', section_one.id
subsection = section_one.blocks.last
assert_equal 'sub', subsection.id
- section_two = doc.elements.last
+ section_two = doc.blocks.last
assert_equal 'classy', section_two.attr(:role)
assert !doc.attributes.has_key?('orphaned')
end
end
- context "intrinsics" do
-
- test "substitute intrinsics" do
- Asciidoctor::INTRINSICS.each_pair do |key, value|
- html = render_string("Look, a {#{key}} is here")
- # can't use Nokogiri because it interprets the HTML entities and we can't match them
- assert_match /Look, a #{Regexp.escape(value)} is here/, html
- end
- end
-
- test "don't escape intrinsic substitutions" do
- html = render_string('happy{nbsp}together')
- assert_match /happy&#160;together/, html
- end
-
- test "escape special characters" do
- html = render_string('<node>&</node>')
- assert_match /&lt;node&gt;&amp;&lt;\/node&gt;/, html
- end
-
- end
-
end
diff --git a/test/blocks_test.rb b/test/blocks_test.rb
index 11a83f2c..17544140 100644
--- a/test/blocks_test.rb
+++ b/test/blocks_test.rb
@@ -36,7 +36,7 @@ context "Blocks" do
test "trailing endlines after block comment at end of document does not create paragraph" do
d = document_from_string("Paragraph\n\n////\nblock comment\n////\n\n")
- assert_equal 1, d.elements.size
+ assert_equal 1, d.blocks.size
end
end
diff --git a/test/document_test.rb b/test/document_test.rb
index 10a0b263..a7c6a052 100644
--- a/test/document_test.rb
+++ b/test/document_test.rb
@@ -1,48 +1,86 @@
require 'test_helper'
-context "Document" do
+context 'Document' do
- context "Example document" do
- setup do
+ context 'Example document' do
+ test 'test_title' do
@doc = example_document(:asciidoc_index)
+ assert_equal 'AsciiDoc Home Page', @doc.doctitle
+ assert_equal 'AsciiDoc Home Page', @doc.name
+ assert_equal 14, @doc.blocks.size
+ assert_equal :preamble, @doc.blocks[0].context
+ assert @doc.blocks[1].is_a? ::Asciidoctor::Section
end
+ end
- test "test_title" do
- assert_equal "AsciiDoc Home Page", @doc.doctitle
- assert_equal "AsciiDoc Home Page", @doc.name
- assert_equal 14, @doc.elements.size
- assert_equal :preamble, @doc.elements[0].context
- assert @doc.elements[1].is_a? ::Asciidoctor::Section
+ context 'Renderer' do
+ test 'built-in HTML5 views are registered by default' do
+ doc = document_from_string ''
+ assert_equal 'html5', doc.attributes['backend']
+ assert doc.attributes.has_key? 'backend-html5'
+ assert_equal 'html', doc.attributes['basebackend']
+ assert doc.attributes.has_key? 'basebackend-html'
+ renderer = doc.renderer
+ assert !renderer.nil?
+ views = renderer.views
+ assert !views.nil?
+ assert_equal 23, views.size
+ assert views.has_key? 'document'
+ assert views['document'].is_a?(Asciidoctor::HTML5::DocumentTemplate)
end
- end
- test "test_with_no_title" do
- d = document_from_string("Snorf")
- assert_nil d.doctitle
- assert_nil d.name
- assert !d.has_header
- assert_nil d.header
+ test 'built-in DocBook45 views are registered when backend is docbook45' do
+ doc = document_from_string '', :attributes => {'backend' => 'docbook45'}
+ renderer = doc.renderer
+ assert_equal 'docbook45', doc.attributes['backend']
+ assert doc.attributes.has_key? 'backend-docbook45'
+ assert_equal 'docbook', doc.attributes['basebackend']
+ assert doc.attributes.has_key? 'basebackend-docbook'
+ assert !renderer.nil?
+ views = renderer.views
+ assert !views.nil?
+ assert_equal 23, views.size
+ assert views.has_key? 'document'
+ assert views['document'].is_a?(Asciidoctor::DocBook45::DocumentTemplate)
+ end
end
- test "test_with_explicit_title" do
- d = document_from_string("= Title\n:title: Document Title\n\npreamble\n\n== Section")
- assert_equal 'Document Title', d.doctitle
- assert_equal 'Document Title', d.title
- assert d.has_header
- assert_equal 'Title', d.header.title
- assert_equal 'Title', d.first_section.title
- end
+ context 'Structure' do
+ test 'test_with_no_title' do
+ doc = document_from_string('Snorf')
+ assert_nil doc.doctitle
+ assert_nil doc.name
+ assert !doc.has_header?
+ assert_nil doc.header
+ end
- test "test_empty_document" do
- d = document_from_string('')
- assert d.elements.empty?
- assert_nil d.doctitle
- assert !d.has_header
- assert_nil d.header
- end
+ test 'test_with_explicit_title' do
+ input = <<-EOS
+= Title
+:title: Document Title
+
+preamble
+
+== First Section
+ EOS
+ doc = document_from_string input
+ assert_equal 'Document Title', doc.doctitle
+ assert_equal 'Document Title', doc.title
+ assert doc.has_header?
+ assert_equal 'Title', doc.header.title
+ assert_equal 'Title', doc.first_section.title
+ end
- test "test_with_metadata" do
- input = <<-EOS
+ test 'test_empty_document' do
+ doc = document_from_string('')
+ assert doc.blocks.empty?
+ assert_nil doc.doctitle
+ assert !doc.has_header?
+ assert_nil doc.header
+ end
+
+ test 'test_with_metadata' do
+ input = <<-EOS
= AsciiDoc
Stuart Rackham <founder@asciidoc.org>
v8.6.8, 2012-07-12: See changelog.
@@ -50,28 +88,99 @@ v8.6.8, 2012-07-12: See changelog.
== Version 8.6.8
more info...
- EOS
- output = render_string input
- assert_xpath '//*[@id="header"]/span[@id="author"][text() = "Stuart Rackham"]', output, 1
- assert_xpath '//*[@id="header"]/span[@id="email"][contains(text(), "founder@asciidoc.org")]', output, 1
- assert_xpath '//*[@id="header"]/span[@id="revnumber"][text() = "version 8.6.8,"]', output, 1
- assert_xpath '//*[@id="header"]/span[@id="revdate"][text() = "2012-07-12"]', output, 1
- assert_xpath '//*[@id="header"]/span[@id="revremark"][text() = "See changelog."]', output, 1
- end
+ EOS
+ output = render_string input
+ assert_xpath '//*[@id="header"]/span[@id="author"][text() = "Stuart Rackham"]', output, 1
+ assert_xpath '//*[@id="header"]/span[@id="email"][contains(text(), "founder@asciidoc.org")]', output, 1
+ assert_xpath '//*[@id="header"]/span[@id="revnumber"][text() = "version 8.6.8,"]', output, 1
+ assert_xpath '//*[@id="header"]/span[@id="revdate"][text() = "2012-07-12"]', output, 1
+ assert_xpath '//*[@id="header"]/span[@id="revremark"][text() = "See changelog."]', output, 1
+ end
- test "test_with_header_footer" do
- result = render_string("= Title\n\npreamble")
- assert_xpath '/html', result, 1
- assert_xpath '//*[@id="header"]', result, 1
- assert_xpath '//*[@id="footer"]', result, 1
- assert_xpath '//*[@id="preamble"]', result, 1
+ test 'test_with_header_footer' do
+ result = render_string("= Title\n\npreamble")
+ assert_xpath '/html', result, 1
+ assert_xpath '//*[@id="header"]', result, 1
+ assert_xpath '//*[@id="footer"]', result, 1
+ assert_xpath '//*[@id="preamble"]', result, 1
+ end
+
+ test 'test_with_no_header_footer' do
+ result = render_string("= Title\n\npreamble", :header_footer => false)
+ assert_xpath '/html', result, 0
+ assert_xpath '/*[@id="header"]', result, 0
+ assert_xpath '/*[@id="footer"]', result, 0
+ assert_xpath '/*[@id="preamble"]', result, 1
+ end
end
- test "test_with_no_header_footer" do
- result = render_string("= Title\n\npreamble", :header_footer => false)
- assert_xpath '/html', result, 0
- assert_xpath '/*[@id="header"]', result, 0
- assert_xpath '/*[@id="footer"]', result, 0
- assert_xpath '/*[@id="preamble"]', result, 1
+ context 'Backends and Doctypes' do
+ test 'test_html5_backend_doctype_article' do
+ result = render_string("= Title\n\npreamble", :attributes => {'backend' => 'html5'})
+ assert_xpath '/html', result, 1
+ assert_xpath '/html/body[@class="article"]', result, 1
+ assert_xpath '/html//*[@id="header"]/h1[text() = "Title"]', result, 1
+ assert_xpath '/html//*[@id="preamble"]//p[text() = "preamble"]', result, 1
+ end
+
+ test 'test_html5_backend_doctype_book' do
+ result = render_string("= Title\n\npreamble", :attributes => {'backend' => 'html5', 'doctype' => 'book'})
+ assert_xpath '/html', result, 1
+ assert_xpath '/html/body[@class="book"]', result, 1
+ assert_xpath '/html//*[@id="header"]/h1[text() = "Title"]', result, 1
+ assert_xpath '/html//*[@id="preamble"]//p[text() = "preamble"]', result, 1
+ end
+
+ test 'test_docbook45_backend_doctype_article' do
+ input = <<-EOS
+= Title
+
+preamble
+
+== First Section
+
+section body
+ EOS
+ result = render_string(input, :attributes => {'backend' => 'docbook45'})
+ assert_xpath '/article', result, 1
+ assert_xpath '/article/articleinfo/title[text() = "Title"]', result, 1
+ assert_xpath '/article/simpara[text() = "preamble"]', result, 1
+ assert_xpath '/article/section', result, 1
+ assert_xpath '/article/section[@id = "_first_section"]/title[text() = "First Section"]', result, 1
+ assert_xpath '/article/section[@id = "_first_section"]/simpara[text() = "section body"]', result, 1
+ end
+
+ test 'test_docbook45_backend_doctype_article_no_title' do
+ result = render_string('text', :attributes => {'backend' => 'docbook45'})
+ assert_xpath '/article', result, 1
+ assert_xpath '/article/articleinfo/date', result, 1
+ assert_xpath '/article/simpara[text() = "text"]', result, 1
+ end
+
+ test 'test_docbook45_backend_doctype_book' do
+ input = <<-EOS
+= Title
+
+preamble
+
+== First Chapter
+
+chapter body
+ EOS
+ result = render_string(input, :attributes => {'backend' => 'docbook45', 'doctype' => 'book'})
+ assert_xpath '/book', result, 1
+ assert_xpath '/book/bookinfo/title[text() = "Title"]', result, 1
+ assert_xpath '/book/preface/simpara[text() = "preamble"]', result, 1
+ assert_xpath '/book/chapter', result, 1
+ assert_xpath '/book/chapter[@id = "_first_chapter"]/title[text() = "First Chapter"]', result, 1
+ assert_xpath '/book/chapter[@id = "_first_chapter"]/simpara[text() = "chapter body"]', result, 1
+ end
+
+ test 'test_docbook45_backend_doctype_book_no_title' do
+ result = render_string('text', :attributes => {'backend' => 'docbook45', 'doctype' => 'book'})
+ assert_xpath '/book', result, 1
+ assert_xpath '/book/bookinfo/date', result, 1
+ assert_xpath '/book/simpara[text() = "text"]', result, 1
+ end
end
end
diff --git a/test/headers_test.rb b/test/headers_test.rb
index d8a05a1f..4acc4320 100644
--- a/test/headers_test.rb
+++ b/test/headers_test.rb
@@ -76,7 +76,7 @@ context "Headers" do
end
test "with non-word character" do
- assert_xpath "//h2[@id='_where_s_the_love'][text() = \"Where's the love?\"]", render_string("== Where's the love?")
+ assert_xpath "//h2[@id='_where_s_the_love'][text() = \"Where#{[8217].pack('U*')}s the love?\"]", render_string("== Where's the love?")
end
test "with sequential non-word characters" do
diff --git a/test/lexer_test.rb b/test/lexer_test.rb
index 6a33fd30..b212f4e6 100644
--- a/test/lexer_test.rb
+++ b/test/lexer_test.rb
@@ -8,19 +8,19 @@ context "Lexer" do
end
test "test_is_title_section" do
- section = Asciidoctor::Section.new(Asciidoctor::Document.new([]))
+ section = Asciidoctor::Section.new(Asciidoctor::Document.new)
section.level = 0
assert Asciidoctor::Lexer.is_title_section?(section, section.document)
end
test "test_is_not_title_section" do
- section = Asciidoctor::Section.new(Asciidoctor::Document.new([]))
+ section = Asciidoctor::Section.new(Asciidoctor::Document.new)
section.level = 1
assert !Asciidoctor::Lexer.is_title_section?(section, section.document)
section.level = 0
- another_section = Asciidoctor::Section.new(Asciidoctor::Document.new([]))
- another_section.level = 0
- section.document.elements << section
+ another_section = Asciidoctor::Section.new(Asciidoctor::Document.new)
+ another_section.level = 0
+ section.document << section
assert !Asciidoctor::Lexer.is_title_section?(another_section, section.document)
end
diff --git a/test/lists_test.rb b/test/lists_test.rb
index fd88899e..5128ebfd 100644
--- a/test/lists_test.rb
+++ b/test/lists_test.rb
@@ -16,7 +16,7 @@ List
assert_xpath '//ul/li', output, 3
end
- test "dash elements with blank lines should merge lists" do
+ test "dash elements separated by blank lines should merge lists" do
input = <<-EOS
List
====
@@ -25,6 +25,7 @@ List
- Boo
+
- Blech
EOS
output = render_string input
@@ -148,7 +149,7 @@ List
assert_xpath '//ul/li', output, 3
end
- test "asterisk elements with blank lines should merge lists" do
+ test "asterisk elements separated by blank lines should merge lists" do
input = <<-EOS
List
====
@@ -157,6 +158,7 @@ List
* Boo
+
* Blech
EOS
output = render_string input
@@ -340,6 +342,7 @@ List
* Boo
+
- Blech
EOS
output = render_string input
@@ -496,6 +499,7 @@ List
. Boo
+
* Blech
EOS
output = render_string input
@@ -559,8 +563,8 @@ Item one, paragraph two
assert_xpath '//ul/li', output, 2
assert_xpath '//ul/li[1]/p', output, 1
assert_xpath '//ul/li[1]//p', output, 2
- assert_xpath '//ul/li[1]//p[text() = "Item one, paragraph one"]', output, 1
- assert_xpath '//ul/li[1]//p[text() = "Item one, paragraph two"]', output, 1
+ assert_xpath '//ul/li[1]/p[text() = "Item one, paragraph one"]', output, 1
+ assert_xpath '//ul/li[1]/*[@class = "paragraph"]/p[text() = "Item one, paragraph two"]', output, 1
end
test "adjacent list continuation line attaches following block" do
@@ -610,7 +614,7 @@ ____
# NOTE this differs from AsciiDoc behavior, but is more logical
test "consecutive list continuation lines are folded" do
- return pending "rework test to support more compliant behavior"
+ return pending "Rework test to support more compliant behavior"
input = <<-EOS
Lists
=====
@@ -652,7 +656,7 @@ List
assert_xpath '//ol/li', output, 3
end
- test "dot elements with blank lines should merge lists" do
+ test "dot elements separated by blank lines should merge lists" do
input = <<-EOS
List
====
@@ -661,6 +665,7 @@ List
. Boo
+
. Blech
EOS
output = render_string input
@@ -668,7 +673,7 @@ List
assert_xpath '//ol/li', output, 3
end
- test "dot elements with blank lines separated by line comment should not merge lists" do
+ test "dot elements separated by line comment offset by blank lines should not merge lists" do
input = <<-EOS
List
====
@@ -972,6 +977,35 @@ anotherterm:: def
assert_xpath '(//dl/dd)[1]//*[@class="openblock"]//p', output, 2
end
+ test "paragraph attached by a list continuation in a labeled list" do
+ input = <<-EOS
+term1:: def
++
+more detail
++
+term2:: def
+ EOS
+ output = render_string input
+ assert_xpath '(//dl/dd)[1]//p', output, 2
+ assert_xpath '(//dl/dd)[1]/p/following-sibling::*[@class="paragraph"]/p[text() = "more detail"]', output, 1
+ end
+
+ # FIXME!
+ test "paragraph attached by a list continuation to a multi-line element in a labeled list" do
+ input = <<-EOS
+term1::
+def
++
+more detail
++
+term2:: def
+ EOS
+ output = render_string input
+ pending "We're assuming the list continuation would be the first line after the term"
+ #assert_xpath '(//dl/dd)[1]//p', output, 2
+ #assert_xpath '(//dl/dd)[1]/p/following-sibling::*[@class="paragraph"]/p[text() = "more detail"]', output, 1
+ end
+
test "verse paragraph inside a labeled list" do
input = <<-EOS
term1:: def
diff --git a/test/paragraphs_test.rb b/test/paragraphs_test.rb
index 840751af..e0047abc 100644
--- a/test/paragraphs_test.rb
+++ b/test/paragraphs_test.rb
@@ -1,20 +1,22 @@
require 'test_helper'
context "Paragraphs" do
- test "rendered correctly" do
- assert_xpath "//p", render_string("Plain text for the win.\n\nYes, plainly."), 2
- end
+ context 'Normal' do
+ test "rendered correctly" do
+ assert_xpath "//p", render_string("Plain text for the win.\n\nYes, plainly."), 2
+ end
- test "with title" do
- rendered = render_string(".Titled\nParagraph.\n\nWinning")
-
- assert_xpath "//div[@class='title']", rendered
- assert_xpath "//p", rendered, 2
- end
+ test "with title" do
+ rendered = render_string(".Titled\nParagraph.\n\nWinning")
+
+ assert_xpath "//div[@class='title']", rendered
+ assert_xpath "//p", rendered, 2
+ 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
+ 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
+ end
end
context "code" do
diff --git a/test/preamble_test.rb b/test/preamble_test.rb
index 5ae997c8..45d43032 100644
--- a/test/preamble_test.rb
+++ b/test/preamble_test.rb
@@ -106,7 +106,7 @@ They couldn't believe their eyes when...
assert_equal 'book', d.doctype
output = d.render
assert_xpath '//h1', output, 3
- assert_xpath '//*[@id="preamble"]//p[text() = "Back then..."]', output, 1
+ assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{[8230].pack('U*')}"]}, output, 1
end
end
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 5c846bb9..f9fda29c 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -9,7 +9,7 @@ class ReaderTest < Test::Unit::TestCase
context "has_lines?" do
test "returns false for empty document" do
- assert ! Asciidoctor::Reader.new.has_lines?
+ assert !Asciidoctor::Reader.new.has_lines?
end
test "returns true with lines remaining" do
@@ -44,6 +44,114 @@ class ReaderTest < Test::Unit::TestCase
end
end
+ context "Grab lines" do
+ test "Grab until end" do
+ input = <<-EOS
+This is one paragraph.
+
+This is another paragraph.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ result = reader.grab_lines_until
+ assert_equal 3, result.size
+ assert_equal lines, result
+ assert !reader.has_lines?
+ assert reader.empty?
+ end
+
+ test "Grab until blank line" do
+ input = <<-EOS
+This is one paragraph.
+
+This is another paragraph.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ result = reader.grab_lines_until :break_on_blank_lines => true
+ assert_equal 1, result.size
+ assert_equal lines.first, result.first
+ assert_equal lines.last, reader.peek_line
+ end
+
+ test "Grab until blank line preserving last line" do
+ input = <<-EOS
+This is one paragraph.
+
+This is another paragraph.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ result = reader.grab_lines_until :break_on_blank_lines => true, :preserve_last_line => true
+ assert_equal 1, result.size
+ assert_equal lines.first, result.first
+ assert_equal "\n", reader.peek_line
+ end
+
+ test "Grab until condition" do
+ input = <<-EOS
+--
+This is one paragraph inside the block.
+
+This is another paragraph inside the block.
+--
+
+This is a paragraph outside the block.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ reader.get_line
+ result = reader.grab_lines_until {|line| line.chomp == '--' }
+ assert_equal 3, result.size
+ assert_equal lines[1, 3], result
+ assert_equal "\n", reader.peek_line
+ end
+
+ test "Grab until condition with last line" do
+ input = <<-EOS
+--
+This is one paragraph inside the block.
+
+This is another paragraph inside the block.
+--
+
+This is a paragraph outside the block.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ reader.get_line
+ result = reader.grab_lines_until(:grab_last_line => true) {|line| line.chomp == '--' }
+ assert_equal 4, result.size
+ assert_equal lines[1, 4], result
+ assert_equal "\n", reader.peek_line
+ end
+
+ test "Grab until condition with last line and preserving last line" do
+ input = <<-EOS
+--
+This is one paragraph inside the block.
+
+This is another paragraph inside the block.
+--
+
+This is a paragraph outside the block.
+ EOS
+
+ lines = input.lines.entries
+ reader = Asciidoctor::Reader.new(lines)
+ reader.get_line
+ result = reader.grab_lines_until(:grab_last_line => true, :preserve_last_line => true) {|line| line.chomp == '--' }
+ assert_equal 4, result.size
+ assert_equal lines[1, 4], result
+ assert_equal "--\n", reader.peek_line
+ end
+ end
+
context "Include files" do
test "block is called to handle an include macro" do
input = <<-EOS
@@ -53,22 +161,46 @@ include::include-file.asciidoc[]
last line
EOS
- attributes = {}
- reader = Asciidoctor::Reader.new(input.lines.entries, attributes) {|inc|
+ doc = Asciidoctor::Document.new
+ reader = Asciidoctor::Reader.new(input.lines.entries, doc) {|inc|
":file: #{inc}\n\nmiddle line".lines.entries
}
- expected = {'file' => 'include-file.asciidoc'}
- assert_equal expected, attributes
+ assert_equal 'include-file.asciidoc', doc.attributes['file']
end
end
- def test_grab_lines_until
- pending "Not tested yet"
+ # TODO these tests could be expanded
+ context 'Conditional blocks' do
+ test 'ifdef with defined attribute includes block' do
+ input = <<-EOS
+:holygrail:
+
+ifdef::holygrail[]
+There is a holy grail!
+endif::holygrail[]
+ EOS
+
+ reader = Asciidoctor::Reader.new(input.lines.entries, Asciidoctor::Document.new)
+ assert_match /There is a holy grail!/, reader.lines.join
+ end
+
+ test 'ifndef with undefined attribute includes block' do
+ input = <<-EOS
+ifndef::holygrail[]
+Our quest continues to find the holy grail!
+endif::holygrail[]
+ EOS
+
+ reader = Asciidoctor::Reader.new(input.lines.entries, Asciidoctor::Document.new)
+ assert_match /Our quest continues to find the holy grail!/, reader.lines.join
+ end
end
- def test_sanitize_attribute_name
- assert_equal 'foobar', @reader.sanitize_attribute_name("Foo Bar")
- assert_equal 'foo', @reader.sanitize_attribute_name("foo")
- assert_equal 'foo3-bar', @reader.sanitize_attribute_name("Foo 3^ # - Bar[")
+ context 'Text processing' do
+ test 'sanitize attribute name' do
+ assert_equal 'foobar', @reader.sanitize_attribute_name("Foo Bar")
+ assert_equal 'foo', @reader.sanitize_attribute_name("foo")
+ assert_equal 'foo3-bar', @reader.sanitize_attribute_name("Foo 3^ # - Bar[")
+ end
end
end
diff --git a/test/string_test.rb b/test/string_test.rb
new file mode 100644
index 00000000..055e82d3
--- /dev/null
+++ b/test/string_test.rb
@@ -0,0 +1,63 @@
+require 'test_helper'
+
+context 'String' do
+
+ test 'underscore should turn module into path and class name into words delimited by an underscore' do
+ assert_equal 'asciidoctor/abstract_block', Asciidoctor::AbstractBlock.to_s.underscore
+ end
+
+ test 'underscore should convert hypens to underscores' do
+ assert_equal 'one_on_one', 'one-on-one'.underscore
+ end
+
+ test 'underscore should convert camelcase word into words delimited by an underscore' do
+ assert_equal 'big_voodoo_daddy', 'BigVoodooDaddy'.underscore
+ end
+
+ test 'ltrim should trim sequence of char from left of string' do
+ assert_equal 'abc', '_abc'.ltrim('_')
+ assert_equal 'abc', '___abc'.ltrim('_')
+ assert_equal 'abc', 'abc'.ltrim('_')
+ end
+
+ test 'ltrim should not trim sequence of char from middle of string' do
+ assert_equal 'a_b_c', 'a_b_c'.ltrim('_')
+ assert_equal 'a___c', 'a___c'.ltrim('_')
+ assert_equal 'a___c', '_a___c'.ltrim('_')
+ end
+
+ test 'rtrim should trim sequence of char from right of string' do
+ assert_equal 'abc', 'abc_'.rtrim('_')
+ assert_equal 'abc', 'abc___'.rtrim('_')
+ assert_equal 'abc', 'abc'.rtrim('_')
+ end
+
+ test 'rtrim should not trim sequence of char from middle of string' do
+ assert_equal 'a_b_c', 'a_b_c'.rtrim('_')
+ assert_equal 'a___c', 'a___c'.rtrim('_')
+ assert_equal 'a___c', 'a___c_'.rtrim('_')
+ end
+
+ test 'trim should trim sequence of char from boundaries of string' do
+ assert_equal 'abc', '_abc_'.trim('_')
+ assert_equal 'abc', '___abc___'.trim('_')
+ assert_equal 'abc', '___abc_'.trim('_')
+ assert_equal 'abc', '_abc___'.trim('_')
+ end
+
+ test 'trim should not trim sequence of char from middle of string' do
+ assert_equal 'a_b_c', 'a_b_c'.trim('_')
+ assert_equal 'a___c', 'a___c'.trim('_')
+ assert_equal 'a___c', '_a___c_'.trim('_')
+ end
+
+ test 'nuke should remove first occurrence of matched pattern' do
+ assert_equal 'ab_c', 'a_b_c'.nuke(/_/)
+ end
+
+ test 'gnuke should remove all occurrences of matched pattern' do
+ assert_equal 'abc', 'a_b_c'.gnuke(/_/)
+ assert_equal '-foo-bar', '#-?foo #-?bar'.gnuke(/[^\w-]/)
+ end
+
+end
diff --git a/test/substitutions_test.rb b/test/substitutions_test.rb
index ad424d57..a8e4a200 100644
--- a/test/substitutions_test.rb
+++ b/test/substitutions_test.rb
@@ -9,7 +9,7 @@ context 'Substitutions' do
para = block_from_string("[blue]'http://asciidoc.org[AsciiDoc]' & [red]*Ruby*\n&#167; Making +++<u>documentation</u>+++ together +\nsince (C) {inception_year}.")
para.document.attributes['inception_year'] = '2012'
result = para.apply_normal_subs(para.buffer)
- assert_equal %{<em><span class="blue"><a href='http://asciidoc.org'>AsciiDoc</a></span></em> &amp; <strong><span class="red">Ruby</span></strong>\n&#167; Making <u>documentation</u> together<br>\nsince &#169; 2012.}, result
+ assert_equal %{<em><span class="blue"><a href="http://asciidoc.org">AsciiDoc</a></span></em> &amp; <strong><span class="red">Ruby</span></strong>\n&#167; Making <u>documentation</u> together<br>\nsince &#169; 2012.}, result
end
end
@@ -106,7 +106,8 @@ context 'Substitutions' do
test 'escaped single-quotes inside emphasized words are restored' do
para = block_from_string(%q{'Here\'s Johnny!'})
- assert_equal %q{<em>Here's Johnny!</em>}, para.sub_quotes(para.buffer.join)
+ # NOTE the \' is replaced with ' by the :replacements substitution, later in the substitution pipeline
+ assert_equal %q{<em>Here\'s Johnny!</em>}, para.sub_quotes(para.buffer.join)
end
test 'single-line constrained emphasized underline variation string' do
@@ -200,33 +201,33 @@ context 'Substitutions' do
context 'Macros' do
test 'a single-line link macro should be interpreted as a link' do
para = block_from_string('link:/home.html[]')
- assert_equal %q{<a href='/home.html'>/home.html</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %q{<a href="/home.html">/home.html</a>}, para.sub_macros(para.buffer.join)
end
test 'a single-line link macro with text should be interpreted as a link' do
para = block_from_string('link:/home.html[Home]')
- assert_equal %q{<a href='/home.html'>Home</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %q{<a href="/home.html">Home</a>}, para.sub_macros(para.buffer.join)
end
test 'a single-line raw url should be interpreted as a link' do
para = block_from_string('http://google.com')
- assert_equal %q{<a href='http://google.com'>http://google.com</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %q{<a href="http://google.com">http://google.com</a>}, para.sub_macros(para.buffer.join)
end
test 'a single-line raw url with text should be interpreted as a link' do
para = block_from_string('http://google.com[Google]')
- assert_equal %q{<a href='http://google.com'>Google</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %q{<a href="http://google.com">Google</a>}, para.sub_macros(para.buffer.join)
end
test 'a multi-line raw url with text should be interpreted as a link' do
para = block_from_string("http://google.com[Google\nHomepage]")
- assert_equal %{<a href='http://google.com'>Google\nHomepage</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %{<a href="http://google.com">Google\nHomepage</a>}, para.sub_macros(para.buffer.join)
end
test 'a multi-line raw url with attribute as text should be interpreted as a link with resolved attribute' do
para = block_from_string("http://google.com[{google_homepage}]")
para.document.attributes['google_homepage'] = 'Google Homepage'
- assert_equal %q{<a href='http://google.com'>Google Homepage</a>}, para.sub_macros(para.buffer.join)
+ assert_equal %q{<a href="http://google.com">Google Homepage</a>}, para.sub_macros(para.buffer.join)
end
test 'a single-line escaped raw url should not be interpreted as a link' do
@@ -236,22 +237,22 @@ context 'Substitutions' do
test 'a single-line image macro should be interpreted as an image' do
para = block_from_string('image:tiger.png[]')
- assert_equal %{<span class='image'>\n <img src='tiger.png' alt='tiger'>\n</span>}, para.sub_macros(para.buffer.join)
+ assert_equal %{<span class="image">\n <img src="tiger.png" alt="tiger">\n</span>}, para.sub_macros(para.buffer.join)
end
test 'a single-line image macro with text should be interpreted as an image with alt text' do
para = block_from_string('image:tiger.png[Tiger]')
- assert_equal %{<span class='image'>\n <img src='tiger.png' alt='Tiger'>\n</span>}, para.sub_macros(para.buffer.join)
+ assert_equal %{<span class="image">\n <img src="tiger.png" alt="Tiger">\n</span>}, para.sub_macros(para.buffer.join)
end
test 'a single-line image macro with text and dimensions should be interpreted as an image with alt text and dimensions' do
para = block_from_string('image:tiger.png[Tiger, 200, 100]')
- assert_equal %{<span class='image'>\n <img src='tiger.png' alt='Tiger' width='200' height='100'>\n</span>}, para.sub_macros(para.buffer.join)
+ assert_equal %{<span class="image">\n <img src="tiger.png" alt="Tiger" width="200" height="100">\n</span>}, para.sub_macros(para.buffer.join)
end
test 'a single-line image macro with text and link should be interpreted as a linked image with alt text' do
para = block_from_string('image:tiger.png[Tiger, link="http://en.wikipedia.org/wiki/Tiger"]')
- assert_equal %{<span class='image'>\n <a class='image' href='http://en.wikipedia.org/wiki/Tiger'><img src='tiger.png' alt='Tiger'></a>\n</span>}, para.sub_macros(para.buffer.join)
+ assert_equal %{<span class="image">\n <a class="image" href="http://en.wikipedia.org/wiki/Tiger"><img src="tiger.png" alt="Tiger"></a>\n</span>}, para.sub_macros(para.buffer.join)
end
end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 9ab2d497..bb72d32a 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -62,14 +62,21 @@ class Test::Unit::TestCase
end
end
- def assert_xpath(xpath, html, count = nil)
- doc = (html =~ /\s*<!DOCTYPE/) ? Nokogiri::HTML::Document.parse(html) : Nokogiri::HTML::DocumentFragment.parse(html)
+ def assert_xpath(xpath, content, count = nil)
+ match = content.match(/\s*<!DOCTYPE (.*)/)
+ if !match
+ doc = Nokogiri::HTML::DocumentFragment.parse(content)
+ elsif match[1].start_with? 'html'
+ doc = Nokogiri::HTML::Document.parse(content)
+ else
+ doc = Nokogiri::XML::Document.parse(content)
+ end
results = doc.xpath("#{xpath.sub('/', './')}")
if (count && results.length != count)
- flunk "XPath #{xpath} yielded #{results.length} elements rather than #{count} for:\n#{html}"
+ flunk "XPath #{xpath} yielded #{results.length} elements rather than #{count} for:\n#{content}"
elsif (count.nil? && results.empty?)
- flunk "XPath #{xpath} not found in:\n#{html}"
+ flunk "XPath #{xpath} not found in:\n#{content}"
else
assert true
end
@@ -82,7 +89,7 @@ class Test::Unit::TestCase
def block_from_string(src, opts = {})
opts[:header_footer] = false
doc = Asciidoctor::Document.new(src.lines.entries, opts)
- doc.elements.first
+ doc.blocks.first
end
def render_string(src, opts = {})
diff --git a/test/text_test.rb b/test/text_test.rb
index 24234092..f32fc21a 100644
--- a/test/text_test.rb
+++ b/test/text_test.rb
@@ -9,8 +9,20 @@ context "Text" do
assert_xpath "//p", example_document(:encoding).render(:header_footer => false), 1
end
+ # NOTE this test ensures we have the encoding line on block templates too
+ test "proper encoding to handle utf8 characters in arbitrary block" do
+ input = []
+ input << "[verse]\n"
+ input.concat(File.readlines(sample_doc_path(:encoding)))
+ doc = Asciidoctor::Document.new
+ reader = Asciidoctor::Reader.new input
+ block = Asciidoctor::Lexer.next_block(reader, doc)
+ assert_xpath '//pre', block.render.gnuke(/^\s*\n/), 1
+ end
+
test 'escaped text markup' do
- pending "Not done yet"
+ assert_match /All your &lt;em&gt;inline&lt;\/em&gt; markup belongs to &lt;strong&gt;us&lt;\/strong&gt;!/,
+ render_string('All your <em>inline</em> markup belongs to <strong>us</strong>!')
end
test "line breaks" do
@@ -32,11 +44,15 @@ context "Text" do
assert_xpath "//em", render_string("An 'emphatic' no")
end
+ test "emphasized text with single quote" do
+ assert_xpath "//em[text()=\"Johnny#{[8217].pack('U*')}s\"]", render_string("It's 'Johnny's' phone")
+ end
+
test "emphasized text with escaped single quote" do
assert_xpath "//em[text()=\"Johnny's\"]", render_string("It's 'Johnny\\'s' phone")
end
- test "escaped single quote is restore as single quote" do
+ test "escaped single quote is restored as single quote" do
assert_xpath "//p[contains(text(), \"Let's do it!\")]", render_string("Let\\'s do it!")
end