1 | #!/usr/bin/env python2
|
2 | from __future__ import print_function
|
3 |
|
4 | import unittest
|
5 |
|
6 | from _devbuild.gen.id_kind_asdl import Id
|
7 | from _devbuild.gen.syntax_asdl import EggexFlag, Token, source, SourceLine
|
8 |
|
9 | from core import error
|
10 | from ysh import regex_translate
|
11 |
|
12 |
|
13 | def _Name(s):
|
14 | # Doesn't work
|
15 | #return lexer.DummyToken(Id.Expr_Name, s)
|
16 | src = source.Stdin('')
|
17 | source_line = SourceLine(1, s, src)
|
18 | return Token(Id.Expr_Name, len(s), 0, source_line, None)
|
19 |
|
20 |
|
21 | class RegexTranslateTest(unittest.TestCase):
|
22 |
|
23 | def testCanonicalFlags(self):
|
24 | reg_icase = _Name('reg_icase')
|
25 | i = _Name('i') # abbreviation
|
26 | reg_newline = _Name('reg_newline')
|
27 | bad = _Name('bad')
|
28 |
|
29 | flags = [EggexFlag(False, reg_icase)]
|
30 | self.assertEqual('i', regex_translate.CanonicalFlags(flags))
|
31 |
|
32 | flags = [EggexFlag(False, i)]
|
33 | self.assertEqual('i', regex_translate.CanonicalFlags(flags))
|
34 |
|
35 | flags = [EggexFlag(False, bad)]
|
36 | try:
|
37 | regex_translate.CanonicalFlags(flags)
|
38 | except error.Parse as e:
|
39 | print(e.UserErrorString())
|
40 | else:
|
41 | self.fail('Should have failed')
|
42 |
|
43 | order1 = [EggexFlag(False, reg_icase), EggexFlag(False, reg_newline)]
|
44 | order2 = [EggexFlag(False, reg_newline), EggexFlag(False, reg_icase)]
|
45 |
|
46 | self.assertEqual('in', regex_translate.CanonicalFlags(order1))
|
47 | self.assertEqual('in', regex_translate.CanonicalFlags(order2))
|
48 |
|
49 |
|
50 | if __name__ == '__main__':
|
51 | unittest.main()
|