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 def _GetDirAbove(dirname): | 10 def _GetDirAbove(dirname): |
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 struct MyStruct { | 665 struct MyStruct { |
666 int32[999999999999] too_big_array; | 666 int32[999999999999] too_big_array; |
667 }; | 667 }; |
668 """ | 668 """ |
669 with self.assertRaisesRegexp( | 669 with self.assertRaisesRegexp( |
670 parser.ParseError, | 670 parser.ParseError, |
671 r"^my_file\.mojom:2: Error: Fixed array size 999999999999 invalid\n" | 671 r"^my_file\.mojom:2: Error: Fixed array size 999999999999 invalid\n" |
672 r" *int32\[999999999999\] too_big_array;$"): | 672 r" *int32\[999999999999\] too_big_array;$"): |
673 parser.Parse(source2, "my_file.mojom") | 673 parser.Parse(source2, "my_file.mojom") |
674 | 674 |
675 source3 = """\ | 675 def testValidAssociativeArrays(self): |
676 struct MyStruct { | 676 """Tests that we can parse valid associative array structures.""" |
677 int32[abcdefg] not_a_number; | 677 |
678 }; | 678 source1 = "struct MyStruct { uint8[string] data; };" |
679 """ | 679 expected1 = ast.Mojom( |
680 with self.assertRaisesRegexp( | 680 None, |
681 parser.ParseError, | 681 ast.ImportList(), |
682 r"^my_file\.mojom:2: Error: Unexpected 'abcdefg':\n" | 682 [ast.Struct( |
683 r" *int32\[abcdefg\] not_a_number;"): | 683 'MyStruct', |
684 parser.Parse(source3, "my_file.mojom") | 684 None, |
| 685 ast.StructBody( |
| 686 [ast.StructField('data', None, 'uint8{string}', None)]))]) |
| 687 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) |
| 688 |
| 689 source2 = "interface MyInterface { MyMethod(uint8[string] a); };" |
| 690 expected2 = ast.Mojom( |
| 691 None, |
| 692 ast.ImportList(), |
| 693 [ast.Interface( |
| 694 'MyInterface', |
| 695 None, |
| 696 ast.InterfaceBody( |
| 697 ast.Method( |
| 698 'MyMethod', |
| 699 None, |
| 700 ast.ParameterList( |
| 701 ast.Parameter('a', None, 'uint8{string}')), |
| 702 None)))]) |
| 703 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) |
| 704 |
| 705 source3 = "struct MyStruct { uint8[string][] data; };" |
| 706 expected3 = ast.Mojom( |
| 707 None, |
| 708 ast.ImportList(), |
| 709 [ast.Struct( |
| 710 'MyStruct', |
| 711 None, |
| 712 ast.StructBody( |
| 713 [ast.StructField('data', None, 'uint8{string}[]', None)]))]) |
| 714 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) |
| 715 |
685 | 716 |
686 def testValidMethod(self): | 717 def testValidMethod(self): |
687 """Tests parsing method declarations.""" | 718 """Tests parsing method declarations.""" |
688 | 719 |
689 source1 = "interface MyInterface { MyMethod(int32 a); };" | 720 source1 = "interface MyInterface { MyMethod(int32 a); };" |
690 expected1 = ast.Mojom( | 721 expected1 = ast.Mojom( |
691 None, | 722 None, |
692 ast.ImportList(), | 723 ast.ImportList(), |
693 [ast.Interface( | 724 [ast.Interface( |
694 'MyInterface', | 725 'MyInterface', |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 }; | 1080 }; |
1050 """ | 1081 """ |
1051 with self.assertRaisesRegexp( | 1082 with self.assertRaisesRegexp( |
1052 parser.ParseError, | 1083 parser.ParseError, |
1053 r"^my_file\.mojom:2: Error: Unexpected '&':\n" | 1084 r"^my_file\.mojom:2: Error: Unexpected '&':\n" |
1054 r" *some_interface\?& a;$"): | 1085 r" *some_interface\?& a;$"): |
1055 parser.Parse(source3, "my_file.mojom") | 1086 parser.Parse(source3, "my_file.mojom") |
1056 | 1087 |
1057 if __name__ == "__main__": | 1088 if __name__ == "__main__": |
1058 unittest.main() | 1089 unittest.main() |
OLD | NEW |