test/tables_test.rb in asciidoctor-1.5.7.1 vs test/tables_test.rb in asciidoctor-1.5.8

- old
+ new

@@ -5,11 +5,11 @@ end context 'Tables' do context 'PSV' do - test 'renders simple psv table' do + test 'converts simple psv table' do input = <<-EOS |======= |A |B |C |a |b |c |1 |2 |3 @@ -35,34 +35,48 @@ assert_xpath "(//tr)[#{rowi + 1}]/td[#{celli + 1}]/p[text()='#{cell}']", output, 1 } } end + test 'should add direction CSS class if float attribute is set on table' do + input = <<-EOS +[float=left] +|======= +|A |B |C +|a |b |c +|1 |2 |3 +|======= + EOS + + output = convert_string_to_embedded input + assert_css 'table.left', output, 1 + end + test 'should set stripes class if stripes option is set' do input = <<-EOS [stripes=odd] |======= |A |B |C |a |b |c |1 |2 |3 |======= EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table.stripes-odd', output, 1 end - test 'renders caption on simple psv table' do + test 'outputs a caption on simple psv table' do input = <<-EOS .Simple psv table |======= |A |B |C |a |b |c |1 |2 |3 |======= EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '/table/caption[@class="title"][text()="Table 1. Simple psv table"]', output, 1 assert_xpath '/table/caption/following-sibling::colgroup', output, 1 end test 'only increments table counter for tables that have a title' do @@ -79,41 +93,87 @@ .Second numbered table |======= |7 |8 |9 |======= EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table:root', output, 3 assert_xpath '(/table)[1]/caption', output, 1 assert_xpath '(/table)[1]/caption[text()="Table 1. First numbered table"]', output, 1 assert_xpath '(/table)[2]/caption', output, 0 assert_xpath '(/table)[3]/caption', output, 1 assert_xpath '(/table)[3]/caption[text()="Table 2. Second numbered table"]', output, 1 end - test 'renders explicit caption on simple psv table' do + test 'uses explicit caption in front of title in place of default caption and number' 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 + output = convert_string_to_embedded 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 'disables caption when caption attribute on table is empty' do + input = <<-EOS +[caption=] +.Simple psv table +|======= +|A |B |C +|a |b |c +|1 |2 |3 +|======= + EOS + output = convert_string_to_embedded input + assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1 + assert_xpath '/table/caption/following-sibling::colgroup', output, 1 + end + + test 'disables caption when caption attribute on table is empty string' do + input = <<-EOS +[caption=""] +.Simple psv table +|======= +|A |B |C +|a |b |c +|1 |2 |3 +|======= + EOS + output = convert_string_to_embedded input + assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1 + assert_xpath '/table/caption/following-sibling::colgroup', output, 1 + end + + test 'disables caption on table when table-caption document attribute is unset' do + input = <<-EOS +:!table-caption: + +.Simple psv table +|======= +|A |B |C +|a |b |c +|1 |2 |3 +|======= + EOS + output = convert_string_to_embedded input + assert_xpath '/table/caption[@class="title"][text()="Simple psv table"]', output, 1 + assert_xpath '/table/caption/following-sibling::colgroup', output, 1 + end + test 'ignores escaped separators' do input = <<-EOS |=== |A \\| here| a \\| there |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 1 assert_css 'table > tbody > tr > td', output, 2 assert_xpath '/table/tbody/tr/td[1]/p[text()="A | here"]', output, 1 @@ -127,11 +187,11 @@ |A |B\\| |A1 |B1\\| |A2 |B2\\| |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr:nth-child(1) > th', output, 2 assert_xpath '/table/thead/tr[1]/th[2][text()="B|"]', output, 1 @@ -148,11 +208,11 @@ |A1 | |B1 |B2 |C1 |C2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 3 assert_xpath '/table/tbody/tr[1]/td', output, 2 assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1 @@ -169,11 +229,11 @@ | z | end |=== EOS using_memory_logger do |logger| - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > tbody > tr', output, 2 assert_css 'table > tbody > tr > td', output, 8 assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1 assert_xpath '/table/tbody/tr[1]/td[2]/p[text()="here"]', output, 1 @@ -188,11 +248,11 @@ :show_title: Cool new show |=== |{show_title} |Coming soon... |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '//tbody/tr/td[1]/p[text()="Cool new show"]', output, 1 assert_xpath %(//tbody/tr/td[2]/p[text()='Coming soon#{decode_char 8230}#{decode_char 8203}']), output, 1 end test 'should only substitute specialchars for literal table cells' do @@ -202,11 +262,11 @@ *two* three <four> |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input result = xmlnodes_at_xpath('/table//pre', output, 1) assert_equal %(<pre>one\n*two*\nthree\n&lt;four&gt;</pre>), result.to_s end test 'should preserving leading spaces but not leading endlines or trailing spaces in literal table cells' do @@ -219,11 +279,11 @@ three | normal |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input result = xmlnodes_at_xpath('/table//pre', output, 1) assert_equal %(<pre> one\n two\nthree</pre>), result.to_s end test 'should preserving leading spaces but not leading endlines or trailing spaces in verse table cells' do @@ -236,11 +296,11 @@ three | normal |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input result = xmlnodes_at_xpath('/table//div[@class="verse"]', output, 1) assert_equal %(<div class="verse"> one\n two\nthree</div>), result.to_s end test 'table and column width not assigned when autowidth option is specified' do @@ -250,11 +310,11 @@ |A |B |C |a |b |c |1 |2 |3 |======= EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table.fit-content', output, 1 assert_css 'table[style*="width"]', output, 0 assert_css 'table colgroup col', output, 3 assert_css 'table colgroup col[style*="width"]', output, 0 @@ -317,11 +377,11 @@ |A |B |C |D |a |b |c |d |1 |2 |3 |4 |======= EOS - output = render_embedded_string input, :backend => 'docbook5' + output = convert_string_to_embedded input, :backend => 'docbook5' assert_css 'tgroup[cols="4"]', output, 1 assert_css 'tgroup colspec', output, 4 assert_css 'tgroup colspec[colwidth]', output, 4 assert_css 'tgroup colspec[colwidth="15*"]', output, 1 assert_css 'tgroup colspec[colwidth="28.3333*"]', output, 2 @@ -335,11 +395,11 @@ |A |B |C |a |b |c |1 |2 |3 |======= EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table[style*="width"]', output, 1 assert_css 'table colgroup col', output, 3 assert_css 'table colgroup col[style*="width"]', output, 0 end @@ -350,11 +410,11 @@ |first |second |third |fourth |1 |2 |3 |4 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 4 assert_css 'table > tbody > tr', output, 2 assert_css 'table > tbody > tr:nth-child(1) > td', output, 4 assert_css 'table > tbody > tr:nth-child(2) > td', output, 4 @@ -365,11 +425,11 @@ [cols="3*"] |=== |A |B |C |a |b |c |1 |2 |3 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > tbody > tr', output, 3 end test 'table with explicit column count can have multiple rows on a single line' do @@ -378,11 +438,11 @@ |=== |one |two |1 |2 |a |b |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 assert_css 'table > tbody > tr', output, 2 end @@ -392,11 +452,11 @@ |=== |one |two |1 |2 |a |b |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 assert_css 'table > tbody > tr', output, 2 end @@ -406,24 +466,41 @@ |=== |one |two |1 |2 |a |b |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 3 end + test 'cols may be separated by semi-colon instead of comma' do + input = <<-EOS +[cols="1s;3m"] +|=== +| strong +| mono +|=== + EOS + output = convert_string_to_embedded input + assert_css 'table', output, 1 + assert_css 'table > colgroup > col', output, 2 + assert_css 'col[style="width: 25%;"]', output, 1 + assert_css 'col[style="width: 75%;"]', output, 1 + assert_xpath '(//td)[1]//strong', output, 1 + assert_xpath '(//td)[2]//code', output, 1 + 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 + output = convert_string_to_embedded 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 @@ -434,11 +511,11 @@ |=== |one |two |1 |2 |a |b |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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 @@ -449,11 +526,11 @@ |=== |one |two |1 |2 |a |b |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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 @@ -467,11 +544,11 @@ |Item 2 |2 |Item 3 |3 |Total |6 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr > th', output, 2 @@ -494,11 +571,11 @@ |Item 2 |2 |Item 3 |3 |Total |6 |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_css 'table', output, 1 assert_css 'table[frame="topbot"]', output, 1 assert_css 'table > title', output, 1 assert_css 'table > tgroup', output, 1 assert_css 'table > tgroup[cols="2"]', output, 1 @@ -524,11 +601,11 @@ [frame=ends] |=== |A |B |C |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_css 'informaltable[frame="topbot"]', output, 1 end test 'table with landscape orientation in DocBook' do ['orientation=landscape', '%rotate'].each do |attrs| @@ -537,11 +614,11 @@ |=== |Column A | Column B | Column C |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_css 'informaltable', output, 1 assert_css 'informaltable[orient="land"]', output, 1 end end @@ -555,11 +632,11 @@ |Data A2 |Data B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr > th', output, 2 @@ -572,11 +649,11 @@ |=== |Column 1 |Column 2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 assert_css 'table > thead > tr > th', output, 2 @@ -591,11 +668,11 @@ |Data A1 |Data B1 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table[style*="width"]', output, 0 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 1 assert_css 'table > thead > tr', output, 1 @@ -613,11 +690,11 @@ |Data A2 |Data B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 0 assert_css 'table > tbody', output, 1 assert_css 'table > tbody > tr', output, 3 @@ -634,11 +711,11 @@ |A2 |B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 0 assert_css 'table > tbody', output, 1 assert_css 'table > tbody > tr', output, 2 @@ -659,11 +736,11 @@ just text |A2 |B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 0 assert_css 'table > tbody', output, 1 assert_css 'table > tbody > tr', output, 2 @@ -682,11 +759,11 @@ |Data A2 |Data B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 0 assert_css 'table > tbody', output, 1 assert_css 'table > tbody > tr', output, 3 @@ -703,11 +780,11 @@ |Data A2 |Data B2 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > thead', output, 0 assert_css 'table > tbody', output, 1 assert_css 'table > tbody > tr', output, 3 @@ -720,11 +797,11 @@ |Name |Occupation| Website |Octocat |Social coding| https://github.com |Name |Occupation| Website |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > thead > tr > th', output, 3 assert_css 'table > thead > tr > th > *', output, 0 assert_css 'table > tfoot > tr > th', output, 1 @@ -750,11 +827,11 @@ |Name |Occupation| Website |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > tbody > tr > th', output, 3 assert_css 'table > tbody > tr > td', output, 6 assert_css 'table > tbody > tr .header', output, 0 assert_css 'table > tbody > tr > td > p > strong', output, 3 @@ -782,11 +859,11 @@ I am getting in shape! |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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.647%"]', output, 1 @@ -811,11 +888,11 @@ |=== |column A |column B |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '/table/colgroup/col', output, 2 assert_xpath '(/table/colgroup/col)[1][@style="width: 10%;"]', output, 1 assert_xpath '(/table/colgroup/col)[2][@style="width: 90%;"]', output, 1 end @@ -827,11 +904,11 @@ ^|5 2.2+^.^|6 .3+<.>m|7 ^|8 d|9 2+>|10 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col[style*="width: 25%"]', output, 4 assert_css 'table > tbody > tr', output, 4 assert_css 'table > tbody > tr > td', output, 10 assert_css 'table > tbody > tr:nth-child(1) > td', output, 4 @@ -862,11 +939,11 @@ 2+^|AAA |CCC |AAA |BBB |CCC |AAA |BBB |CCC |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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 @@ -878,11 +955,11 @@ 3*|A |1 3*|2 |b |c |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 assert_css 'table > tbody > tr', output, 3 assert_css 'table > tbody > tr:nth-child(1) > td', output, 3 assert_css 'table > tbody > tr:nth-child(2) > td', output, 3 @@ -907,11 +984,11 @@ 2+|Two Columns |One Column |One Column |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_xpath '//colspec', output, 2 assert_xpath '(//colspec)[1][@colname="col_1"]', output, 1 assert_xpath '(//colspec)[2][@colname="col_2"]', output, 1 assert_xpath '//row', output, 2 assert_xpath '(//row)[1]/entry', output, 1 @@ -924,11 +1001,11 @@ 2+|Two Columns | One Column |One Column |One Column |One Column |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_xpath '//colspec', output, 3 assert_xpath '(//colspec)[1][@colname="col_1"]', output, 1 assert_xpath '(//colspec)[2][@colname="col_2"]', output, 1 assert_xpath '(//colspec)[3][@colname="col_3"]', output, 1 assert_xpath '//row', output, 2 @@ -946,11 +1023,11 @@ | Host processes | Core 0 | Core 1 | Core 4 | Core 5 | Guest processes | Core 2 | Core 3 | Core 6 | Core 7 |=== EOS - output = render_embedded_string input, :backend => 'docbook' + output = convert_string_to_embedded input, :backend => 'docbook' assert_xpath '//colspec', output, 5 (1..5).each do |n| assert_xpath %((//colspec)[#{n}][@colname="col_#{n}"]), output, 1 end assert_xpath '(//row)[1]/entry', output, 3 @@ -970,11 +1047,11 @@ more C |=== EOS using_memory_logger do |logger| - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table *', output, 0 assert_message logger, :ERROR, '<stdin>: line 5: dropping cell because it exceeds specified number of columns', Hash end end @@ -1010,11 +1087,11 @@ of a potentially great harvest of future knowledge and wisdom. I wouldn't have it any other way. |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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 @@ -1040,11 +1117,11 @@ third paragraph |=== EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_xpath %((//p[@class="tableblock"])[1][text()="first wrapped\nparagraph"]), result, 1 assert_xpath %((//p[@class="tableblock"])[2][text()="second paragraph"]), result, 1 assert_xpath %((//p[@class="tableblock"])[3][text()="third paragraph"]), result, 1 end @@ -1057,11 +1134,11 @@ content -- |=== EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_css 'table.tableblock', result, 1 assert_css 'table.tableblock td.tableblock', result, 1 assert_css 'table.tableblock td.tableblock .openblock', result, 1 assert_css 'table.tableblock td.tableblock .openblock .admonitionblock', result, 1 assert_css 'table.tableblock td.tableblock .openblock .paragraph', result, 1 @@ -1072,11 +1149,11 @@ |=== a|AsciiDoc table cell |=== EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_css 'table.tableblock td.tableblock > div.content', result, 1 assert_css 'table.tableblock td.tableblock > div.content > div.paragraph', result, 1 end test 'doctype can be set in AsciiDoc table cell' do @@ -1087,11 +1164,11 @@ content |=== EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_css 'table.tableblock', result, 1 assert_css 'table.tableblock .paragraph', result, 0 end test 'should reset doctype to default in AsciiDoc table cell' do @@ -1109,11 +1186,11 @@ {backend-html5-doctype-article} {backend-html5-doctype-book} |=== EOS - result = render_embedded_string input, :attributes => { 'attribute-missing' => 'skip' } + result = convert_string_to_embedded input, :attributes => { 'attribute-missing' => 'skip' } assert_includes result, 'doctype=article' refute_includes result, '{backend-html5-doctype-article}' assert_includes result, '{backend-html5-doctype-book}' end @@ -1133,11 +1210,11 @@ {backend-html5-doctype-book} {backend-html5-doctype-article} |=== EOS - result = render_embedded_string input, :attributes => { 'attribute-missing' => 'skip' } + result = convert_string_to_embedded input, :attributes => { 'attribute-missing' => 'skip' } assert_includes result, 'doctype=book' refute_includes result, '{backend-html5-doctype-book}' assert_includes result, '{backend-html5-doctype-article}' end @@ -1220,11 +1297,11 @@ |=== a|include::fixtures/include-file.asciidoc[] |=== EOS - output = render_embedded_string input, :safe => :safe, :base_dir => testdir + output = convert_string_to_embedded input, :safe => :safe, :base_dir => testdir assert_match(/included content/, output) end test 'cross reference link in an AsciiDoc table cell should resolve to reference in main document' do input = <<-EOS @@ -1237,11 +1314,11 @@ == More content EOS - result = render_string input + result = convert_string input assert_xpath '//a[@href="#_more"]', result, 1 assert_xpath '//a[@href="#_more"][text()="More"]', result, 1 end test 'should discover anchor at start of cell and register it as a reference' do @@ -1274,11 +1351,11 @@ |=== a|AsciiDoc footnote:[A lightweight markup language.] |=== EOS - result = render_string input + result = convert_string input assert_css '#_footnotedef_1', result, 1 end test 'callout numbers should be globally unique, including AsciiDoc table cells' do input = <<-EOS @@ -1313,11 +1390,11 @@ key: value <1> ---- <1> Third callout EOS - result = render_string input, :backend => 'docbook' + result = convert_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 @@ -1336,11 +1413,11 @@ The word 'italic' is emphasized. |=== EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_xpath '//em[text()="italic"]', result, 1 end test 'compat mode in AsciiDoc table cell inherits from parent document' do input = <<-EOS @@ -1356,11 +1433,11 @@ |=== The word 'askew' is emphasized. EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_xpath '//em[text()="italic"]', result, 1 assert_xpath '//em[text()="oblique"]', result, 1 assert_xpath '//em[text()="slanted"]', result, 1 assert_xpath '//em[text()="askew"]', result, 1 end @@ -1381,11 +1458,11 @@ |=== The word 'askew' is emphasized. EOS - result = render_embedded_string input + result = convert_string_to_embedded input assert_xpath '//em[text()="italic"]', result, 1 assert_xpath '//em[text()="oblique"]', result, 1 assert_xpath '//em[text()="slanted"]', result, 0 assert_xpath '//em[text()="askew"]', result, 1 end @@ -1400,11 +1477,11 @@ !=== !Nested table cell 1 !Nested table cell 2 !=== |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 2 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 @@ -1420,11 +1497,11 @@ !nested cell !=== |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 2 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, 1 end @@ -1439,11 +1516,11 @@ |=== a|AsciiDoc content |=== EOS - output = render_string input + output = convert_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 @@ -1461,11 +1538,11 @@ content |=== EOS - output = render_string input + output = convert_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 @@ -1487,11 +1564,11 @@ content |=== EOS - output = render_string input + output = convert_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 @@ -1504,11 +1581,11 @@ |=== |AsciiDoc content |=== EOS - output = render_string input + output = convert_string input assert_css 'table', output, 1 assert_css 'table > tbody > tr > td', output, 1 assert_css 'table > tbody > tr > td #preamble', output, 0 assert_css 'table > tbody > tr > td .paragraph', output, 1 end @@ -1524,11 +1601,11 @@ |{set:cellbgcolor!} plain |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '(/table/thead/tr/th)[1][@style="background-color: green;"]', output, 1 assert_xpath '(/table/thead/tr/th)[2][@style="background-color: green;"]', output, 0 assert_xpath '(/table/tbody/tr/td)[1][@style="background-color: red;"]', output, 1 assert_xpath '(/table/tbody/tr/td)[2][@style="background-color: green;"]', output, 0 end @@ -1545,11 +1622,11 @@ eof EOS using_memory_logger do |logger| - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '/table', output, 1 assert_message logger, :WARN, '<stdin>: line 3: unterminated table block', Hash end end @@ -1569,20 +1646,111 @@ eof EOS using_memory_logger do |logger| - output = render_embedded_string input + output = convert_string_to_embedded input assert_xpath '//ul//table', output, 1 assert_message logger, :WARN, '<stdin>: line 9: unterminated example block', Hash end end + + test 'custom separator for an AsciiDoc table cell' do + input = <<-EOS +[cols=2,separator=!] +|=== +!Pipe output to vim +a! +---- +asciidoctor -o - -s test.adoc | view - +---- +|=== + EOS + output = convert_string_to_embedded input + assert_css 'table', output, 1 + assert_css 'table > colgroup > col', output, 2 + assert_css 'table > tbody > tr', output, 1 + assert_css 'table > tbody > tr:nth-child(1) > td', output, 2 + assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1) p', output, 1 + assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2) .listingblock', output, 1 + end + + test 'table with breakable option docbook 4.5' do + input = <<-EOS +.Table with breakable +[%breakable] +|=== +|Item |Quantity +|Item 1 |1 +|=== + EOS + output = convert_string_to_embedded input, :backend => 'docbook45' + assert_includes output, '<?dbfo keep-together="auto"?>' + end + + test 'table with breakable option docbook 5' do + input = <<-EOS +.Table with breakable +[%breakable] +|=== +|Item |Quantity +|Item 1 |1 +|=== + EOS + output = convert_string_to_embedded input, :backend => 'docbook5' + assert_includes output, '<?dbfo keep-together="auto"?>' + end + + test 'table with unbreakable option docbook 5' do + input = <<-EOS +.Table with unbreakable +[%unbreakable] +|=== +|Item |Quantity +|Item 1 |1 +|=== + EOS + output = convert_string_to_embedded input, :backend => 'docbook5' + assert_includes output, '<?dbfo keep-together="always"?>' + end + + test 'table with unbreakable option docbook 4.5' do + input = <<-EOS +.Table with unbreakable +[%unbreakable] +|=== +|Item |Quantity +|Item 1 |1 +|=== + EOS + output = convert_string_to_embedded input, :backend => 'docbook45' + assert_includes output, '<?dbfo keep-together="always"?>' + end + + test 'no implicit header row if cell in first line is quoted and spans multiple lines' do + input = <<-EOS +[cols=2*l] +,=== +"A1 + +A1 continued",B1 +A2,B2 +,=== + EOS + output = convert_string_to_embedded input + assert_css 'table', output, 1 + assert_css 'table > colgroup > col', output, 2 + assert_css 'table > thead', output, 0 + assert_css 'table > tbody', output, 1 + assert_css 'table > tbody > tr', output, 2 + assert_xpath %((//td)[1]//pre[text()="A1\n\nA1 continued"]), output, 1 + end end context 'DSV' do - test 'renders simple dsv table' do + test 'converts simple dsv table' do input = <<-EOS [width="75%",format="dsv"] |=== root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin @@ -1609,11 +1777,11 @@ :=== a:b:c 1:2:3 :=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 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 @@ -1624,11 +1792,11 @@ :=== single cell :=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table td', output, 1 end test 'should treat trailing colon as an empty cell' do input = <<-EOS @@ -1636,11 +1804,11 @@ A1: B1:B2 C1:C2 :=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 3 assert_xpath '/table/tbody/tr[1]/td', output, 2 assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1 @@ -1657,20 +1825,36 @@ A1, B1,B2 C1,C2 ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 3 assert_xpath '/table/tbody/tr[1]/td', output, 2 assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A1"]', output, 1 assert_xpath '/table/tbody/tr[1]/td[2]/p', output, 0 assert_xpath '/table/tbody/tr[2]/td[1]/p[text()="B1"]', output, 1 end + test 'should log error but not crash if cell data has unclosed quote' do + input = <<-EOS +,=== +a,b +c," +,=== + EOS + using_memory_logger do |logger| + output = convert_string_to_embedded input + assert_css 'table', output, 1 + assert_css 'table td', output, 4 + assert_xpath '(/table/td)[4]/p', output, 0 + assert_message logger, :ERROR, '<stdin>: line 3: unclosed quote in CSV data; setting cell to empty', Hash + end + end + test 'should preserve newlines in quoted CSV values' do input = <<-EOS [cols="1,1,1l"] ,=== "A @@ -1684,11 +1868,11 @@ re me" ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 assert_css 'table > tbody > tr', output, 1 assert_xpath '/table/tbody/tr[1]/td', output, 3 assert_xpath %(/table/tbody/tr[1]/td[1]/p[text()="A\nB\nC"]), output, 1 @@ -1711,11 +1895,11 @@ air, moon roof, loaded",4799.00 2000,Toyota,Tundra,"""This one's gonna to blow you're socks off,"" per the sticker",10000.00 2000,Toyota,Tundra,"Check it, ""this one's gonna to blow you're socks off"", per the sticker",10000.00 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded 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, 6 assert_xpath '((//tbody/tr)[1]/td)[4]/p[text()="ac, abs, moon"]', output, 1 @@ -1734,11 +1918,11 @@ "," B " ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 2 assert_css 'table > tbody > tr', output, 1 assert_xpath '/table/tbody/tr[1]/td', output, 2 assert_xpath '/table/tbody/tr[1]/td[1]/p[text()="A"]', output, 1 @@ -1750,11 +1934,11 @@ ,=== a,b,c 1,2,3 ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 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 @@ -1766,11 +1950,11 @@ ,=== a\tb\tc 1\t2\t3 ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 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 @@ -1782,11 +1966,11 @@ |=== a;b;c 1;2;3 |=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 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 @@ -1798,116 +1982,55 @@ ,=== a\tb\tc 1\t2\t3 ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table', output, 1 assert_css 'table > colgroup > col', output, 3 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 for an AsciiDoc table cell' do - input = <<-EOS -[cols=2,separator=!] -|=== -!Pipe output to vim -a! ----- -asciidoctor -o - -s test.adoc | view - ----- -|=== - EOS - output = render_embedded_string input - assert_css 'table', output, 1 - assert_css 'table > colgroup > col', output, 2 - assert_css 'table > tbody > tr', output, 1 - assert_css 'table > tbody > tr:nth-child(1) > td', output, 2 - assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(1) p', output, 1 - assert_css 'table > tbody > tr:nth-child(1) > td:nth-child(2) .listingblock', output, 1 - end - test 'single cell in CSV table should only produce single row' do input = <<-EOS ,=== single cell ,=== EOS - output = render_embedded_string input + output = convert_string_to_embedded input assert_css 'table td', output, 1 end - test 'table with breakable db45' do + test 'cell formatted with AsciiDoc style' do input = <<-EOS -.Table with breakable -[options="breakable"] -|=== -|Item |Quantity -|Item 1 |1 -|=== - EOS - output = render_embedded_string input, :backend => 'docbook45' - assert_includes output, '<?dbfo keep-together="auto"?>' - end +[cols="1,1,1a",separator=;] +,=== +element;description;example - test 'table with breakable db5' do - input = <<-EOS -.Table with breakable -[options="breakable"] -|=== -|Item |Quantity -|Item 1 |1 -|=== +thematic break,a visible break; also known as a horizontal rule;--- +,=== EOS - output = render_embedded_string input, :backend => 'docbook5' - assert_includes output, '<?dbfo keep-together="auto"?>' - end - test 'table with unbreakable db5' do - input = <<-EOS -.Table with unbreakable -[options="unbreakable"] -|=== -|Item |Quantity -|Item 1 |1 -|=== - EOS - output = render_embedded_string input, :backend => 'docbook5' - assert_includes output, '<?dbfo keep-together="always"?>' + output = convert_string_to_embedded input + assert_css 'table tbody hr', output, 1 end - test 'table with unbreakable db45' do + test 'should strip whitespace around contents of AsciiDoc cell' do input = <<-EOS -.Table with unbreakable -[options="unbreakable"] -|=== -|Item |Quantity -|Item 1 |1 -|=== - EOS - output = render_embedded_string input, :backend => 'docbook45' - assert_includes output, '<?dbfo keep-together="always"?>' - end - - test 'no implicit header row if cell in first line is quoted and spans multiple lines' do - input = <<-EOS -[cols=2*l] +[cols="1,1,1a",separator=;] ,=== -"A1 +element;description;example -A1 continued",B1 -A2,B2 +paragraph;contiguous lines of words and phrases;" + one sentence, one line + " ,=== EOS - output = render_embedded_string input - assert_css 'table', output, 1 - assert_css 'table > colgroup > col', output, 2 - assert_css 'table > thead', output, 0 - assert_css 'table > tbody', output, 1 - assert_css 'table > tbody > tr', output, 2 - assert_xpath %((//td)[1]//pre[text()="A1\n\nA1 continued"]), output, 1 + + output = convert_string_to_embedded input + assert_xpath '/table/tbody//*[@class="paragraph"]/p[text()="one sentence, one line"]', output, 1 end end end