Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / google_input_tools / third_party / closure_library / closure / bin / build / source_test.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2010 The Closure Library Authors. All Rights Reserved.
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17
18 """Unit test for source."""
19
20 __author__ = 'nnaze@google.com (Nathan Naze)'
21
22
23 import unittest
24
25 import source
26
27
28 class SourceTestCase(unittest.TestCase):
29   """Unit test for source.  Tests the parser on a known source input."""
30
31   def testSourceScan(self):
32     test_source = source.Source(_TEST_SOURCE)
33
34     self.assertEqual(set(['foo', 'foo.test']),
35                      test_source.provides)
36     self.assertEqual(set(['goog.dom', 'goog.events.EventType']),
37                      test_source.requires)
38
39   def testSourceScanBase(self):
40     test_source = source.Source(_TEST_BASE_SOURCE)
41
42     self.assertEqual(set(['goog']),
43                      test_source.provides)
44     self.assertEqual(test_source.requires, set())
45
46   def testSourceScanBadBase(self):
47
48     def MakeSource():
49       source.Source(_TEST_BAD_BASE_SOURCE)
50
51     self.assertRaises(Exception, MakeSource)
52
53   def testStripComments(self):
54     self.assertEquals(
55         '\nvar foo = function() {}',
56         source.Source._StripComments((
57             '/* This is\n'
58             '  a comment split\n'
59             '  over multiple lines\n'
60             '*/\n'
61             'var foo = function() {}')))
62
63   def testGoogStatementsInComments(self):
64     test_source = source.Source(_TEST_COMMENT_SOURCE)
65
66     self.assertEqual(set(['foo']),
67                      test_source.provides)
68     self.assertEqual(set(['goog.events.EventType']),
69                      test_source.requires)
70
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))
75
76
77 _TEST_SOURCE = """// Fake copyright notice
78
79 /** Very important comment. */
80
81 goog.provide('foo');
82 goog.provide('foo.test');
83
84 goog.require('goog.dom');
85 goog.require('goog.events.EventType');
86
87 function foo() {
88   // Set bar to seventeen to increase performance.
89   this.bar = 17;
90 }
91 """
92
93 _TEST_COMMENT_SOURCE = """// Fake copyright notice
94
95 goog.provide('foo');
96
97 /*
98 goog.provide('foo.test');
99  */
100
101 /*
102 goog.require('goog.dom');
103 */
104
105 // goog.require('goog.dom');
106
107 goog.require('goog.events.EventType');
108
109 function bar() {
110   this.baz = 55;
111 }
112 """
113
114 _TEST_BASE_SOURCE = """
115 /**
116  * @fileoverview The base file.
117  * @provideGoog
118  */
119
120 var goog = goog || {};
121 """
122
123 _TEST_BAD_BASE_SOURCE = """
124 /**
125  * @fileoverview The base file.
126  * @provideGoog
127  */
128
129 goog.provide('goog');
130 """
131
132
133 if __name__ == '__main__':
134   unittest.main()