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

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

Issue 226983002: Mojo: Mojom: Test the parser when there's no module declared. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
« no previous file with comments | « mojo/public/tools/bindings/pylib/parse/mojo_parser.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py
diff --git a/mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py b/mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py
index 1c22ab93bed6dd6b111ed93feaa6d499f4015f89..cc49c46c3d6de83ace4914a87411a9f4a68754d4 100644
--- a/mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py
+++ b/mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py
@@ -41,7 +41,7 @@ module my_module {
def testSimpleStruct(self):
"""Tests a simple .mojom source that just defines a struct."""
- source ="""\
+ source = """\
module my_module {
struct MyStruct {
@@ -51,7 +51,6 @@ struct MyStruct {
} // module my_module
"""
- # Note: Output as pretty-printed on failure by the test harness.
expected = \
[('MODULE',
'my_module',
@@ -62,6 +61,53 @@ struct MyStruct {
('FIELD', 'double', 'b', None, None)])])]
self.assertEquals(mojo_parser.Parse(source, "my_file.mojom"), expected)
+ def testSimpleStructWithoutModule(self):
+ """Tests a simple struct without an enclosing module."""
+ source = """\
+struct MyStruct {
+ int32 a;
+ double b;
+};
+"""
+ expected = \
+[('MODULE',
+ '',
+ [('STRUCT',
+ 'MyStruct',
+ None,
+ [('FIELD', 'int32', 'a', None, None),
+ ('FIELD', 'double', 'b', None, None)])])]
+ self.assertEquals(mojo_parser.Parse(source, "my_file.mojom"), expected)
+
+ def testMissingModuleName(self):
+ """Tests an (invalid) .mojom with a missing module name."""
+ source1 = """\
+// Missing module name.
+module {
+struct MyStruct {
+ int32 a;
+};
+}
+"""
+ with self.assertRaisesRegexp(
+ mojo_parser.ParseError,
+ r"^my_file\.mojom:2: Error: Unexpected '{':\nmodule {$"):
+ mojo_parser.Parse(source1, "my_file.mojom")
+
+ # Another similar case, but make sure that line-number tracking/reporting
+ # is correct.
+ source2 = """\
+module
+// This line intentionally left unblank.
+
+{
+}
+"""
+ with self.assertRaisesRegexp(
+ mojo_parser.ParseError,
+ r"^my_file\.mojom:4: Error: Unexpected '{':\n{$"):
+ mojo_parser.Parse(source2, "my_file.mojom")
+
def testEnumExpressions(self):
"""Tests an enum with values calculated using simple expressions."""
source = """\
« no previous file with comments | « mojo/public/tools/bindings/pylib/parse/mojo_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698