| 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 struct MyStruct { | 676 struct MyStruct { |
| 677 array<int32, abcdefg> not_a_number; | 677 array<int32, abcdefg> not_a_number; |
| 678 }; | 678 }; |
| 679 """ | 679 """ |
| 680 with self.assertRaisesRegexp( | 680 with self.assertRaisesRegexp( |
| 681 parser.ParseError, | 681 parser.ParseError, |
| 682 r"^my_file\.mojom:2: Error: Unexpected 'abcdefg':\n" | 682 r"^my_file\.mojom:2: Error: Unexpected 'abcdefg':\n" |
| 683 r" *array<int32, abcdefg> not_a_number;"): | 683 r" *array<int32, abcdefg> not_a_number;"): |
| 684 parser.Parse(source3, "my_file.mojom") | 684 parser.Parse(source3, "my_file.mojom") |
| 685 | 685 |
| 686 def testValidAssociativeArrays(self): |
| 687 """Tests that we can parse valid associative array structures.""" |
| 688 |
| 689 source1 = "struct MyStruct { map<string, uint8> data; };" |
| 690 expected1 = ast.Mojom( |
| 691 None, |
| 692 ast.ImportList(), |
| 693 [ast.Struct( |
| 694 'MyStruct', |
| 695 None, |
| 696 ast.StructBody( |
| 697 [ast.StructField('data', None, 'uint8{string}', None)]))]) |
| 698 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) |
| 699 |
| 700 source2 = "interface MyInterface { MyMethod(map<string, uint8> a); };" |
| 701 expected2 = ast.Mojom( |
| 702 None, |
| 703 ast.ImportList(), |
| 704 [ast.Interface( |
| 705 'MyInterface', |
| 706 None, |
| 707 ast.InterfaceBody( |
| 708 ast.Method( |
| 709 'MyMethod', |
| 710 None, |
| 711 ast.ParameterList( |
| 712 ast.Parameter('a', None, 'uint8{string}')), |
| 713 None)))]) |
| 714 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) |
| 715 |
| 716 source3 = "struct MyStruct { map<string, array<uint8>> data; };" |
| 717 expected3 = ast.Mojom( |
| 718 None, |
| 719 ast.ImportList(), |
| 720 [ast.Struct( |
| 721 'MyStruct', |
| 722 None, |
| 723 ast.StructBody( |
| 724 [ast.StructField('data', None, 'uint8[]{string}', None)]))]) |
| 725 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) |
| 726 |
| 686 def testValidMethod(self): | 727 def testValidMethod(self): |
| 687 """Tests parsing method declarations.""" | 728 """Tests parsing method declarations.""" |
| 688 | 729 |
| 689 source1 = "interface MyInterface { MyMethod(int32 a); };" | 730 source1 = "interface MyInterface { MyMethod(int32 a); };" |
| 690 expected1 = ast.Mojom( | 731 expected1 = ast.Mojom( |
| 691 None, | 732 None, |
| 692 ast.ImportList(), | 733 ast.ImportList(), |
| 693 [ast.Interface( | 734 [ast.Interface( |
| 694 'MyInterface', | 735 'MyInterface', |
| 695 None, | 736 None, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 }; | 1090 }; |
| 1050 """ | 1091 """ |
| 1051 with self.assertRaisesRegexp( | 1092 with self.assertRaisesRegexp( |
| 1052 parser.ParseError, | 1093 parser.ParseError, |
| 1053 r"^my_file\.mojom:2: Error: Unexpected '&':\n" | 1094 r"^my_file\.mojom:2: Error: Unexpected '&':\n" |
| 1054 r" *some_interface\?& a;$"): | 1095 r" *some_interface\?& a;$"): |
| 1055 parser.Parse(source3, "my_file.mojom") | 1096 parser.Parse(source3, "my_file.mojom") |
| 1056 | 1097 |
| 1057 if __name__ == "__main__": | 1098 if __name__ == "__main__": |
| 1058 unittest.main() | 1099 unittest.main() |
| OLD | NEW |