| 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 r" *int32\[abcdefg\] not_a_number;"): | 619 r" *int32\[abcdefg\] not_a_number;"): |
| 620 parser.Parse(source3, "my_file.mojom") | 620 parser.Parse(source3, "my_file.mojom") |
| 621 | 621 |
| 622 def testValidMethod(self): | 622 def testValidMethod(self): |
| 623 """Tests parsing method declarations.""" | 623 """Tests parsing method declarations.""" |
| 624 | 624 |
| 625 source1 = "interface MyInterface { MyMethod(int32 a); };" | 625 source1 = "interface MyInterface { MyMethod(int32 a); };" |
| 626 expected1 = ast.Mojom( | 626 expected1 = ast.Mojom( |
| 627 None, | 627 None, |
| 628 ast.ImportList(), | 628 ast.ImportList(), |
| 629 [('INTERFACE', | 629 [ast.Interface( |
| 630 'MyInterface', | 630 'MyInterface', |
| 631 None, | |
| 632 [('METHOD', | |
| 633 'MyMethod', | |
| 634 ast.ParameterList(ast.Parameter('a', None, 'int32')), | |
| 635 None, | 631 None, |
| 636 None)])]) | 632 ast.InterfaceBody( |
| 633 ast.Method( |
| 634 'MyMethod', |
| 635 None, |
| 636 ast.ParameterList(ast.Parameter('a', None, 'int32')), |
| 637 None)))]) |
| 637 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) | 638 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) |
| 638 | 639 |
| 639 source2 = """\ | 640 source2 = """\ |
| 640 interface MyInterface { | 641 interface MyInterface { |
| 641 MyMethod1@0(int32 a@0, int64 b@1); | 642 MyMethod1@0(int32 a@0, int64 b@1); |
| 642 MyMethod2@1() => (); | 643 MyMethod2@1() => (); |
| 643 }; | 644 }; |
| 644 """ | 645 """ |
| 645 expected2 = ast.Mojom( | 646 expected2 = ast.Mojom( |
| 646 None, | 647 None, |
| 647 ast.ImportList(), | 648 ast.ImportList(), |
| 648 [('INTERFACE', | 649 [ast.Interface( |
| 649 'MyInterface', | 650 'MyInterface', |
| 650 None, | 651 None, |
| 651 [('METHOD', | 652 ast.InterfaceBody([ |
| 652 'MyMethod1', | 653 ast.Method( |
| 653 ast.ParameterList([ast.Parameter('a', ast.Ordinal(0), 'int32'), | 654 'MyMethod1', |
| 654 ast.Parameter('b', ast.Ordinal(1), 'int64')]), | 655 ast.Ordinal(0), |
| 655 ast.Ordinal(0), | 656 ast.ParameterList([ast.Parameter('a', ast.Ordinal(0), |
| 656 None), | 657 'int32'), |
| 657 ('METHOD', | 658 ast.Parameter('b', ast.Ordinal(1), |
| 658 'MyMethod2', | 659 'int64')]), |
| 659 ast.ParameterList(), | 660 None), |
| 660 ast.Ordinal(1), | 661 ast.Method( |
| 661 ast.ParameterList())])]) | 662 'MyMethod2', |
| 663 ast.Ordinal(1), |
| 664 ast.ParameterList(), |
| 665 ast.ParameterList())]))]) |
| 662 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) | 666 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) |
| 663 | 667 |
| 664 source3 = """\ | 668 source3 = """\ |
| 665 interface MyInterface { | 669 interface MyInterface { |
| 666 MyMethod(string a) => (int32 a, bool b); | 670 MyMethod(string a) => (int32 a, bool b); |
| 667 }; | 671 }; |
| 668 """ | 672 """ |
| 669 expected3 = ast.Mojom( | 673 expected3 = ast.Mojom( |
| 670 None, | 674 None, |
| 671 ast.ImportList(), | 675 ast.ImportList(), |
| 672 [('INTERFACE', | 676 [ast.Interface( |
| 673 'MyInterface', | 677 'MyInterface', |
| 674 None, | |
| 675 [('METHOD', | |
| 676 'MyMethod', | |
| 677 ast.ParameterList(ast.Parameter('a', None, 'string')), | |
| 678 None, | 678 None, |
| 679 ast.ParameterList([ast.Parameter('a', None, 'int32'), | 679 ast.InterfaceBody( |
| 680 ast.Parameter('b', None, 'bool')]))])]) | 680 ast.Method( |
| 681 'MyMethod', |
| 682 None, |
| 683 ast.ParameterList(ast.Parameter('a', None, 'string')), |
| 684 ast.ParameterList([ast.Parameter('a', None, 'int32'), |
| 685 ast.Parameter('b', None, 'bool')]))))]) |
| 681 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) | 686 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) |
| 682 | 687 |
| 683 def testInvalidMethods(self): | 688 def testInvalidMethods(self): |
| 684 """Tests that invalid method declarations are correctly detected.""" | 689 """Tests that invalid method declarations are correctly detected.""" |
| 685 | 690 |
| 686 # No trailing commas. | 691 # No trailing commas. |
| 687 source1 = """\ | 692 source1 = """\ |
| 688 interface MyInterface { | 693 interface MyInterface { |
| 689 MyMethod(string a,); | 694 MyMethod(string a,); |
| 690 }; | 695 }; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 """ | 833 """ |
| 829 with self.assertRaisesRegexp( | 834 with self.assertRaisesRegexp( |
| 830 parser.ParseError, | 835 parser.ParseError, |
| 831 r"^my_file\.mojom:2: Error: Unexpected 'module':\n" | 836 r"^my_file\.mojom:2: Error: Unexpected 'module':\n" |
| 832 r" *module {}$"): | 837 r" *module {}$"): |
| 833 parser.Parse(source2, "my_file.mojom") | 838 parser.Parse(source2, "my_file.mojom") |
| 834 | 839 |
| 835 | 840 |
| 836 if __name__ == "__main__": | 841 if __name__ == "__main__": |
| 837 unittest.main() | 842 unittest.main() |
| OLD | NEW |