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

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

Issue 2511533002: Add support for single line enums to java_cpp_enum.py. (Closed)
Patch Set: Created 4 years, 1 month 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 self.assertEqual(collections.OrderedDict([('ENUM_ONE_A', '1'), 269 self.assertEqual(collections.OrderedDict([('ENUM_ONE_A', '1'),
270 ('ENUM_ONE_B', 'A')]), 270 ('ENUM_ONE_B', 'A')]),
271 definition.entries) 271 definition.entries)
272 definition = definitions[1] 272 definition = definitions[1]
273 self.assertEqual('EnumTwo', definition.class_name) 273 self.assertEqual('EnumTwo', definition.class_name)
274 self.assertEqual('other.package', definition.enum_package) 274 self.assertEqual('other.package', definition.enum_package)
275 self.assertEqual(collections.OrderedDict([('P_A', 0), 275 self.assertEqual(collections.OrderedDict([('P_A', 0),
276 ('P_B', 1)]), 276 ('P_B', 1)]),
277 definition.entries) 277 definition.entries)
278 278
279 def testParseSingleLineEnum(self):
280 test_data = """
281 // GENERATED_JAVA_ENUM_PACKAGE: other.package
282 // GENERATED_JAVA_PREFIX_TO_STRIP: P_
283 enum EnumTwo { P_A, P_B };
284 """.split('\n')
285 definitions = HeaderParser(test_data).ParseDefinitions()
286 definition = definitions[0]
287 self.assertEqual('EnumTwo', definition.class_name)
288 self.assertEqual('other.package', definition.enum_package)
289 self.assertEqual(collections.OrderedDict([('A', 0),
290 ('B', 1)]),
291 definition.entries)
292
293 def testParseSingleLineAndRegularEnum(self):
294 test_data = """
295 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
296 enum EnumOne {
297 ENUM_ONE_A = 1,
298 // Comment there
299 ENUM_ONE_B = A,
300 };
301
302 // GENERATED_JAVA_ENUM_PACKAGE: other.package
303 enum EnumTwo { P_A, P_B };
304
305 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
306 // GENERATED_JAVA_CLASS_NAME_OVERRIDE: OverrideName
307 enum EnumName {
308 ENUM_NAME_FOO
309 };
310 """.split('\n')
311 definitions = HeaderParser(test_data).ParseDefinitions()
312 definition = definitions[0]
313 self.assertEqual(
314 collections.OrderedDict([('A', '1'), ('B', 'A')]), definition.entries)
315 self.assertEqual(collections.OrderedDict([('ENUM_ONE_B', 'Comment there')]),
316 definition.comments)
317
318 self.assertEqual(3, len(definitions))
319 definition = definitions[1]
320 self.assertEqual(
321 collections.OrderedDict([('P_A', 0), ('P_B', 1)]), definition.entries)
322
323 definition = definitions[2]
324 self.assertEqual(collections.OrderedDict([('FOO', 0)]), definition.entries)
325
279 def testParseThrowsOnUnknownDirective(self): 326 def testParseThrowsOnUnknownDirective(self):
280 test_data = """ 327 test_data = """
281 // GENERATED_JAVA_UNKNOWN: Value 328 // GENERATED_JAVA_UNKNOWN: Value
282 enum EnumName { 329 enum EnumName {
283 VALUE_ONE, 330 VALUE_ONE,
284 }; 331 };
285 """.split('\n') 332 """.split('\n')
286 with self.assertRaises(Exception): 333 with self.assertRaises(Exception):
287 HeaderParser(test_data).ParseDefinitions() 334 HeaderParser(test_data).ParseDefinitions()
288 335
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 options, _ = parser.parse_args(argv) 620 options, _ = parser.parse_args(argv)
574 621
575 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) 622 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess)
576 unittest.TextTestRunner(verbosity=0).run(suite) 623 unittest.TextTestRunner(verbosity=0).run(suite)
577 624
578 if options.stamp: 625 if options.stamp:
579 build_utils.Touch(options.stamp) 626 build_utils.Touch(options.stamp)
580 627
581 if __name__ == '__main__': 628 if __name__ == '__main__':
582 main(sys.argv[1:]) 629 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