test/tables_test.rb in asciidoctor-1.5.5 vs test/tables_test.rb in asciidoctor-1.5.6
- old
+ new
@@ -150,19 +150,20 @@
input = <<-EOS
|===
A | here| a | there
|===
EOS
- output = render_embedded_string input
+ output, warnings = redirect_streams {|_, err| [(render_embedded_string input), err.string] }
assert_css 'table', output, 1
assert_css 'table > colgroup > col', output, 4
assert_css 'table > tbody > tr', output, 1
assert_css 'table > tbody > tr > td', output, 4
assert_xpath '/table/tbody/tr/td[1]/p[text()="A"]', output, 1
assert_xpath '/table/tbody/tr/td[2]/p[text()="here"]', output, 1
assert_xpath '/table/tbody/tr/td[3]/p[text()="a"]', output, 1
assert_xpath '/table/tbody/tr/td[4]/p[text()="there"]', output, 1
+ assert_includes warnings, 'table missing leading separator'
end
test 'performs normal substitutions on cell content' do
input = <<-EOS
:show_title: Cool new show
@@ -170,13 +171,61 @@
|{show_title} |Coming soon...
|===
EOS
output = render_embedded_string input
assert_xpath '//tbody/tr/td[1]/p[text()="Cool new show"]', output, 1
- assert_xpath %(//tbody/tr/td[2]/p[text()='Coming soon#{expand_entity 8230}#{expand_entity 8203}']), 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
+ input = <<-EOS
+|===
+l|one
+*two*
+three
+<four>
+|===
+ EOS
+ output = render_embedded_string input
+ result = xmlnodes_at_xpath('/table//pre', output, 1)
+ assert_equal %(<pre>one\n*two*\nthree\n<four></pre>), result.to_s
+ end
+
+ test 'should preserving leading spaces but not leading endlines or trailing spaces in literal table cells' do
+ input = <<-EOS
+[cols=2*]
+|===
+l|
+ one
+ two
+three
+
+ | normal
+|===
+ EOS
+ output = render_embedded_string 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
+ input = <<-EOS
+[cols=2*]
+|===
+v|
+ one
+ two
+three
+
+ | normal
+|===
+ EOS
+ output = render_embedded_string 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 col width not assigned when autowidth option is specified' do
input = <<-EOS
[options="autowidth"]
|=======
|A |B |C
@@ -413,10 +462,26 @@
assert_css 'table > thead > tr > th', output, 2
assert_css 'table > tbody', output, 1
assert_css 'table > tbody > tr', output, 2
end
+ test 'table with implicit header row only' do
+ input = <<-EOS
+|===
+|Column 1 |Column 2
+
+|===
+ EOS
+ output = render_embedded_string 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
+ assert_css 'table > tbody', output, 0
+ end
+
test 'table with implicit header row when other options set' do
input = <<-EOS
[%autowidth]
|===
|Column 1 |Column 2
@@ -453,10 +518,57 @@
assert_css 'table > thead', output, 0
assert_css 'table > tbody', output, 1
assert_css 'table > tbody > tr', output, 3
end
+ test 'no implicit header row if cell in first line spans multiple lines' do
+ input = <<-EOS
+[cols=2*]
+|===
+|A1
+
+
+A1 continued|B1
+
+|A2
+|B2
+|===
+ 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]/p', output, 2
+ end
+
+ test 'no implicit header row if AsciiDoc cell in first line spans multiple lines' do
+ input = <<-EOS
+[cols=2*]
+|===
+a|contains AsciiDoc content
+
+* a
+* b
+* c
+a|contains no AsciiDoc content
+
+just text
+|A2
+|B2
+|===
+ 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]//ul', output, 1
+ end
+
test 'no implicit header row if first line blank' do
input = <<-EOS
|===
|Column 1 |Column 2
@@ -501,11 +613,11 @@
test 'styles not applied to header cells' do
input = <<-EOS
[cols="1h,1s,1e",options="header,footer"]
|====
|Name |Occupation| Website
-|Octocat |Social coding| http://github.com
+|Octocat |Social coding| https://github.com
|Name |Occupation| Website
|====
EOS
output = render_embedded_string input
assert_css 'table', output, 1
@@ -529,11 +641,11 @@
[cols="1h,1s,1e"]
|====
|Name |Occupation| Website
-|Octocat |Social coding| http://github.com
+|Octocat |Social coding| https://github.com
|Name |Occupation| Website
|====
EOS
@@ -754,13 +866,14 @@
a|C
more C
|===
EOS
- output = render_embedded_string input
+ output, warnings = redirect_streams {|_, err| [(render_embedded_string input), err.string] }
assert_css 'table', output, 1
assert_css 'table *', output, 0
+ assert_includes warnings, 'exceeds specified number of columns'
end
test 'paragraph, verse and literal content' do
input = <<-EOS
[cols=",^v,^l",options="header"]
@@ -810,10 +923,28 @@
assert_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
literal = xmlnodes_at_css 'table > tbody > tr > td:nth-child(3).halign-center.valign-top > div.literal > pre', output, 1
assert_equal 26, literal.text.lines.entries.size
end
+ test 'should strip trailing endline when splitting paragraphs' do
+ input = <<-EOS
+|===
+|first wrapped
+paragraph
+
+second paragraph
+
+third paragraph
+|===
+ EOS
+
+ result = render_embedded_string 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
+
test 'basic asciidoc cell' do
input = <<-EOS
|===
a|--
NOTE: content
@@ -844,24 +975,57 @@
result = render_embedded_string input
assert_css 'table.tableblock', result, 1
assert_css 'table.tableblock .paragraph', result, 0
end
- test 'compat mode can be activated in asciidoc table cell' do
+ test 'should reset doctype to default in AsciiDoc table cell' do
input = <<-EOS
+= Book Title
+:doctype: book
+
+== Chapter 1
+
|===
a|
-:compat-mode:
+= AsciiDoc Table Cell
-'italic'
+doctype={doctype}
+{backend-html5-doctype-article}
+{backend-html5-doctype-book}
|===
EOS
- result = render_embedded_string input
- assert_css 'table.tableblock td em', result, 1
+ result = render_embedded_string 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
+ test 'should update doctype-related attributes in AsciiDoc table cell when doctype is set' do
+ input = <<-EOS
+= Document Title
+:doctype: article
+
+== Chapter 1
+
+|===
+a|
+= AsciiDoc Table Cell
+:doctype: book
+
+doctype={doctype}
+{backend-html5-doctype-book}
+{backend-html5-doctype-article}
+|===
+ EOS
+
+ result = render_embedded_string 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
+
test 'asciidoc content' do
input = <<-EOS
[cols="1e,1,5a",frame="topbot",options="header"]
|===
|Name |Backends |Description
@@ -989,10 +1153,72 @@
['CO1-1', 'CO2-1', 'CO3-1'].each_with_index do |callout, idx|
assert_equal callout, callouts[idx].attribute('arearefs').value
end
end
+ test 'compat mode can be activated in AsciiDoc table cell' do
+ input = <<-EOS
+|===
+a|
+:compat-mode:
+
+The word 'italic' is emphasized.
+|===
+ EOS
+
+ result = render_embedded_string input
+ assert_xpath '//em[text()="italic"]', result, 1
+ end
+
+ test 'compat mode in AsciiDoc table cell inherits from parent document' do
+ input = <<-EOS
+:compat-mode:
+
+The word 'italic' is emphasized.
+
+[cols=1*]
+|===
+|The word 'oblique' is emphasized.
+a|
+The word 'slanted' is emphasized.
+|===
+
+The word 'askew' is emphasized.
+ EOS
+
+ result = render_embedded_string 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
+
+ test 'compat mode in AsciiDoc table cell can be unset if set in parent document' do
+ input = <<-EOS
+:compat-mode:
+
+The word 'italic' is emphasized.
+
+[cols=1*]
+|===
+|The word 'oblique' is emphasized.
+a|
+:!compat-mode:
+
+The word 'slanted' is not emphasized.
+|===
+
+The word 'askew' is emphasized.
+ EOS
+
+ result = render_embedded_string 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
+
test 'nested table' do
input = <<-EOS
[cols="1,2a"]
|===
|Normal cell
@@ -1004,15 +1230,34 @@
|===
EOS
output = render_embedded_string input
assert_css 'table', output, 2
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 'can set format of nested table to psv' do
+ input = <<-EOS
+[cols="2*"]
+|===
+|normal cell
+a|
+[format=psv]
+!===
+!nested cell
+!===
+|===
+ EOS
+
+ output = render_embedded_string 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
+
test 'toc from parent document should not be included in an AsciiDoc table cell' do
input = <<-EOS
= Document Title
:toc:
@@ -1205,30 +1450,34 @@
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 'mixed unquoted records and quoted records with escaped quotes, commas and wrapped lines' do
+ test 'mixed unquoted records and quoted records with escaped quotes, commas, and wrapped lines' do
input = <<-EOS
[format="csv",options="header"]
|===
Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
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
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_css 'table > tbody > tr', output, 6
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
+ assert_xpath %(((//tbody/tr)[5]/td)[4]/p[text()='"This one#{decode_char 8217}s gonna to blow you#{decode_char 8217}re socks off," per the sticker']), output, 1
+ assert_xpath %(((//tbody/tr)[6]/td)[4]/p[text()='Check it, "this one#{decode_char 8217}s gonna to blow you#{decode_char 8217}re socks off", per the sticker']), output, 1
end
test 'csv format shorthand' do
input = <<-EOS
,===
@@ -1242,13 +1491,29 @@
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
+ test 'tsv as format' do
input = <<-EOS
-[format="csv", separator=";"]
+[format=tsv]
+,===
+a\tb\tc
+1\t2\t3
+,===
+ 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 csv separator' do
+ input = <<-EOS
+[format=csv,separator=;]
|===
a;b;c
1;2;3
|===
EOS
@@ -1258,10 +1523,26 @@
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 'tab as separator' do
+ input = <<-EOS
+[separator=\\t]
+,===
+a\tb\tc
+1\t2\t3
+,===
+ 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 for an AsciiDoc table cell' do
input = <<-EOS
[cols=2,separator=!]
|===
!Pipe output to vim
@@ -1339,8 +1620,27 @@
|Item 1 |1
|===
EOS
output = render_embedded_string input, :backend => 'docbook45'
assert output.include?('<?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*]
+,===
+"A1
+
+A1 continued",B1
+A2,B2
+,===
+ 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]/p[text()="A1 A1 continued"]', output, 1
end
end
end