Index: mojo/public/bindings/pylib/parse/mojo_parser_unittest.py |
diff --git a/mojo/public/bindings/pylib/parse/mojo_parser_unittest.py b/mojo/public/bindings/pylib/parse/mojo_parser_unittest.py |
index d9f13d10dde10a9e1c3544a3494e1533b775d8b6..d9d8c0c63f2565a666db18feb5c654627be6b037 100644 |
--- a/mojo/public/bindings/pylib/parse/mojo_parser_unittest.py |
+++ b/mojo/public/bindings/pylib/parse/mojo_parser_unittest.py |
@@ -83,7 +83,6 @@ enum MyEnum { |
} // my_module |
""" |
- self.maxDiff = 2000 |
expected = \ |
[('MODULE', |
'my_module', |
@@ -133,6 +132,99 @@ enum MyEnum { |
r"^my_file\.mojom:4: Error: Illegal character '\?'$"): |
mojo_parser.Parse(source, "my_file.mojom") |
+ def testSimpleOrdinals(self): |
+ """Tests that (valid) ordinal values are scanned correctly.""" |
+ source = """\ |
+module my_module { |
+ |
+// This isn't actually valid .mojom, but the problem (missing ordinals) should |
+// be handled at a different level. |
+struct MyStruct { |
+ int32 a0 @0; |
+ int32 a1 @1; |
+ int32 a2 @2; |
+ int32 a9 @9; |
+ int32 a10 @10; |
+ int32 a11 @11; |
+ int32 a29 @29; |
+ int32 a1234567890 @1234567890; |
+}; |
+ |
+} // module my_module |
+""" |
+ expected = \ |
+[('MODULE', |
+ 'my_module', |
+ [('STRUCT', |
+ 'MyStruct', |
+ None, |
+ [('FIELD', 'int32', 'a0', '@0', None), |
+ ('FIELD', 'int32', 'a1', '@1', None), |
+ ('FIELD', 'int32', 'a2', '@2', None), |
+ ('FIELD', 'int32', 'a9', '@9', None), |
+ ('FIELD', 'int32', 'a10', '@10', None), |
+ ('FIELD', 'int32', 'a11', '@11', None), |
+ ('FIELD', 'int32', 'a29', '@29', None), |
+ ('FIELD', 'int32', 'a1234567890', '@1234567890', None)])])] |
+ self.assertEquals(mojo_parser.Parse(source, "my_file.mojom"), expected) |
+ |
+ def testInvalidOrdinals(self): |
+ """Tests that (lexically) invalid ordinals are correctly detected.""" |
+ source1 = """\ |
+module my_module { |
+ |
+struct MyStruct { |
+ int32 a_missing @; |
+}; |
+ |
+} // module my_module |
+""" |
+ with self.assertRaisesRegexp( |
+ mojo_lexer.LexError, |
+ r"^my_file\.mojom:4: Error: Missing ordinal value$"): |
+ mojo_parser.Parse(source1, "my_file.mojom") |
+ |
+ source2 = """\ |
+module my_module { |
+ |
+struct MyStruct { |
+ int32 a_octal @01; |
+}; |
+ |
+} // module my_module |
+""" |
+ with self.assertRaisesRegexp( |
+ mojo_lexer.LexError, |
+ r"^my_file\.mojom:4: Error: " |
+ r"Octal and hexadecimal ordinal values not allowed$"): |
+ mojo_parser.Parse(source2, "my_file.mojom") |
+ |
+ source3 = """\ |
+module my_module { struct MyStruct { int32 a_invalid_octal @08; }; } |
+""" |
+ with self.assertRaisesRegexp( |
+ mojo_lexer.LexError, |
+ r"^my_file\.mojom:1: Error: " |
+ r"Octal and hexadecimal ordinal values not allowed$"): |
+ mojo_parser.Parse(source3, "my_file.mojom") |
+ |
+ source4 = """\ |
+module my_module { struct MyStruct { int32 a_hex @0x1aB9; }; } |
+""" |
+ with self.assertRaisesRegexp( |
+ mojo_lexer.LexError, |
+ r"^my_file\.mojom:1: Error: " |
+ r"Octal and hexadecimal ordinal values not allowed$"): |
+ mojo_parser.Parse(source4, "my_file.mojom") |
+ |
+ source5 = """\ |
+module my_module { struct MyStruct { int32 a_hex @0X0; }; } |
+""" |
+ with self.assertRaisesRegexp( |
+ mojo_lexer.LexError, |
+ r"^my_file\.mojom:1: Error: " |
+ r"Octal and hexadecimal ordinal values not allowed$"): |
+ mojo_parser.Parse(source5, "my_file.mojom") |
if __name__ == "__main__": |
unittest.main() |