-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_parsers.py
51 lines (44 loc) · 1.41 KB
/
test_parsers.py
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
46
47
48
49
50
51
#!/usr/bin/python3
"""Unit tests for the compiler.parsers module"""
import re
import unittest
from pyhp.compiler import parsers
class TestRegexParser(unittest.TestCase):
"""Test the regex parser implementation"""
parser = parsers.RegexParser(re.compile("{"), re.compile("}"))
def test_syntax(self) -> None:
"""test basic syntax"""
sections = list(self.parser.parse("text1{code1}\n{code2}{\ncode3\n}text3\n"))
self.assertEqual(
sections,
[
("text1", 0, False),
("code1", 0, True),
("\n", 0, False),
("code2", 1, True),
("", 1, False),
("\ncode3\n", 1, True),
("text3\n", 3, False)
]
)
def test_missing_end(self) -> None:
"""test behavior on missing end of code section"""
sections = list(self.parser.parse("text1{code1"))
self.assertEqual(
sections,
[
("text1", 0, False),
("code1", 0, True)
]
)
def test_code_start(self) -> None:
"""test behavior on starting code section"""
sections = list(self.parser.parse("{code1}text1"))
self.assertEqual(
sections,
[
("", 0, False),
("code1", 0, True),
("text1", 0, False)
]
)