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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py

Issue 295973007: Mojo: Mojom: Change order of default values and ordinals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/parser.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 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import imp 5 import imp
6 import os.path 6 import os.path
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 # Disable lint check for finding modules: 10 # Disable lint check for finding modules:
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 parser.Parse(source, "my_file.mojom") 204 parser.Parse(source, "my_file.mojom")
205 205
206 def testSimpleOrdinals(self): 206 def testSimpleOrdinals(self):
207 """Tests that (valid) ordinal values are scanned correctly.""" 207 """Tests that (valid) ordinal values are scanned correctly."""
208 source = """\ 208 source = """\
209 module my_module { 209 module my_module {
210 210
211 // This isn't actually valid .mojom, but the problem (missing ordinals) should 211 // This isn't actually valid .mojom, but the problem (missing ordinals) should
212 // be handled at a different level. 212 // be handled at a different level.
213 struct MyStruct { 213 struct MyStruct {
214 int32 a0 @0; 214 int32 a0@0;
215 int32 a1 @1; 215 int32 a1@1;
216 int32 a2 @2; 216 int32 a2@2;
217 int32 a9 @9; 217 int32 a9@9;
218 int32 a10 @10; 218 int32 a10 @10;
219 int32 a11 @11; 219 int32 a11 @11;
220 int32 a29 @29; 220 int32 a29 @29;
221 int32 a1234567890 @1234567890; 221 int32 a1234567890 @1234567890;
222 }; 222 };
223 223
224 } // module my_module 224 } // module my_module
225 """ 225 """
226 expected = \ 226 expected = \
227 [('MODULE', 227 [('MODULE',
(...skipping 11 matching lines...) Expand all
239 ('FIELD', 'int32', 'a29', ast.Ordinal(29), None), 239 ('FIELD', 'int32', 'a29', ast.Ordinal(29), None),
240 ('FIELD', 'int32', 'a1234567890', ast.Ordinal(1234567890), None)])])] 240 ('FIELD', 'int32', 'a1234567890', ast.Ordinal(1234567890), None)])])]
241 self.assertEquals(parser.Parse(source, "my_file.mojom"), expected) 241 self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
242 242
243 def testInvalidOrdinals(self): 243 def testInvalidOrdinals(self):
244 """Tests that (lexically) invalid ordinals are correctly detected.""" 244 """Tests that (lexically) invalid ordinals are correctly detected."""
245 source1 = """\ 245 source1 = """\
246 module my_module { 246 module my_module {
247 247
248 struct MyStruct { 248 struct MyStruct {
249 int32 a_missing @; 249 int32 a_missing@;
250 }; 250 };
251 251
252 } // module my_module 252 } // module my_module
253 """ 253 """
254 with self.assertRaisesRegexp( 254 with self.assertRaisesRegexp(
255 lexer.LexError, 255 lexer.LexError,
256 r"^my_file\.mojom:4: Error: Missing ordinal value$"): 256 r"^my_file\.mojom:4: Error: Missing ordinal value$"):
257 parser.Parse(source1, "my_file.mojom") 257 parser.Parse(source1, "my_file.mojom")
258 258
259 source2 = """\ 259 source2 = """\
260 module my_module { 260 module my_module {
261 261
262 struct MyStruct { 262 struct MyStruct {
263 int32 a_octal @01; 263 int32 a_octal@01;
264 }; 264 };
265 265
266 } // module my_module 266 } // module my_module
267 """ 267 """
268 with self.assertRaisesRegexp( 268 with self.assertRaisesRegexp(
269 lexer.LexError, 269 lexer.LexError,
270 r"^my_file\.mojom:4: Error: " 270 r"^my_file\.mojom:4: Error: "
271 r"Octal and hexadecimal ordinal values not allowed$"): 271 r"Octal and hexadecimal ordinal values not allowed$"):
272 parser.Parse(source2, "my_file.mojom") 272 parser.Parse(source2, "my_file.mojom")
273 273
274 source3 = """\ 274 source3 = """\
275 module my_module { struct MyStruct { int32 a_invalid_octal @08; }; } 275 module my_module { struct MyStruct { int32 a_invalid_octal@08; }; }
276 """ 276 """
277 with self.assertRaisesRegexp( 277 with self.assertRaisesRegexp(
278 lexer.LexError, 278 lexer.LexError,
279 r"^my_file\.mojom:1: Error: " 279 r"^my_file\.mojom:1: Error: "
280 r"Octal and hexadecimal ordinal values not allowed$"): 280 r"Octal and hexadecimal ordinal values not allowed$"):
281 parser.Parse(source3, "my_file.mojom") 281 parser.Parse(source3, "my_file.mojom")
282 282
283 source4 = """\ 283 source4 = """\
284 module my_module { struct MyStruct { int32 a_hex @0x1aB9; }; } 284 module my_module { struct MyStruct { int32 a_hex@0x1aB9; }; }
285 """ 285 """
286 with self.assertRaisesRegexp( 286 with self.assertRaisesRegexp(
287 lexer.LexError, 287 lexer.LexError,
288 r"^my_file\.mojom:1: Error: " 288 r"^my_file\.mojom:1: Error: "
289 r"Octal and hexadecimal ordinal values not allowed$"): 289 r"Octal and hexadecimal ordinal values not allowed$"):
290 parser.Parse(source4, "my_file.mojom") 290 parser.Parse(source4, "my_file.mojom")
291 291
292 source5 = """\ 292 source5 = """\
293 module my_module { struct MyStruct { int32 a_hex @0X0; }; } 293 module my_module { struct MyStruct { int32 a_hex@0X0; }; }
294 """ 294 """
295 with self.assertRaisesRegexp( 295 with self.assertRaisesRegexp(
296 lexer.LexError, 296 lexer.LexError,
297 r"^my_file\.mojom:1: Error: " 297 r"^my_file\.mojom:1: Error: "
298 r"Octal and hexadecimal ordinal values not allowed$"): 298 r"Octal and hexadecimal ordinal values not allowed$"):
299 parser.Parse(source5, "my_file.mojom") 299 parser.Parse(source5, "my_file.mojom")
300 300
301 source6 = """\ 301 source6 = """\
302 struct MyStruct { 302 struct MyStruct {
303 int32 a_too_big @999999999999; 303 int32 a_too_big@999999999999;
304 }; 304 };
305 """ 305 """
306 with self.assertRaisesRegexp( 306 with self.assertRaisesRegexp(
307 parser.ParseError, 307 parser.ParseError,
308 r"^my_file\.mojom:2: Error: " 308 r"^my_file\.mojom:2: Error: "
309 r"Ordinal value 999999999999 too large:\n" 309 r"Ordinal value 999999999999 too large:\n"
310 r" int32 a_too_big @999999999999;$"): 310 r" int32 a_too_big@999999999999;$"):
311 parser.Parse(source6, "my_file.mojom") 311 parser.Parse(source6, "my_file.mojom")
312 312
313 def testNestedNamespace(self): 313 def testNestedNamespace(self):
314 """Tests that "nested" namespaces work.""" 314 """Tests that "nested" namespaces work."""
315 source = """\ 315 source = """\
316 module my.mod { 316 module my.mod {
317 317
318 struct MyStruct { 318 struct MyStruct {
319 int32 a; 319 int32 a;
320 }; 320 };
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 with self.assertRaisesRegexp( 368 with self.assertRaisesRegexp(
369 parser.ParseError, 369 parser.ParseError,
370 r"^my_file\.mojom:2: Error: " 370 r"^my_file\.mojom:2: Error: "
371 r"Invalid handle type 'wtf_is_this':\n" 371 r"Invalid handle type 'wtf_is_this':\n"
372 r" handle<wtf_is_this> foo;$"): 372 r" handle<wtf_is_this> foo;$"):
373 parser.Parse(source, "my_file.mojom") 373 parser.Parse(source, "my_file.mojom")
374 374
375 375
376 if __name__ == "__main__": 376 if __name__ == "__main__":
377 unittest.main() 377 unittest.main()
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698