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

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

Issue 363033004: Mojo: bindings generator: Add an AST type for parameter lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 5 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/translate.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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 source1 = "interface MyInterface { MyMethod(int32 a); };" 585 source1 = "interface MyInterface { MyMethod(int32 a); };"
586 expected1 = \ 586 expected1 = \
587 [('MODULE', 587 [('MODULE',
588 '', 588 '',
589 None, 589 None,
590 [('INTERFACE', 590 [('INTERFACE',
591 'MyInterface', 591 'MyInterface',
592 None, 592 None,
593 [('METHOD', 593 [('METHOD',
594 'MyMethod', 594 'MyMethod',
595 [ast.Parameter('int32', 'a', ast.Ordinal(None))], 595 ast.ParameterList(ast.Parameter('int32', 'a', ast.Ordinal(None))),
596 ast.Ordinal(None), 596 ast.Ordinal(None),
597 None)])])] 597 None)])])]
598 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) 598 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1)
599 599
600 source2 = """\ 600 source2 = """\
601 interface MyInterface { 601 interface MyInterface {
602 MyMethod1@0(int32 a@0, int64 b@1); 602 MyMethod1@0(int32 a@0, int64 b@1);
603 MyMethod2@1() => (); 603 MyMethod2@1() => ();
604 }; 604 };
605 """ 605 """
606 expected2 = \ 606 expected2 = \
607 [('MODULE', 607 [('MODULE',
608 '', 608 '',
609 None, 609 None,
610 [('INTERFACE', 610 [('INTERFACE',
611 'MyInterface', 611 'MyInterface',
612 None, 612 None,
613 [('METHOD', 613 [('METHOD',
614 'MyMethod1', 614 'MyMethod1',
615 [ast.Parameter('int32', 'a', ast.Ordinal(0)), 615 ast.ParameterList([ast.Parameter('int32', 'a', ast.Ordinal(0)),
616 ast.Parameter('int64', 'b', ast.Ordinal(1))], 616 ast.Parameter('int64', 'b', ast.Ordinal(1))]),
617 ast.Ordinal(0), 617 ast.Ordinal(0),
618 None), 618 None),
619 ('METHOD', 619 ('METHOD',
620 'MyMethod2', 620 'MyMethod2',
621 [], 621 ast.ParameterList(),
622 ast.Ordinal(1), 622 ast.Ordinal(1),
623 [])])])] 623 ast.ParameterList())])])]
624 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) 624 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2)
625 625
626 source3 = """\ 626 source3 = """\
627 interface MyInterface { 627 interface MyInterface {
628 MyMethod(string a) => (int32 a, bool b); 628 MyMethod(string a) => (int32 a, bool b);
629 }; 629 };
630 """ 630 """
631 expected3 = \ 631 expected3 = \
632 [('MODULE', 632 [('MODULE',
633 '', 633 '',
634 None, 634 None,
635 [('INTERFACE', 635 [('INTERFACE',
636 'MyInterface', 636 'MyInterface',
637 None, 637 None,
638 [('METHOD', 638 [('METHOD',
639 'MyMethod', 639 'MyMethod',
640 [ast.Parameter('string', 'a', ast.Ordinal(None))], 640 ast.ParameterList(ast.Parameter('string', 'a',
641 ast.Ordinal(None))),
641 ast.Ordinal(None), 642 ast.Ordinal(None),
642 [ast.Parameter('int32', 'a', ast.Ordinal(None)), 643 ast.ParameterList([ast.Parameter('int32', 'a', ast.Ordinal(None)),
643 ast.Parameter('bool', 'b', ast.Ordinal(None))])])])] 644 ast.Parameter('bool', 'b',
645 ast.Ordinal(None))]))])])]
644 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) 646 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3)
645 647
646 def testInvalidMethods(self): 648 def testInvalidMethods(self):
647 """Tests that invalid method declarations are correctly detected.""" 649 """Tests that invalid method declarations are correctly detected."""
648 650
649 # No trailing commas. 651 # No trailing commas.
650 source1 = """\ 652 source1 = """\
651 interface MyInterface { 653 interface MyInterface {
652 MyMethod(string a,); 654 MyMethod(string a,);
653 }; 655 };
(...skipping 11 matching lines...) Expand all
665 }; 667 };
666 """ 668 """
667 with self.assertRaisesRegexp( 669 with self.assertRaisesRegexp(
668 parser.ParseError, 670 parser.ParseError,
669 r"^my_file\.mojom:2: Error: Unexpected ',':\n" 671 r"^my_file\.mojom:2: Error: Unexpected ',':\n"
670 r" *MyMethod\(, string a\);$"): 672 r" *MyMethod\(, string a\);$"):
671 parser.Parse(source2, "my_file.mojom") 673 parser.Parse(source2, "my_file.mojom")
672 674
673 if __name__ == "__main__": 675 if __name__ == "__main__":
674 unittest.main() 676 unittest.main()
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/translate.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698