HTML reader tests: improve test coverage of new features

This commit is contained in:
Albert Krewinkel 2020-11-27 21:21:25 +01:00
parent 3a2d993165
commit 8c38390038
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
3 changed files with 187 additions and 1 deletions

View file

@ -214,7 +214,8 @@ normalize :: [ColWidth] -> TableHead -> [TableBody] -> TableFoot
-> Either String ([ColSpec], TableHead, [TableBody], TableFoot)
normalize widths head' bodies foot = do
let rows = headRows head' <> concatMap bodyRows bodies <> footRows foot
let rowLength = length . rowCells
let cellWidth (Cell _ _ _ (ColSpan cs) _) = cs
let rowLength = foldr (\cell acc -> cellWidth cell + acc) 0 . rowCells
let ncols = maximum (map rowLength rows)
let tblType = tableType (map rowCells rows)
-- fail on empty table

View file

@ -487,6 +487,7 @@ An e-mail address: nobody [at] nowhere.net<blockquote>
</tbody>
</table>
<hr />
<p>Row headers</p>
<table>
<thead>
<tr>
@ -656,6 +657,7 @@ An e-mail address: nobody [at] nowhere.net<blockquote>
</tbody>
</table>
<hr />
<p>tbody tags omitted</p>
<table>
<tr>
<td>1</td>
@ -669,6 +671,7 @@ An e-mail address: nobody [at] nowhere.net<blockquote>
</tr>
</table>
<hr />
<p>empty head</p>
<table>
<thead>
</thead>
@ -686,6 +689,7 @@ An e-mail address: nobody [at] nowhere.net<blockquote>
</tbody>
</table>
<hr />
<p>explicit body and foot</p>
<table>
<tbody>
<tr>
@ -702,6 +706,78 @@ An e-mail address: nobody [at] nowhere.net<blockquote>
</tr>
</tfoot>
</table>
<h2>Colspans and Rowspans</h2>
<table>
<tr>
<td colspan="2">1 and 2</td>
<td>3</td>
</tr>
<tr>
<td colspan="3">4, 5, and 6</td>
</tr>
</table>
<hr/>
<table>
<thead>
<tr>
<th colspan="3">Numbers</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">1 and 4</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>5</td>
<td>6</td>
</tr>
</tbody>
</table>
<h2>Attributes</h2>
<table id="attrib-test-table">
<thead class="table-head">
<tr class="table-head-row">
<th abbr="x" colspan="3">Cat X</th>
</tr>
<tbody data-part="body" class="main">
<tr data-part="row">
<td data-part="cell">1</td>
<td valign="bottom">2</td>
<td style="color: #151950">3</td>
</tr>
</tbody>
<tfoot class="summary">
<tr bgcolor="#ccc">
<td data-square="true">4</td>
<td>5</td>
<td>6</td>
</tr>
</tfoot>
</table>
<h2>Tag omission</h2>
<p>thead, tbody, and tfoot</p>
<table>
<thead>
<tr>
<td>X</td>
<td>Y</td>
<td>Z</td>
</tr>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tfoot>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>
<h2>Empty Tables</h2>
<p>This section should be empty.</p>
<table>

View file

@ -395,6 +395,7 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
(TableFoot ("",[],[])
[])
,HorizontalRule
,Para [Str "Row",Space,Str "headers"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
@ -647,6 +648,7 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
(TableFoot ("",[],[])
[])
,HorizontalRule
,Para [Str "tbody",Space,Str "tags",Space,Str "omitted"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
@ -673,6 +675,7 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
(TableFoot ("",[],[])
[])
,HorizontalRule
,Para [Str "empty",Space,Str "head"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
@ -699,6 +702,7 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
(TableFoot ("",[],[])
[])
,HorizontalRule
,Para [Str "explicit",Space,Str "body",Space,Str "and",Space,Str "foot"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
@ -723,5 +727,110 @@ Pandoc (Meta {unMeta = fromList [("generator",MetaInlines [Str "pandoc"]),("titl
[Plain [Str "5"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "6"]]]])
,Header 2 ("colspans-and-rowspans",[],[]) [Str "Colspans",Space,Str "and",Space,Str "Rowspans"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)]
(TableHead ("",[],[])
[])
[(TableBody ("",[],[]) (RowHeadColumns 0)
[]
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 2)
[Plain [Str "1",Space,Str "and",Space,Str "2"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "3"]]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 3)
[Plain [Str "4,",Space,Str "5,",Space,Str "and",Space,Str "6"]]]])]
(TableFoot ("",[],[])
[])
,HorizontalRule
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)]
(TableHead ("",[],[])
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 3)
[Plain [Str "Numbers"]]]])
[(TableBody ("",[],[]) (RowHeadColumns 0)
[]
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 2) (ColSpan 1)
[Plain [Str "1",Space,Str "and",Space,Str "4"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "2"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "3"]]]
,Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "5"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "6"]]]])]
(TableFoot ("",[],[])
[])
,Header 2 ("attributes",[],[]) [Str "Attributes"]
,Table ("attrib-test-table",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)]
(TableHead ("",["table-head"],[])
[Row ("",["table-head-row"],[])
[Cell ("",[],[("abbr","x")]) AlignDefault (RowSpan 1) (ColSpan 3)
[Plain [Str "Cat",Space,Str "X"]]]])
[(TableBody ("",["main"],[("part","body")]) (RowHeadColumns 0)
[]
[Row ("",[],[("part","row")])
[Cell ("",[],[("part","cell")]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "1"]]
,Cell ("",[],[("valign","bottom")]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "2"]]
,Cell ("",[],[("style","color: #151950")]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "3"]]]])]
(TableFoot ("",["summary"],[])
[Row ("",[],[("bgcolor","#ccc")])
[Cell ("",[],[("square","true")]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "4"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "5"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "6"]]]])
,Header 2 ("tag-omission",[],[]) [Str "Tag",Space,Str "omission"]
,Para [Str "thead,",Space,Str "tbody,",Space,Str "and",Space,Str "tfoot"]
,Table ("",[],[]) (Caption Nothing
[])
[(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)
,(AlignDefault,ColWidthDefault)]
(TableHead ("",[],[])
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "X"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "Y"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "Z"]]]])
[(TableBody ("",[],[]) (RowHeadColumns 0)
[]
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "1"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "2"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "3"]]]])]
(TableFoot ("",[],[])
[Row ("",[],[])
[Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "4"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "5"]]
,Cell ("",[],[]) AlignDefault (RowSpan 1) (ColSpan 1)
[Plain [Str "6"]]]])
,Header 2 ("empty-tables",[],[]) [Str "Empty",Space,Str "Tables"]
,Para [Str "This",Space,Str "section",Space,Str "should",Space,Str "be",Space,Str "empty."]]