OLD | NEW |
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 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 }; |
321 | 321 |
322 } // module my.mod | 322 } // module my.mod |
323 """ | 323 """ |
324 expected = \ | 324 expected = \ |
325 [('MODULE', | 325 [('MODULE', |
326 'my.mod', | 326 'my.mod', |
327 None, | 327 None, |
328 [('STRUCT', | 328 [('STRUCT', |
329 'MyStruct', | 329 'MyStruct', |
330 None, | 330 None, |
331 [('FIELD', 'int32', 'a', ast.Ordinal(None), None)])])] | 331 [('FIELD', 'int32', 'a', ast.Ordinal(None), None)])])] |
332 self.assertEquals(parser.Parse(source, "my_file.mojom"), expected) | 332 self.assertEquals(parser.Parse(source, "my_file.mojom"), expected) |
333 | 333 |
| 334 def testValidHandleTypes(self): |
| 335 """Tests (valid) handle types.""" |
| 336 source = """\ |
| 337 struct MyStruct { |
| 338 handle a; |
| 339 handle<data_pipe_consumer> b; |
| 340 handle <data_pipe_producer> c; |
| 341 handle < message_pipe > d; |
| 342 handle |
| 343 < shared_buffer |
| 344 > e; |
| 345 }; |
| 346 """ |
| 347 expected = \ |
| 348 [('MODULE', |
| 349 '', |
| 350 None, |
| 351 [('STRUCT', |
| 352 'MyStruct', |
| 353 None, |
| 354 [('FIELD', 'handle', 'a', ast.Ordinal(None), None), |
| 355 ('FIELD', 'handle<data_pipe_consumer>', 'b', ast.Ordinal(None), None), |
| 356 ('FIELD', 'handle<data_pipe_producer>', 'c', ast.Ordinal(None), None), |
| 357 ('FIELD', 'handle<message_pipe>', 'd', ast.Ordinal(None), None), |
| 358 ('FIELD', 'handle<shared_buffer>', 'e', ast.Ordinal(None), None)])])] |
| 359 self.assertEquals(parser.Parse(source, "my_file.mojom"), expected) |
| 360 |
| 361 def testInvalidHandleType(self): |
| 362 """Tests an invalid (unknown) handle type.""" |
| 363 source = """\ |
| 364 struct MyStruct { |
| 365 handle<wtf_is_this> foo; |
| 366 }; |
| 367 """ |
| 368 with self.assertRaisesRegexp( |
| 369 parser.ParseError, |
| 370 r"^my_file\.mojom:2: Error: " |
| 371 r"Invalid handle type 'wtf_is_this':\n" |
| 372 r" handle<wtf_is_this> foo;$"): |
| 373 parser.Parse(source, "my_file.mojom") |
| 374 |
334 | 375 |
335 if __name__ == "__main__": | 376 if __name__ == "__main__": |
336 unittest.main() | 377 unittest.main() |
OLD | NEW |