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

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

Issue 2503763004: Fix comment preservation in java_cpp_enum.py. (Closed)
Patch Set: Create separate test for comment preservation w/prefix-stripping 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 self.assertEqual(2, len(definitions)) 195 self.assertEqual(2, len(definitions))
196 definition = definitions[0] 196 definition = definitions[0]
197 self.assertEqual('OverrideName', definition.class_name) 197 self.assertEqual('OverrideName', definition.class_name)
198 198
199 definition = definitions[1] 199 definition = definitions[1]
200 self.assertEqual('OtherOverride', definition.class_name) 200 self.assertEqual('OtherOverride', definition.class_name)
201 self.assertEqual(collections.OrderedDict([('A', 0), 201 self.assertEqual(collections.OrderedDict([('A', 0),
202 ('B', 1)]), 202 ('B', 1)]),
203 definition.entries) 203 definition.entries)
204 204
205 def testParseTwoEnums(self): 205 def testParsePreservesCommentsWhenPrefixStripping(self):
206 test_data = """ 206 test_data = """
207 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace 207 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
208 enum EnumOne { 208 enum EnumOne {
209 ENUM_ONE_A = 1, 209 ENUM_ONE_A = 1,
210 // Comment there 210 // Comment there
211 ENUM_ONE_B = A, 211 ENUM_ONE_B = A,
212 }; 212 };
213 213
214 enum EnumIgnore { 214 enum EnumIgnore {
215 C, D, E 215 C, D, E
216 }; 216 };
217 217
218 // GENERATED_JAVA_ENUM_PACKAGE: other.package 218 // GENERATED_JAVA_ENUM_PACKAGE: other.package
219 // GENERATED_JAVA_PREFIX_TO_STRIP: P_ 219 // GENERATED_JAVA_PREFIX_TO_STRIP: P_
220 enum EnumTwo { 220 enum EnumTwo {
221 P_A, 221 P_A,
222 // This comment spans 222 // This comment spans
223 // two lines. 223 // two lines.
224 P_B 224 P_B
225 }; 225 };
226 """.split('\n') 226 """.split('\n')
227 definitions = HeaderParser(test_data).ParseDefinitions() 227 definitions = HeaderParser(test_data).ParseDefinitions()
228 self.assertEqual(2, len(definitions)) 228 self.assertEqual(2, len(definitions))
229 definition = definitions[0] 229 definition = definitions[0]
230 self.assertEqual('EnumOne', definition.class_name) 230 self.assertEqual('EnumOne', definition.class_name)
231 self.assertEqual('test.namespace', definition.enum_package) 231 self.assertEqual('test.namespace', definition.enum_package)
232 self.assertEqual(collections.OrderedDict([('A', '1'), 232 self.assertEqual(collections.OrderedDict([('A', '1'),
233 ('B', 'A')]), 233 ('B', 'A')]),
234 definition.entries) 234 definition.entries)
235 self.assertEqual(collections.OrderedDict([('ENUM_ONE_B', 'Comment there')]), 235 self.assertEqual(collections.OrderedDict([('B', 'Comment there')]),
236 definition.comments) 236 definition.comments)
237 definition = definitions[1] 237 definition = definitions[1]
238 self.assertEqual('EnumTwo', definition.class_name) 238 self.assertEqual('EnumTwo', definition.class_name)
239 self.assertEqual('other.package', definition.enum_package) 239 self.assertEqual('other.package', definition.enum_package)
240 self.assertEqual(collections.OrderedDict( 240 self.assertEqual(collections.OrderedDict(
241 [('P_B', 'This comment spans two lines.')]), definition.comments) 241 [('B', 'This comment spans two lines.')]), definition.comments)
242 self.assertEqual(collections.OrderedDict([('A', 0), 242 self.assertEqual(collections.OrderedDict([('A', 0),
243 ('B', 1)]), 243 ('B', 1)]),
244 definition.entries) 244 definition.entries)
245 245
246 def testParseTwoEnums(self):
247 test_data = """
248 // GENERATED_JAVA_ENUM_PACKAGE: test.namespace
249 enum AnEnum {
250 ENUM_ONE_A = 1,
251 ENUM_ONE_B = A,
252 };
253
254 enum EnumIgnore {
255 C, D, E
256 };
257
258 // GENERATED_JAVA_ENUM_PACKAGE: other.package
259 enum EnumTwo {
260 P_A,
261 P_B
262 };
263 """.split('\n')
264 definitions = HeaderParser(test_data).ParseDefinitions()
265 self.assertEqual(2, len(definitions))
266 definition = definitions[0]
267 self.assertEqual('AnEnum', definition.class_name)
268 self.assertEqual('test.namespace', definition.enum_package)
269 self.assertEqual(collections.OrderedDict([('ENUM_ONE_A', '1'),
270 ('ENUM_ONE_B', 'A')]),
271 definition.entries)
272 definition = definitions[1]
273 self.assertEqual('EnumTwo', definition.class_name)
274 self.assertEqual('other.package', definition.enum_package)
275 self.assertEqual(collections.OrderedDict([('P_A', 0),
276 ('P_B', 1)]),
277 definition.entries)
278
246 def testParseThrowsOnUnknownDirective(self): 279 def testParseThrowsOnUnknownDirective(self):
247 test_data = """ 280 test_data = """
248 // GENERATED_JAVA_UNKNOWN: Value 281 // GENERATED_JAVA_UNKNOWN: Value
249 enum EnumName { 282 enum EnumName {
250 VALUE_ONE, 283 VALUE_ONE,
251 }; 284 };
252 """.split('\n') 285 """.split('\n')
253 with self.assertRaises(Exception): 286 with self.assertRaises(Exception):
254 HeaderParser(test_data).ParseDefinitions() 287 HeaderParser(test_data).ParseDefinitions()
255 288
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 options, _ = parser.parse_args(argv) 562 options, _ = parser.parse_args(argv)
530 563
531 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess) 564 suite = unittest.TestLoader().loadTestsFromTestCase(TestPreprocess)
532 unittest.TextTestRunner(verbosity=0).run(suite) 565 unittest.TextTestRunner(verbosity=0).run(suite)
533 566
534 if options.stamp: 567 if options.stamp:
535 build_utils.Touch(options.stamp) 568 build_utils.Touch(options.stamp)
536 569
537 if __name__ == '__main__': 570 if __name__ == '__main__':
538 main(sys.argv[1:]) 571 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