diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2012-12-13 04:23:36 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2012-12-13 04:29:07 -0700 |
| commit | b4e0f2a9014d9667e6104a5c44bab1744a77f252 (patch) | |
| tree | c84027bf5c6f77469ad4fb9a35c66d8749ecf777 /test | |
| parent | 01a771e6280447dc2609de85a03ee346a77a64dd (diff) | |
make header/footer optional, set intrinsic attributes
- make header/footer optional using option :header_footer
- set intrinsic attributes such as date/time, doctype and asciidoctor version
- expose doctitle and title accessors in Document (preferred over header)
- fill in the template for Document more completely to be consistent w/ AsciiDoc
Diffstat (limited to 'test')
| -rw-r--r-- | test/document_test.rb | 20 | ||||
| -rw-r--r-- | test/test_helper.rb | 11 | ||||
| -rw-r--r-- | test/text_test.rb | 3 |
3 files changed, 26 insertions, 8 deletions
diff --git a/test/document_test.rb b/test/document_test.rb index 1548ee8a..cea43e83 100644 --- a/test/document_test.rb +++ b/test/document_test.rb @@ -7,7 +7,7 @@ class DocumentTest < Test::Unit::TestCase end def test_title - assert_equal "AsciiDoc Home Page", @doc.title + assert_equal "AsciiDoc Home Page", @doc.doctitle assert_equal 14, @doc.elements.size assert_equal :preamble, @doc.elements[0].context assert_true @doc.elements[1].is_a? ::Asciidoctor::Section @@ -15,6 +15,22 @@ class DocumentTest < Test::Unit::TestCase def test_with_no_title d = Asciidoctor::Document.new(["Snorf"]) - assert_nil d.title + assert_nil d.doctitle + end + + def test_with_header_footer + 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 + + def test_with_no_header_footer + 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 diff --git a/test/test_helper.rb b/test/test_helper.rb index c69b0b12..0e2f7b9d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -50,7 +50,8 @@ class Test::Unit::TestCase end def assert_xpath(xpath, html, count = nil) - results = Nokogiri::HTML::DocumentFragment.parse(html).xpath("#{xpath.sub('/', './')}") + doc = (html =~ /\s*<!DOCTYPE/) ? Nokogiri::HTML::Document.parse(html) : Nokogiri::HTML::DocumentFragment.parse(html) + results = doc.xpath("#{xpath.sub('/', './')}") if (count && results.length != count) flunk "XPath #{xpath} yielded #{results.length} elements rather than #{count} for:\n#{html}" @@ -61,12 +62,12 @@ class Test::Unit::TestCase end end - def document_from_string(src) - Asciidoctor::Document.new(src.split("\n")) + def document_from_string(src, opts = {}) + Asciidoctor::Document.new(src.split("\n"), opts) end - def render_string(src) - document_from_string(src).render + def render_string(src, opts = {}) + document_from_string(src, opts).render end end diff --git a/test/text_test.rb b/test/text_test.rb index 4616db9e..f892398a 100644 --- a/test/text_test.rb +++ b/test/text_test.rb @@ -16,7 +16,8 @@ context "Text" do end test "separator" do - assert_xpath "//hr", render_string("This is separated.\n\n'''\n\n...from this!"), 1 + # for some reason, the html enclosure breaks the xpath //*[@id='content']//hr + assert_xpath "//*[@id='content']//hr", render_string("This is separated.\n\n'''\n\n...from this!"), 1 end test "emphasized text" do |
