-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsource_test.py
79 lines (58 loc) · 2.01 KB
/
source_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
import scanner
import source
import unittest
import symboltypes
class SourceTestCase(unittest.TestCase):
def testScanSource(self):
test_source = source.ScanScript(_TEST_SCRIPT)
self.assertEquals(
set(['goog.aaa', 'goog.bbb']), test_source.provides)
self.assertEquals(
set(['goog.ccc', 'goog.ddd']), test_source.requires)
self.assertEquals(1, len(test_source.symbols))
symbol = list(test_source.symbols)[0]
self.assertEquals('goog.aaa.bbb', symbol.identifier)
self.assertTrue(symbol.static)
self.assertEquals('goog.aaa', symbol.namespace)
self.assertEquals(symboltypes.FUNCTION, symbol.type)
comment = symbol.comment
self.assertEquals('Testing testing.\n@return {string} Dog.', comment.text)
self.assertEquals(['Testing testing.'], comment.description_sections)
self.assertEquals(1, len(comment.flags))
flag = comment.flags[0]
self.assertEquals('@return', flag.name)
self.assertEquals('{string} Dog.', flag.text)
def testIsIgnorableIdentifier(self):
match = scanner.FindCommentTarget(' aaa.bbb = 3');
self.assertEquals('aaa.bbb', match.group())
self.assertFalse(source._IsIgnorableIdentifier(match))
match = scanner.FindCommentTarget(' aaa.bbb(3)');
self.assertEquals('aaa.bbb', match.group())
self.assertTrue(source._IsIgnorableIdentifier(match))
match = scanner.FindCommentTarget(' aaa.bbb[3])');
self.assertEquals('aaa.bbb', match.group())
self.assertTrue(source._IsIgnorableIdentifier(match))
def testScanPrototypeProperty(self):
test_source = source.ScanScript("""\
goog.provide('abc.Def');
/**
* Test.
*/
abc.Def.prototype.ghi;
""")
symbol = list(test_source.symbols)[0]
self.assertEquals('ghi', symbol.property)
self.assertFalse(symbol.static)
_TEST_SCRIPT = """
goog.provide('goog.aaa');
goog.provide('goog.bbb');
goog.require('goog.ccc');
goog.require('goog.ddd');
/**
* Testing testing.
* @return {string} Dog.
*/
goog.aaa.bbb;
"""
if __name__ == '__main__':
unittest.main()