Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: build/android/gyp/java_cpp_enum_tests.py

Issue 2396533002: Allow multi-line enum entries in java_cpp_enum.py. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tests for enum_preprocess.py. 6 """Tests for enum_preprocess.py.
7 7
8 This test suite containss various tests for the C++ -> Java enum generator. 8 This test suite containss various tests for the C++ -> Java enum generator.
9 """ 9 """
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 """.split('\n') 101 """.split('\n')
102 definitions = HeaderParser(test_data).ParseDefinitions() 102 definitions = HeaderParser(test_data).ParseDefinitions()
103 self.assertEqual(1, len(definitions)) 103 self.assertEqual(1, len(definitions))
104 definition = definitions[0] 104 definition = definitions[0]
105 self.assertEqual('EnumName', definition.class_name) 105 self.assertEqual('EnumName', definition.class_name)
106 self.assertEqual('test.namespace', definition.enum_package) 106 self.assertEqual('test.namespace', definition.enum_package)
107 self.assertEqual(collections.OrderedDict([('VALUE_ZERO', '1 << 0'), 107 self.assertEqual(collections.OrderedDict([('VALUE_ZERO', '1 << 0'),
108 ('VALUE_ONE', '1 << 1')]), 108 ('VALUE_ONE', '1 << 1')]),
109 definition.entries) 109 definition.entries)
110 110
111 def testParseMultilineEnumEntry(self):
112 test_data = """
113 // GENERATED_JAVA_ENUM_PACKAGE: bar.namespace
114 enum Foo {
115 VALUE_ZERO = 1 << 0,
116 VALUE_ONE =
117 SymbolKey | FnKey | AltGrKey | MetaKey | AltKey | ControlKey,
118 VALUE_TWO = 1 << 18,
119 };
120 """.split('\n')
121 expected_entries = collections.OrderedDict([
122 ('VALUE_ZERO', '1 << 0'),
123 ('VALUE_ONE', 'SymbolKey | FnKey | AltGrKey | MetaKey | AltKey | '
124 'ControlKey'),
125 ('VALUE_TWO', '1 << 18')])
126 definitions = HeaderParser(test_data).ParseDefinitions()
127 self.assertEqual(1, len(definitions))
128 definition = definitions[0]
129 self.assertEqual('Foo', definition.class_name)
130 self.assertEqual('bar.namespace', definition.enum_package)
131 self.assertEqual(expected_entries, definition.entries)
132
133 def testParseEnumEntryWithTrailingMultilineEntry(self):
134 test_data = """
135 // GENERATED_JAVA_ENUM_PACKAGE: bar.namespace
136 enum Foo {
137 VALUE_ZERO = 1,
138 VALUE_ONE =
139 SymbolKey | FnKey | AltGrKey | MetaKey |
140 AltKey | ControlKey | ShiftKey,
141 };
142 """.split('\n')
143 expected_entries = collections.OrderedDict([
144 ('VALUE_ZERO', '1'),
145 ('VALUE_ONE', 'SymbolKey | FnKey | AltGrKey | MetaKey | AltKey | '
146 'ControlKey | ShiftKey')])
147 definitions = HeaderParser(test_data).ParseDefinitions()
148 self.assertEqual(1, len(definitions))
149 definition = definitions[0]
150 self.assertEqual('Foo', definition.class_name)
151 self.assertEqual('bar.namespace', definition.enum_package)
152 self.assertEqual(expected_entries, definition.entries)
153
154 def testParseNoCommaAfterLastEntry(self):
155 test_data = """
156 // GENERATED_JAVA_ENUM_PACKAGE: bar.namespace
157 enum Foo {
158 VALUE_ZERO = 1,
159
160 // This is a multiline
161 //
162 // comment with an empty line.
163 VALUE_ONE = 2
164 };
165 """.split('\n')
166 expected_entries = collections.OrderedDict([
167 ('VALUE_ZERO', '1'),
168 ('VALUE_ONE', '2')])
169 expected_comments = collections.OrderedDict([
170 ('VALUE_ONE', 'This is a multiline comment with an empty line.')])
171 definitions = HeaderParser(test_data).ParseDefinitions()
172 self.assertEqual(1, len(definitions))
173 definition = definitions[0]
174 self.assertEqual('Foo', definition.class_name)
175 self.assertEqual('bar.namespace', definition.enum_package)
176 self.assertEqual(expected_entries, definition.entries)
177 self.assertEqual(expected_comments, definition.comments)
178
111 def testParseClassNameOverride(self): 179 def testParseClassNameOverride(self):
112 test_data = """ 180 test_data = """
113 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace 181 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
114 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OverrideName 182 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OverrideName
115 enum EnumName { 183 enum EnumName {
116 FOO 184 FOO
117 }; 185 };
118 186
119 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace 187 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
120 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OtherOverride 188 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OtherOverride
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 options, _ = parser.parse_args(argv) 529 options, _ = parser.parse_args(argv)
462 530
463 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) 531 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess)
464 unittest.TextTestRunner(verbosity=0).run(suite) 532 unittest.TextTestRunner(verbosity=0).run(suite)
465 533
466 if options.stamp: 534 if options.stamp:
467 build_utils.Touch(options.stamp) 535 build_utils.Touch(options.stamp)
468 536
469 if __name__ == '__main__': 537 if __name__ == '__main__':
470 main(sys.argv[1:]) 538 main(sys.argv[1:])
OLDNEW
« build/android/gyp/java_cpp_enum.py ('K') | « build/android/gyp/java_cpp_enum.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698