summary refs log tree commit diff stats
path: root/tests/stdlib/thtmlparser2813.nim
blob: 4b04bc3f0cdda8b02e14aba35158cfa346797bc3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
discard """
  output: "@[]"
"""
import htmlparser
import xmltree
from streams import newStringStream

const
  html = """
  <html>
    <head>
      <title>Test</title>
    </head>
    <body>
      <table>
        <thead>
          <tr><td>A</td></tr>
          <tr><td>B</td></tr>
        </thead>
        <tbody>
          <tr><td></td>A<td></td></tr>
          <tr><td></td>B<td></td></tr>
          <tr><td></td>C<td></td></tr>
        </tbody>
        <tfoot>
          <tr><td>A</td></tr>
        </tfoot>
      </table>
    </body>
  </html>
  """
var errors: seq[string] = @[]

let tree = parseHtml(newStringStream(html), "test.html", errors)

echo errors # Errors: </thead> expected,...

var len = tree.findAll("tr").len # len = 6

var rows: seq[XmlNode] = @[]
for n in tree.findAll("table"):
  n.findAll("tr", rows)  # len = 2
  break

assert tree.findAll("tr").len == rows.len