| 42 | |
| 43 | |
| 44 | def test_parser_generators(): |
| 45 | parser = rl.Parser(rl.HtmlOptions()) |
| 46 | parser.process(b"<html><p>Ali</p></html>") |
| 47 | parser.finish() |
| 48 | |
| 49 | repr(parser) |
| 50 | |
| 51 | parser = rl.Parser(rl.HtmlOptions()) |
| 52 | parser.process("<html><p>Ali</p></html>") |
| 53 | |
| 54 | repr(parser) |
| 55 | |
| 56 | with pytest.raises(TypeError): |
| 57 | parser.process(1) |
| 58 | |
| 59 | with pytest.raises(RuntimeError): |
| 60 | parser.into_dom() |
| 61 | |
| 62 | parser.finish() |
| 63 | |
| 64 | with pytest.raises(RuntimeError): |
| 65 | parser.process("") |
| 66 | |
| 67 | with pytest.raises(RuntimeError): |
| 68 | parser.finish() |
| 69 | |
| 70 | parser.into_dom() |
| 71 | with pytest.raises(RuntimeError): |
| 72 | parser.into_dom() |
| 73 | |
| 74 | parser = rl.Parser(rl.XmlOptions()) |
| 75 | for c in ("<html>", b"Ali", b"</html>"): |
| 76 | parser.process(c) |
| 77 | parser.finish() |
| 78 | |
| 79 | assert isinstance(parser.errors(), list) |
| 80 | assert parser.lineno() == 1 |
| 81 | assert parser.quirks_mode() == 2 |
| 82 | |
| 83 | parser = rl.Parser(rl.HtmlOptions(full_document=False)) |
| 84 | for c in (b"<html><p>Ali</p>", "\n", "</html>"): |
| 85 | parser.process(c) |
| 86 | parser.finish() |
| 87 | |
| 88 | assert parser.lineno() == 2 |
| 89 | |
| 90 | _ = parser.into_dom() |
| 91 | |
| 92 | repr(parser) |
| 93 | |
| 94 | with pytest.raises(RuntimeError): |
| 95 | parser.errors() |
| 96 | |
| 97 | |
| 98 | def test_document(): |