1 | #!/usr/bin/env python2
|
2 | from __future__ import print_function
|
3 |
|
4 | import unittest
|
5 | import re
|
6 |
|
7 | from data_lang import htm8
|
8 |
|
9 | class RegexTest(unittest.TestCase):
|
10 |
|
11 | def testDotAll(self):
|
12 | # type: () -> None
|
13 |
|
14 | # Note that $ matches end of line, not end of string
|
15 | p1 = re.compile(r'.')
|
16 | print(p1.match('\n'))
|
17 |
|
18 | p2 = re.compile(r'.', re.DOTALL)
|
19 | print(p2.match('\n'))
|
20 |
|
21 | #p3 = re.compile(r'[.\n]', re.VERBOSE)
|
22 | p3 = re.compile(r'[.\n]')
|
23 | print(p3.match('\n'))
|
24 |
|
25 | print('Negation')
|
26 |
|
27 | p4 = re.compile(r'[^>]')
|
28 | print(p4.match('\n'))
|
29 |
|
30 | def testAttrRe(self):
|
31 | # type: () -> None
|
32 | _ATTR_RE = htm8._ATTR_RE
|
33 | m = _ATTR_RE.match(' empty= val')
|
34 | print(m.groups())
|
35 |
|
36 |
|
37 | class FunctionsTest(unittest.TestCase):
|
38 |
|
39 | def testFindLineNum(self):
|
40 | # type: () -> None
|
41 | s = 'foo\n' * 3
|
42 | for pos in [1, 5, 10, 50]: # out of bounds
|
43 | line_num = htm8.FindLineNum(s, pos)
|
44 | print(line_num)
|
45 |
|
46 |
|
47 | if __name__ == '__main__':
|
48 | unittest.main()
|