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

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

Issue 375993002: Mojo: Mojom: Make enum values only integers. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/translate.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/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 bc6b10ffb2a17d55a8fb75d70ccd416e350ff717..99d152346b5b9d1b4c8e948839ed440358d54c21 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
@@ -200,19 +200,21 @@ class ParserTest(unittest.TestCase):
r"^my_file\.mojom:4: Error: Unexpected '{':\n *{$"):
parser.Parse(source2, "my_file.mojom")
- def testEnumInitializers(self):
- """Tests an enum with simple initialized values."""
+ def testEnums(self):
+ """Tests that enum statements are correctly parsed."""
source = """\
module my_module {
-
- enum MyEnum {
- MY_ENUM_NEG1 = -1,
- MY_ENUM_ZERO = 0,
- MY_ENUM_1 = +1,
- MY_ENUM_2,
+ enum MyEnum1 { VALUE1, VALUE2 }; // No trailing comma.
+ enum MyEnum2 {
+ VALUE1 = -1,
+ VALUE2 = 0,
+ VALUE3 = + 987, // Check that space is allowed.
+ VALUE4 = 0xAF12,
+ VALUE5 = -0x09bcd,
+ VALUE6 = VALUE5,
+ VALUE7, // Leave trailing comma.
};
-
} // my_module
"""
expected = \
@@ -220,15 +222,52 @@ class ParserTest(unittest.TestCase):
'my_module',
None,
[('ENUM',
- 'MyEnum',
- [('ENUM_FIELD', 'MY_ENUM_NEG1', '-1'),
- ('ENUM_FIELD', 'MY_ENUM_ZERO', '0'),
- ('ENUM_FIELD', 'MY_ENUM_1', '+1'),
- ('ENUM_FIELD', 'MY_ENUM_2', None)])])]
+ 'MyEnum1',
+ [('ENUM_VALUE', 'VALUE1', None),
+ ('ENUM_VALUE', 'VALUE2', None)]),
+ ('ENUM',
+ 'MyEnum2',
+ [('ENUM_VALUE', 'VALUE1', '-1'),
+ ('ENUM_VALUE', 'VALUE2', '0'),
+ ('ENUM_VALUE', 'VALUE3', '+987'),
+ ('ENUM_VALUE', 'VALUE4', '0xAF12'),
+ ('ENUM_VALUE', 'VALUE5', '-0x09bcd'),
+ ('ENUM_VALUE', 'VALUE6', ('IDENTIFIER', 'VALUE5')),
+ ('ENUM_VALUE', 'VALUE7', None)])])]
self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
- def testConst(self):
- """Tests some constants and struct memebers initialized with them."""
+ def testInvalidEnumInitializers(self):
+ """Tests that invalid enum initializers are correctly detected."""
+
+ # No values.
+ source1 = """\
+ enum MyEnum {
+ };
+ """
+ with self.assertRaisesRegexp(
+ parser.ParseError,
+ r"^my_file\.mojom:2: Error: Unexpected '}':\n"
+ r" *};$"):
+ parser.Parse(source1, "my_file.mojom")
+
+ # Floating point value.
+ source2 = "enum MyEnum { VALUE = 0.123 };"
+ with self.assertRaisesRegexp(
+ parser.ParseError,
+ r"^my_file\.mojom:1: Error: Unexpected '0\.123':\n"
+ r"enum MyEnum { VALUE = 0\.123 };$"):
+ parser.Parse(source2, "my_file.mojom")
+
+ # Boolean value.
+ source2 = "enum MyEnum { VALUE = true };"
+ with self.assertRaisesRegexp(
+ parser.ParseError,
+ r"^my_file\.mojom:1: Error: Unexpected 'true':\n"
+ r"enum MyEnum { VALUE = true };$"):
+ parser.Parse(source2, "my_file.mojom")
+
+ def testConsts(self):
+ """Tests some constants and struct members initialized with them."""
source = """\
module my_module {
@@ -248,7 +287,7 @@ class ParserTest(unittest.TestCase):
'MyStruct', None,
[('CONST', 'int8', 'kNumber', '-1'),
('FIELD', 'int8', 'number',
- ast.Ordinal(0), ('IDENTIFIER', 'kNumber'))])])]
+ ast.Ordinal(0), ('IDENTIFIER', 'kNumber'))])])]
self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
def testNoConditionals(self):
« 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