-
Notifications
You must be signed in to change notification settings - Fork 2
/
flags_test.py
105 lines (78 loc) · 2.51 KB
/
flags_test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import flags
import unittest
import re
import source
class FlagTestCase(unittest.TestCase):
def testParseParamDescription(self):
desc = '{!bbb|ccc?} aaa This \nis the desc. '
self.assertEquals(
('aaa', '!bbb|ccc?', 'This \nis the desc.'),
flags.ParseParameterDescription(desc))
desc = '{...*} var_args The items to substitute into the pattern.'
self.assertEquals(
('var_args', '...*', 'The items to substitute into the pattern.'),
flags.ParseParameterDescription(desc))
desc = '{string} aaa'
self.assertEquals(
('aaa', 'string', ''),
flags.ParseParameterDescription(desc))
self.assertRaises(
ValueError,
lambda: flags.ParseParameterDescription('desc without type'))
def testParseReturnDescription(self):
desc = ' {!bbb|ccc?} This \nis the desc. '
self.assertEquals(
('!bbb|ccc?', 'This \nis the desc.'),
flags.ParseReturnDescription(desc))
self.assertRaises(
ValueError,
lambda: flags.ParseReturnDescription('desc without type'))
def testMabyeParseTypeFromDescription(self):
self.assertEquals(
'aaa',
flags.MaybeParseTypeFromDescription(' {aaa} bbb ccc'))
self.assertEquals(
None,
flags.MaybeParseTypeFromDescription('aaa bbb ccc'))
@staticmethod
def GetFlags(script):
desc, flags = source._GetDescriptionAndFlags(script)
return flags
def testGetSymbolType(self):
self.assertEquals(
'aaa', flags.GetSymbolType(self.GetFlags("""@const {aaa}""")))
self.assertEquals(
'bbb', flags.GetSymbolType(self.GetFlags("""@private {bbb}""")))
self.assertEquals(
'ccc', flags.GetSymbolType(self.GetFlags("""@protected {ccc}""")))
self.assertEquals(
'ddd', flags.GetSymbolType(self.GetFlags("""@const {ddd}""")))
def testGetVisibility(self):
test_source = source.ScanScript("""\
goog.provide('abc');
/**
* @private
*/
abc.def;
""")
symbol = list(test_source.symbols)[0]
self.assertEquals(flags.PRIVATE, flags.GetVisibility(symbol.comment.flags))
test_source = source.ScanScript("""\
goog.provide('abc');
/**
* @protected
*/
abc.def;
""")
symbol = list(test_source.symbols)[0]
self.assertEquals(flags.PROTECTED, flags.GetVisibility(symbol.comment.flags))
test_source = source.ScanScript("""\
goog.provide('abc');
/**
*/
abc.def;
""")
symbol = list(test_source.symbols)[0]
self.assertEquals(flags.PUBLIC, flags.GetVisibility(symbol.comment.flags))
if __name__ == '__main__':
unittest.main()