test/tables_test.rb in asciidoctor-1.5.3 vs test/tables_test.rb in asciidoctor-1.5.4

- old
+ new

@@ -14,14 +14,18 @@ |a |b |c |1 |2 |3 |======= EOS cells = [%w(A B C), %w(a b c), %w(1 2 3)] - output = render_embedded_string input + doc = document_from_string input, :header_footer => false + table = doc.blocks[0] + assert 100, table.columns.map {|col| col.attributes['colpcwidth'] }.reduce(:+) + output = doc.convert assert_css 'table', output, 1 assert_css 'table.tableblock.frame-all.grid-all.spread', output, 1 - assert_css 'table > colgroup > col[style*="width: 33%"]', output, 3 + assert_css 'table > colgroup > col[style*="width: 33.3333%"]', output, 2 + assert_css 'table > colgroup > col:last-of-type[style*="width: 33.3334%"]', output, 1 assert_css 'table tr', output, 3 assert_css 'table > tbody > tr', output, 3 assert_css 'table td', output, 9 assert_css 'table > tbody > tr > td.tableblock.halign-left.valign-top > p.tableblock', output, 9 cells.each_with_index {|row, rowi| @@ -255,10 +259,39 @@ assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 3 end + test 'cols attribute may include spaces' do + input = <<-EOS +[cols=" 1, 1 "] +|=== +|one |two |1 |2 |a |b +|=== + EOS + output = render_embedded_string input + assert_css 'table', output, 1 + assert_css 'table > colgroup > col', output, 2 + assert_css 'col[style="width: 50%;"]', output, 2 + assert_css 'table > tbody > tr', output, 3 + end + + test 'blank cols attribute should be ignored' do + input = <<-EOS +[cols=" "] +|=== +|one |two +|1 |2 |a |b +|=== + EOS + output = render_embedded_string input + assert_css 'table', output, 1 + assert_css 'table > colgroup > col', output, 2 + assert_css 'col[style="width: 50%;"]', output, 2 + assert_css 'table > tbody > tr', output, 3 + end + test 'empty cols attribute should be ignored' do input = <<-EOS [cols=""] |=== |one |two @@ -275,14 +308,14 @@ test 'table with header and footer' do input = <<-EOS [frame="topbot",options="header,footer"] |=== |Item |Quantity -|Item 1 |1 -|Item 2 |2 -|Item 3 |3 -|Total |6 +|Item 1 |1 +|Item 2 |2 +|Item 3 |3 +|Total |6 |=== EOS output = render_embedded_string input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 @@ -300,14 +333,14 @@ input = <<-EOS .Table with header, body and footer [frame="topbot",options="header,footer"] |=== |Item |Quantity -|Item 1 |1 -|Item 2 |2 -|Item 3 |3 -|Total |6 +|Item 1 |1 +|Item 2 |2 +|Item 3 |3 +|Total |6 |=== EOS output = render_embedded_string input, :backend => 'docbook' assert_css 'table', output, 1 assert_css 'table[frame="topbot"]', output, 1 @@ -487,14 +520,14 @@ output = render_embedded_string input assert_css 'table', output, 1 assert_css 'table[style*="width: 80%"]', output, 1 assert_xpath '/table/caption[@class="title"][text()="Table 1. Horizontal and vertical source data"]', output, 1 assert_css 'table > colgroup > col', output, 4 - assert_css 'table > colgroup > col:nth-child(1)[@style*="width: 17%"]', output, 1 - assert_css 'table > colgroup > col:nth-child(2)[@style*="width: 11%"]', output, 1 - assert_css 'table > colgroup > col:nth-child(3)[@style*="width: 11%"]', output, 1 - assert_css 'table > colgroup > col:nth-child(4)[@style*="width: 58%"]', output, 1 + assert_css 'table > colgroup > col:nth-child(1)[@style*="width: 17.647%"]', output, 1 + assert_css 'table > colgroup > col:nth-child(2)[@style*="width: 11.7647%"]', output, 1 + assert_css 'table > colgroup > col:nth-child(3)[@style*="width: 11.7647%"]', output, 1 + assert_css 'table > colgroup > col:nth-child(4)[@style*="width: 58.8236%"]', output, 1 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr > th', output, 4 assert_css 'table > tbody > tr', output, 3 assert_css 'table > tbody > tr:nth-child(1) > td', output, 4 @@ -536,11 +569,11 @@ assert_css 'table > tbody > tr > td', output, 10 assert_css 'table > tbody > tr:nth-child(1) > td', output, 4 assert_css 'table > tbody > tr:nth-child(2) > td', output, 3 assert_css 'table > tbody > tr:nth-child(3) > td', output, 1 assert_css 'table > tbody > tr:nth-child(4) > td', output, 2 - + assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1).halign-left.valign-top p em', output, 1 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2).halign-right.valign-top p strong', output, 1 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p', output, 1 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p *', output, 0 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(4).halign-right.valign-top p strong', output, 1 @@ -562,11 +595,11 @@ 2+^|AAA |CCC |AAA |BBB |CCC |AAA |BBB |CCC |=== EOS - output = render_embedded_string input + output = render_embedded_string input assert_css 'table > tbody > tr:nth-child(1) > td', output, 2 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1)[colspan="2"]', output, 1 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2):not([colspan])', output, 1 assert_css 'table > tbody > tr:nth-child(2) > td:not([colspan])', output, 3 assert_css 'table > tbody > tr:nth-child(3) > td:not([colspan])', output, 3 @@ -682,14 +715,14 @@ that I haven't understood enough... that I can't know enough... that I am always hungrily operating on the margins of a potentially great harvest of future knowledge and wisdom. -I wouldn't have it any other way. +I wouldn't have it any other way. |=== EOS - output = render_embedded_string input + output = render_embedded_string input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr > th', output, 3 @@ -781,11 +814,11 @@ EOS doc = document_from_string input table = doc.blocks.first assert !table.nil? tbody = table.rows.body - assert_equal 2, tbody.size + assert_equal 2, tbody.size body_cell_1_3 = tbody[0][2] assert !body_cell_1_3.inner_document.nil? assert body_cell_1_3.inner_document.nested? assert_equal doc, body_cell_1_3.inner_document.parent_document assert_equal doc.converter, body_cell_1_3.inner_document.converter @@ -794,22 +827,22 @@ assert_css 'table > tbody > tr', output, 2 assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(3) div.admonitionblock', output, 1 assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(3) div.dlist', output, 1 end - test 'preprocessor directive on first line of AsciiDoc cell should be processed' do + test 'preprocessor directive on first line of an AsciiDoc table cell should be processed' do input = <<-EOS |=== a|include::fixtures/include-file.asciidoc[] |=== EOS output = render_embedded_string input, :safe => :safe, :base_dir => File.dirname(__FILE__) assert_match(/included content/, output) end - test 'cross reference link in AsciiDoc-style table cell should resolve to reference in main document' do + test 'cross reference link in an AsciiDoc table cell should resolve to reference in main document' do input = <<-EOS == Some |=== a|See <<_more>> @@ -823,21 +856,69 @@ result = render_string input assert_xpath '//a[@href="#_more"]', result, 1 assert_xpath '//a[@href="#_more"][text()="More"]', result, 1 end - test 'footnotes should not be shared between AsciiDoc-style table cell and main document' do + test 'footnotes should not be shared between an AsciiDoc table cell and the main document' do input = <<-EOS |=== a|AsciiDoc footnote:[A lightweight markup language.] |=== EOS result = render_string input assert_css '#_footnote_1', result, 1 end + test 'callout numbers should be globally unique, including AsciiDoc table cells' do + input = <<-EOS += Document Title + +== Section 1 + +|==== +a| +[source, yaml] +---- +key: value <1> +---- +<1> First callout +|==== + +== Section 2 + +|==== +a| +[source, yaml] +---- +key: value <1> +---- +<1> Second callout +|==== + +== Section 3 + +[source, yaml] +---- +key: value <1> +---- +<1> Third callout + EOS + + result = render_string input, :backend => 'docbook' + conums = xmlnodes_at_xpath '//co', result + assert_equal 3, conums.size + ['CO1-1', 'CO2-1', 'CO3-1'].each_with_index do |conum, idx| + assert_equal conum, conums[idx].attribute('xml:id').value + end + callouts = xmlnodes_at_xpath '//callout', result + assert_equal 3, callouts.size + ['CO1-1', 'CO2-1', 'CO3-1'].each_with_index do |callout, idx| + assert_equal callout, callouts[idx].attribute('arearefs').value + end + end + test 'nested table' do input = <<-EOS [cols="1,2a"] |=== |Normal cell @@ -854,14 +935,81 @@ assert_css 'table table', output, 1 assert_css 'table > tbody > tr > td:nth-child(2) table', output, 1 assert_css 'table > tbody > tr > td:nth-child(2) table > tbody > tr > td', output, 2 end - test 'nested document in AsciiDoc cell should not see doctitle of parent' do + test 'toc from parent document should not be included in an AsciiDoc table cell' do input = <<-EOS = Document Title +:toc: +== Section A + +|=== +a|AsciiDoc content +|=== + EOS + + output = render_string input + assert_css '.toc', output, 1 + assert_css 'table .toc', output, 0 + end + + test 'should be able to enable toc in an AsciiDoc table cell' do + input = <<-EOS += Document Title + +== Section A + +|=== +a| += Subdocument Title +:toc: + +== Subdocument Section A + +content +|=== + EOS + + output = render_string input + assert_css '.toc', output, 1 + assert_css 'table .toc', output, 1 + end + + test 'should be able to enable toc in both outer document and in an AsciiDoc table cell' do + input = <<-EOS += Document Title +:toc: + +== Section A + +|=== +a| += Subdocument Title +:toc: macro + +[#table-cell-toc] +toc::[] + +== Subdocument Section A + +content +|=== + EOS + + output = render_string input + assert_css '.toc', output, 2 + assert_css '#toc', output, 1 + assert_css 'table .toc', output, 1 + assert_css 'table #table-cell-toc', output, 1 + end + + test 'document in an AsciiDoc table cell should not see doctitle of parent' do + input = <<-EOS += Document Title + [cols="1a"] |=== |AsciiDoc content |=== EOS @@ -906,13 +1054,17 @@ gdm:x:42:42::/var/lib/gdm:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin |=== EOS - output = render_embedded_string input + doc = document_from_string input, :header_footer => false + table = doc.blocks[0] + assert 100, table.columns.map {|col| col.attributes['colpcwidth'] }.reduce(:+) + output = doc.convert assert_css 'table', output, 1 - assert_css 'table > colgroup > col[style*="width: 14%"]', output, 7 + assert_css 'table > colgroup > col[style*="width: 14.2857"]', output, 6 + assert_css 'table > colgroup > col:last-of-type[style*="width: 14.2858%"]', output, 1 assert_css 'table > tbody > tr', output, 6 assert_xpath '//tr[4]/td[5]/p/text()', output, 0 assert_xpath '//tr[3]/td[5]/p[text()="MySQL:Server"]', output, 1 end @@ -991,11 +1143,11 @@ 1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00 |=== EOS - output = render_embedded_string input + output = render_embedded_string input assert_css 'table', output, 1 assert_css 'table > colgroup > col[style*="width: 20%"]', output, 5 assert_css 'table > thead > tr', output, 1 assert_css 'table > tbody > tr', output, 4 assert_xpath '((//tbody/tr)[1]/td)[4]/p[text()="ac, abs, moon"]', output, 1 @@ -1032,11 +1184,11 @@ assert_css 'table > tbody > tr', output, 2 assert_css 'table > tbody > tr:nth-child(1) > td', output, 3 assert_css 'table > tbody > tr:nth-child(2) > td', output, 3 end - test 'custom separator on AsciiDoc table cell' do + test 'custom separator for an AsciiDoc table cell' do input = <<-EOS [cols=2,separator=!] |=== !Pipe output to vim a! @@ -1069,11 +1221,11 @@ input = <<-EOS .Table with breakable [options="breakable"] |=== |Item |Quantity -|Item 1 |1 +|Item 1 |1 |=== EOS output = render_embedded_string input, :backend => 'docbook45' assert output.include?('<?dbfo keep-together="auto"?>') end @@ -1082,11 +1234,11 @@ input = <<-EOS .Table with breakable [options="breakable"] |=== |Item |Quantity -|Item 1 |1 +|Item 1 |1 |=== EOS output = render_embedded_string input, :backend => 'docbook5' assert output.include?('<?dbfo keep-together="auto"?>') end @@ -1095,11 +1247,11 @@ input = <<-EOS .Table with unbreakable [options="unbreakable"] |=== |Item |Quantity -|Item 1 |1 +|Item 1 |1 |=== EOS output = render_embedded_string input, :backend => 'docbook5' assert output.include?('<?dbfo keep-together="always"?>') end @@ -1108,10 +1260,10 @@ input = <<-EOS .Table with unbreakable [options="unbreakable"] |=== |Item |Quantity -|Item 1 |1 +|Item 1 |1 |=== EOS output = render_embedded_string input, :backend => 'docbook45' assert output.include?('<?dbfo keep-together="always"?>') end