test/tables_test.rb in asciidoctor-0.1.2 vs test/tables_test.rb in asciidoctor-0.1.3

- old
+ new

@@ -19,12 +19,12 @@ 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| - assert_css "table tr:nth-child(#{rowi + 1}) > td", output, row.size - assert_css "table tr:nth-child(#{rowi + 1}) > td > p", output, row.size + assert_css "table > tbody > tr:nth-child(#{rowi + 1}) > td", output, row.size + assert_css "table > tbody > tr:nth-child(#{rowi + 1}) > td > p", output, row.size row.each_with_index {|cell, celli| assert_xpath "(//tr)[#{rowi + 1}]/td[#{celli + 1}]/p[text()='#{cell}']", output, 1 } } end @@ -310,25 +310,25 @@ 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 tr:nth-child(1) > td:nth-child(1).halign-left.valign-top p em', output, 1 - assert_css 'table tr:nth-child(1) > td:nth-child(2).halign-right.valign-top p strong', output, 1 - assert_css 'table tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p', output, 1 - assert_css 'table tr:nth-child(1) > td:nth-child(3).halign-center.valign-top p *', output, 0 - assert_css 'table tr:nth-child(1) > td:nth-child(4).halign-right.valign-top p strong', output, 1 + 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 - assert_css 'table tr:nth-child(2) > td:nth-child(1).halign-center.valign-top p em', output, 1 - assert_css 'table tr:nth-child(2) > td:nth-child(2).halign-center.valign-middle[colspan="2"][rowspan="2"] p code', output, 1 - assert_css 'table tr:nth-child(2) > td:nth-child(3).halign-left.valign-bottom[rowspan="3"] p code', output, 1 + assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(1).halign-center.valign-top p em', output, 1 + assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(2).halign-center.valign-middle[colspan="2"][rowspan="2"] p code', output, 1 + assert_css 'table > tbody > tr:nth-child(2) > td:nth-child(3).halign-left.valign-bottom[rowspan="3"] p code', output, 1 - assert_css 'table tr:nth-child(3) > td:nth-child(1).halign-center.valign-top p em', output, 1 + assert_css 'table > tbody > tr:nth-child(3) > td:nth-child(1).halign-center.valign-top p em', output, 1 - assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p', output, 1 - assert_css 'table tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 0 - assert_css 'table tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p code', output, 1 + assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p', output, 1 + assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(1).halign-left.valign-top p em', output, 0 + assert_css 'table > tbody > tr:nth-child(4) > td:nth-child(2).halign-right.valign-top[colspan="2"] p code', output, 1 end test 'supports repeating cells' do input = <<-EOS |=== @@ -472,10 +472,47 @@ assert_css 'table table', output, 1 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 + input = <<-EOS += Document Title + +[cols="1a"] +|=== +|AsciiDoc content +|=== + EOS + + output = render_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 + + test 'cell background color' do + input = <<-EOS +[cols="1e,1", options="header"] +|=== +|{set:cellbgcolor:green}green +|{set:cellbgcolor!} +plain +|{set:cellbgcolor:red}red +|{set:cellbgcolor!} +plain +|=== + EOS + + output = render_embedded_string 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 end context 'DSV' do test 'renders simple dsv table' do @@ -495,10 +532,25 @@ assert_css 'table > colgroup > col[style*="width:14%"]', output, 7 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 + + test 'dsv format shorthand' do + input = <<-EOS +:=== +a:b:c +1:2:3 +:=== + EOS + output = render_embedded_string 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 end context 'CSV' do test 'mixed unquoted records and quoted records with escaped quotes, commas and wrapped lines' do @@ -519,9 +571,24 @@ 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 assert_xpath %(((//tbody/tr)[2]/td)[3]/p[text()='Venture "Extended Edition"']), output, 1 assert_xpath '((//tbody/tr)[4]/td)[4]/p[text()="MUST SELL! air, moon roof, loaded"]', output, 1 + end + + test 'csv format shorthand' do + input = <<-EOS +,=== +a,b,c +1,2,3 +,=== + EOS + output = render_embedded_string 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' do input = <<-EOS [format="csv", separator=";"]