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 |
|
10 | class RegexTest(unittest.TestCase):
|
11 |
|
12 | def testDotAll(self):
|
13 | # type: () -> None
|
14 |
|
15 | # Note that $ matches end of line, not end of string
|
16 | p1 = re.compile(r'.')
|
17 | print(p1.match('\n'))
|
18 |
|
19 | p2 = re.compile(r'.', re.DOTALL)
|
20 | print(p2.match('\n'))
|
21 |
|
22 | #p3 = re.compile(r'[.\n]', re.VERBOSE)
|
23 | p3 = re.compile(r'[.\n]')
|
24 | print(p3.match('\n'))
|
25 |
|
26 | print('Negation')
|
27 |
|
28 | p4 = re.compile(r'[^>]')
|
29 | print(p4.match('\n'))
|
30 |
|
31 | def testAttrRe(self):
|
32 | # type: () -> None
|
33 | _ATTR_RE = htm8._ATTR_RE
|
34 | m = _ATTR_RE.match(' empty= val')
|
35 | print(m.groups())
|
36 |
|
37 |
|
38 | class FunctionsTest(unittest.TestCase):
|
39 |
|
40 | def testFindLineNum(self):
|
41 | # type: () -> None
|
42 | s = 'foo\n' * 3
|
43 | for pos in [1, 5, 10, 50]: # out of bounds
|
44 | line_num = htm8._FindLineNum(s, pos)
|
45 | print(line_num)
|
46 |
|
47 |
|
48 | class AttrLexerTest(unittest.TestCase):
|
49 |
|
50 | def testAttrLexer(self):
|
51 | # type: () -> None
|
52 |
|
53 | # TODO: h8_id.StartTag and EndTag will expose the tag_name_pos - the
|
54 | # end of the tag name
|
55 |
|
56 | attr_lexer = htm8.AttrLexer('x <a>')
|
57 | attr_lexer.Init(4, 4)
|
58 | attr_lexer.ReadName()
|
59 |
|
60 | attr_lexer = htm8.AttrLexer('x <a>')
|
61 | attr_lexer.Init(4, 4)
|
62 | attr_lexer.ReadName()
|
63 |
|
64 |
|
65 | if __name__ == '__main__':
|
66 | unittest.main()
|