3 # Copyright 2010 The Closure Library Authors. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS-IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 """Unit test for source."""
20 __author__ = 'nnaze@google.com (Nathan Naze)'
28 class SourceTestCase(unittest.TestCase):
29 """Unit test for source. Tests the parser on a known source input."""
31 def testSourceScan(self):
32 test_source = source.Source(_TEST_SOURCE)
34 self.assertEqual(set(['foo', 'foo.test']),
36 self.assertEqual(set(['goog.dom', 'goog.events.EventType']),
39 def testSourceScanBase(self):
40 test_source = source.Source(_TEST_BASE_SOURCE)
42 self.assertEqual(set(['goog']),
44 self.assertEqual(test_source.requires, set())
46 def testSourceScanBadBase(self):
49 source.Source(_TEST_BAD_BASE_SOURCE)
51 self.assertRaises(Exception, MakeSource)
53 def testStripComments(self):
55 '\nvar foo = function() {}',
56 source.Source._StripComments((
59 ' over multiple lines\n'
61 'var foo = function() {}')))
63 def testGoogStatementsInComments(self):
64 test_source = source.Source(_TEST_COMMENT_SOURCE)
66 self.assertEqual(set(['foo']),
68 self.assertEqual(set(['goog.events.EventType']),
71 def testHasProvideGoog(self):
72 self.assertTrue(source.Source._HasProvideGoogFlag(_TEST_BASE_SOURCE))
73 self.assertTrue(source.Source._HasProvideGoogFlag(_TEST_BAD_BASE_SOURCE))
74 self.assertFalse(source.Source._HasProvideGoogFlag(_TEST_COMMENT_SOURCE))
77 _TEST_SOURCE = """// Fake copyright notice
79 /** Very important comment. */
82 goog.provide('foo.test');
84 goog.require('goog.dom');
85 goog.require('goog.events.EventType');
88 // Set bar to seventeen to increase performance.
93 _TEST_COMMENT_SOURCE = """// Fake copyright notice
98 goog.provide('foo.test');
102 goog.require('goog.dom');
105 // goog.require('goog.dom');
107 goog.require('goog.events.EventType');
114 _TEST_BASE_SOURCE = """
116 * @fileoverview The base file.
120 var goog = goog || {};
123 _TEST_BAD_BASE_SOURCE = """
125 * @fileoverview The base file.
129 goog.provide('goog');
133 if __name__ == '__main__':