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

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

Issue 695583002: Update mojo sdk to rev e083961bf11fd0c94d40be8853761da529b6d444 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch in https://codereview.chromium.org/692823003 Created 6 years, 1 month 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
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 def _GetDirAbove(dirname): 10 def _GetDirAbove(dirname):
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 with self.assertRaisesRegexp( 954 with self.assertRaisesRegexp(
955 parser.ParseError, 955 parser.ParseError,
956 r"^my_file\.mojom:1: Error: Unexpected '=':\n" 956 r"^my_file\.mojom:1: Error: Unexpected '=':\n"
957 r"\[=MyName\] struct MyStruct {};$"): 957 r"\[=MyName\] struct MyStruct {};$"):
958 parser.Parse(source3, "my_file.mojom") 958 parser.Parse(source3, "my_file.mojom")
959 959
960 def testValidImports(self): 960 def testValidImports(self):
961 """Tests parsing import statements.""" 961 """Tests parsing import statements."""
962 962
963 # One import (no module statement). 963 # One import (no module statement).
964 source1 = "import \"somedir/my.mojom\"" 964 source1 = "import \"somedir/my.mojom\";"
965 expected1 = ast.Mojom( 965 expected1 = ast.Mojom(
966 None, 966 None,
967 ast.ImportList(ast.Import("somedir/my.mojom")), 967 ast.ImportList(ast.Import("somedir/my.mojom")),
968 []) 968 [])
969 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1) 969 self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1)
970 970
971 # Two imports (no module statement). 971 # Two imports (no module statement).
972 source2 = """\ 972 source2 = """\
973 import "somedir/my1.mojom" 973 import "somedir/my1.mojom";
974 import "somedir/my2.mojom" 974 import "somedir/my2.mojom";
975 """ 975 """
976 expected2 = ast.Mojom( 976 expected2 = ast.Mojom(
977 None, 977 None,
978 ast.ImportList([ast.Import("somedir/my1.mojom"), 978 ast.ImportList([ast.Import("somedir/my1.mojom"),
979 ast.Import("somedir/my2.mojom")]), 979 ast.Import("somedir/my2.mojom")]),
980 []) 980 [])
981 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2) 981 self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2)
982 982
983 # Imports with module statement. 983 # Imports with module statement.
984 source3 = """\ 984 source3 = """\
985 import "somedir/my1.mojom" 985 import "somedir/my1.mojom";
986 import "somedir/my2.mojom" 986 import "somedir/my2.mojom";
987 module my_module {} 987 module my_module {}
988 """ 988 """
989 expected3 = ast.Mojom( 989 expected3 = ast.Mojom(
990 ast.Module(('IDENTIFIER', 'my_module'), None), 990 ast.Module(('IDENTIFIER', 'my_module'), None),
991 ast.ImportList([ast.Import("somedir/my1.mojom"), 991 ast.ImportList([ast.Import("somedir/my1.mojom"),
992 ast.Import("somedir/my2.mojom")]), 992 ast.Import("somedir/my2.mojom")]),
993 []) 993 [])
994 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3) 994 self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3)
995 995
996 def testInvalidImports(self): 996 def testInvalidImports(self):
(...skipping 12 matching lines...) Expand all
1009 source2 = """\ 1009 source2 = """\
1010 import // Missing string. 1010 import // Missing string.
1011 module {} 1011 module {}
1012 """ 1012 """
1013 with self.assertRaisesRegexp( 1013 with self.assertRaisesRegexp(
1014 parser.ParseError, 1014 parser.ParseError,
1015 r"^my_file\.mojom:2: Error: Unexpected 'module':\n" 1015 r"^my_file\.mojom:2: Error: Unexpected 'module':\n"
1016 r" *module {}$"): 1016 r" *module {}$"):
1017 parser.Parse(source2, "my_file.mojom") 1017 parser.Parse(source2, "my_file.mojom")
1018 1018
1019 source3 = """\
1020 import "foo.mojom" // Missing semicolon.
1021 module {}
1022 """
1023 with self.assertRaisesRegexp(
1024 parser.ParseError,
1025 r"^my_file\.mojom:2: Error: Unexpected 'module':\n"
1026 r" *module {}$"):
1027 parser.Parse(source3, "my_file.mojom")
1028
1019 def testValidNullableTypes(self): 1029 def testValidNullableTypes(self):
1020 """Tests parsing nullable types.""" 1030 """Tests parsing nullable types."""
1021 1031
1022 source = """\ 1032 source = """\
1023 struct MyStruct { 1033 struct MyStruct {
1024 int32? a; // This is actually invalid, but handled at a different 1034 int32? a; // This is actually invalid, but handled at a different
1025 // level. 1035 // level.
1026 string? b; 1036 string? b;
1027 array<int32> ? c; 1037 array<int32> ? c;
1028 array<string ? > ? d; 1038 array<string ? > ? d;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 }; 1103 };
1094 """ 1104 """
1095 with self.assertRaisesRegexp( 1105 with self.assertRaisesRegexp(
1096 parser.ParseError, 1106 parser.ParseError,
1097 r"^my_file\.mojom:2: Error: Unexpected '&':\n" 1107 r"^my_file\.mojom:2: Error: Unexpected '&':\n"
1098 r" *some_interface\?& a;$"): 1108 r" *some_interface\?& a;$"):
1099 parser.Parse(source3, "my_file.mojom") 1109 parser.Parse(source3, "my_file.mojom")
1100 1110
1101 if __name__ == "__main__": 1111 if __name__ == "__main__":
1102 unittest.main() 1112 unittest.main()
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/parser.py ('k') | mojo/services/public/cpp/native_viewport/args.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698