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

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

Issue 611633002: mojom: Add associative arrays to the mojom language. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gn build. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
index 2fa172fb60c8248ae26d1ac6b0ca27b5ec9583f3..abfb8779547ea87d4e653a1bdff507a419e06c57 100644
--- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
+++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
@@ -672,16 +672,47 @@ class ParserTest(unittest.TestCase):
r" *int32\[999999999999\] too_big_array;$"):
parser.Parse(source2, "my_file.mojom")
- source3 = """\
- struct MyStruct {
- int32[abcdefg] not_a_number;
- };
- """
- with self.assertRaisesRegexp(
- parser.ParseError,
- r"^my_file\.mojom:2: Error: Unexpected 'abcdefg':\n"
- r" *int32\[abcdefg\] not_a_number;"):
- parser.Parse(source3, "my_file.mojom")
+ def testValidAssociativeArrays(self):
+ """Tests that we can parse valid associative array structures."""
+
+ source1 = "struct MyStruct { uint8[string] data; };"
+ expected1 = ast.Mojom(
+ None,
+ ast.ImportList(),
+ [ast.Struct(
+ 'MyStruct',
+ None,
+ ast.StructBody(
+ [ast.StructField('data', None, 'uint8{string}', None)]))])
+ self.assertEquals(parser.Parse(source1, "my_file.mojom"), expected1)
+
+ source2 = "interface MyInterface { MyMethod(uint8[string] a); };"
+ expected2 = ast.Mojom(
+ None,
+ ast.ImportList(),
+ [ast.Interface(
+ 'MyInterface',
+ None,
+ ast.InterfaceBody(
+ ast.Method(
+ 'MyMethod',
+ None,
+ ast.ParameterList(
+ ast.Parameter('a', None, 'uint8{string}')),
+ None)))])
+ self.assertEquals(parser.Parse(source2, "my_file.mojom"), expected2)
+
+ source3 = "struct MyStruct { uint8[string][] data; };"
+ expected3 = ast.Mojom(
+ None,
+ ast.ImportList(),
+ [ast.Struct(
+ 'MyStruct',
+ None,
+ ast.StructBody(
+ [ast.StructField('data', None, 'uint8{string}[]', None)]))])
+ self.assertEquals(parser.Parse(source3, "my_file.mojom"), expected3)
+
def testValidMethod(self):
"""Tests parsing method declarations."""

Powered by Google App Engine
This is Rietveld 408576698