summaryrefslogtreecommitdiff
path: root/bs4/tests/test_html5lib.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2019-07-21 15:50:49 -0400
committerLeonard Richardson <leonardr@segfault.org>2019-07-21 15:50:49 -0400
commit41c2b7c056e73c63c872eeb0a5e3a1f65473eaf0 (patch)
tree514f0a3ccd449c74d847917471ec6c09642e1318 /bs4/tests/test_html5lib.py
parentb2294f4f05d9e8583613560986f8aa64b18866b9 (diff)
Implemented line number tracking for html5lib.
Diffstat (limited to 'bs4/tests/test_html5lib.py')
-rw-r--r--bs4/tests/test_html5lib.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/bs4/tests/test_html5lib.py b/bs4/tests/test_html5lib.py
index 371463a..6446f84 100644
--- a/bs4/tests/test_html5lib.py
+++ b/bs4/tests/test_html5lib.py
@@ -168,3 +168,17 @@ class HTML5LibBuilderSmokeTest(SoupTest, HTML5TreeBuilderSmokeTest):
for form in soup.find_all('form'):
inputs.extend(form.find_all('input'))
self.assertEqual(len(inputs), 1)
+
+ def test_tracking_line_numbers(self):
+ # The html.parser TreeBuilder keeps track of line number and
+ # position of each element.
+ markup = "\n <p>\n\n<sourceline>\n<b>text</b></sourceline><sourcepos></p>"
+ soup = self.soup(markup)
+ self.assertEqual(2, soup.p.sourceline)
+ self.assertEqual(5, soup.p.sourcepos)
+ self.assertEqual("sourceline", soup.p.find('sourceline').name)
+
+ # You can deactivate this behavior.
+ soup = self.soup(markup, store_line_numbers=False)
+ self.assertEqual("sourceline", soup.p.sourceline.name)
+ self.assertEqual("sourcepos", soup.p.sourcepos.name)