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

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

Issue 841173006: Add multi-line directives in the C++->Java enum generator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 5 years, 11 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
« no previous file with comments | « build/android/gyp/java_cpp_enum.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 def testParseUnknownFixedTypeRaises(self): 216 def testParseUnknownFixedTypeRaises(self):
217 test_data = """ 217 test_data = """
218 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace 218 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
219 enum class Foo: foo_type { 219 enum class Foo: foo_type {
220 FOO_A, 220 FOO_A,
221 }; 221 };
222 """.split('\n') 222 """.split('\n')
223 with self.assertRaises(Exception): 223 with self.assertRaises(Exception):
224 HeaderParser(test_data).ParseDefinitions() 224 HeaderParser(test_data).ParseDefinitions()
225 225
226 def testParseSimpleMultiLineDirective(self):
227 test_data = """
228 // GENERATED_JAVA_ENUM_PACKAGE: \\
229 // test.namespace
230 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: Bar
231 enum Foo {
232 FOO_A,
233 };
234 """.split('\n')
235 definitions = HeaderParser(test_data).ParseDefinitions()
236 self.assertEqual('test.namespace', definitions[0].enum_package)
237 self.assertEqual('Bar', definitions[0].class_name)
238
239 def testParseMultiLineDirective(self):
240 test_data = """
241 // GENERATED_JAVA_ENUM_PACKAGE: te\\
242 // st.name\\
243 // space
244 enum Foo {
245 FOO_A,
246 };
247 """.split('\n')
248 definitions = HeaderParser(test_data).ParseDefinitions()
249 self.assertEqual('test.namespace', definitions[0].enum_package)
250
251 def testParseMultiLineDirectiveWithOtherDirective(self):
252 test_data = """
253 // GENERATED_JAVA_ENUM_PACKAGE: \\
254 // test.namespace
255 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: \\
256 // Ba\\
257 // r
258 enum Foo {
259 FOO_A,
260 };
261 """.split('\n')
262 definitions = HeaderParser(test_data).ParseDefinitions()
263 self.assertEqual('test.namespace', definitions[0].enum_package)
264 self.assertEqual('Bar', definitions[0].class_name)
265
266 def testParseMalformedMultiLineDirectiveWithOtherDirective(self):
267 test_data = """
268 // GENERATED_JAVA_ENUM_PACKAGE: \\
269 // test.name\\
270 // space\\
271 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: Bar
272 enum Foo {
273 FOO_A,
274 };
275 """.split('\n')
276 with self.assertRaises(Exception):
277 HeaderParser(test_data).ParseDefinitions()
278
279 def testParseMalformedMultiLineDirective(self):
280 test_data = """
281 // GENERATED_JAVA_ENUM_PACKAGE: \\
282 // test.name\\
283 // space\\
284 enum Foo {
285 FOO_A,
286 };
287 """.split('\n')
288 with self.assertRaises(Exception):
289 HeaderParser(test_data).ParseDefinitions()
290
291 def testParseMalformedMultiLineDirectiveShort(self):
292 test_data = """
293 // GENERATED_JAVA_ENUM_PACKAGE: \\
294 enum Foo {
295 FOO_A,
296 };
297 """.split('\n')
298 with self.assertRaises(Exception):
299 HeaderParser(test_data).ParseDefinitions()
300
226 def testEnumValueAssignmentNoneDefined(self): 301 def testEnumValueAssignmentNoneDefined(self):
227 definition = EnumDefinition(original_enum_name='c', enum_package='p') 302 definition = EnumDefinition(original_enum_name='c', enum_package='p')
228 definition.AppendEntry('A', None) 303 definition.AppendEntry('A', None)
229 definition.AppendEntry('B', None) 304 definition.AppendEntry('B', None)
230 definition.AppendEntry('C', None) 305 definition.AppendEntry('C', None)
231 definition.Finalize() 306 definition.Finalize()
232 self.assertEqual(collections.OrderedDict([('A', 0), 307 self.assertEqual(collections.OrderedDict([('A', 0),
233 ('B', 1), 308 ('B', 1),
234 ('C', 2)]), 309 ('C', 2)]),
235 definition.entries) 310 definition.entries)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 options, _ = parser.parse_args(argv) 408 options, _ = parser.parse_args(argv)
334 409
335 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) 410 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess)
336 unittest.TextTestRunner(verbosity=0).run(suite) 411 unittest.TextTestRunner(verbosity=0).run(suite)
337 412
338 if options.stamp: 413 if options.stamp:
339 build_utils.Touch(options.stamp) 414 build_utils.Touch(options.stamp)
340 415
341 if __name__ == '__main__': 416 if __name__ == '__main__':
342 main(sys.argv[1:]) 417 main(sys.argv[1:])
OLDNEW
« no previous file with comments | « 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