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

Side by Side Diff: mojo/public/bindings/pylib/parse/mojo_parser_unittest.py

Issue 213693004: Mojo: Mojom: Remove relational (e.g., !=) and logical operators (e.g., || and !). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/pylib/parse/mojo_parser.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 mojo_lexer 5 import mojo_lexer
6 import mojo_parser 6 import mojo_parser
7 import unittest 7 import unittest
8 8
9 9
10 class MojoParserTest(unittest.TestCase): 10 class MojoParserTest(unittest.TestCase):
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 def testEnumExpressions(self): 65 def testEnumExpressions(self):
66 """Tests an enum with values calculated using simple expressions.""" 66 """Tests an enum with values calculated using simple expressions."""
67 source = """\ 67 source = """\
68 module my_module { 68 module my_module {
69 69
70 enum MyEnum { 70 enum MyEnum {
71 MY_ENUM_1 = 1, 71 MY_ENUM_1 = 1,
72 MY_ENUM_2 = 1 + 1, 72 MY_ENUM_2 = 1 + 1,
73 MY_ENUM_3 = 1 * 3, 73 MY_ENUM_3 = 1 * 3,
74 MY_ENUM_4 = 2 * (1 + 1), 74 MY_ENUM_4 = 2 * (1 + 1),
75 MY_ENUM_5 = 1 + 2 * 2 75 MY_ENUM_5 = 1 + 2 * 2,
76 MY_ENUM_6 = -6 / -2,
77 MY_ENUM_7 = 3 | (1 << 2),
78 MY_ENUM_8 = 16 >> 1,
79 MY_ENUM_9 = 1 ^ 15 & 8,
80 MY_ENUM_10 = 110 % 100,
81 MY_ENUM_MINUS_1 = ~0
76 }; 82 };
77 83
78 } // my_module 84 } // my_module
79 """ 85 """
86 self.maxDiff = 2000
80 expected = \ 87 expected = \
81 [('MODULE', 88 [('MODULE',
82 'my_module', 89 'my_module',
83 [('ENUM', 90 [('ENUM',
84 'MyEnum', 91 'MyEnum',
85 [('ENUM_FIELD', 'MY_ENUM_1', ('EXPRESSION', ['1'])), 92 [('ENUM_FIELD', 'MY_ENUM_1', ('EXPRESSION', ['1'])),
86 ('ENUM_FIELD', 'MY_ENUM_2', ('EXPRESSION', ['1', '+', '1'])), 93 ('ENUM_FIELD', 'MY_ENUM_2', ('EXPRESSION', ['1', '+', '1'])),
87 ('ENUM_FIELD', 'MY_ENUM_3', ('EXPRESSION', ['1', '*', '3'])), 94 ('ENUM_FIELD', 'MY_ENUM_3', ('EXPRESSION', ['1', '*', '3'])),
88 ('ENUM_FIELD', 95 ('ENUM_FIELD',
89 'MY_ENUM_4', 96 'MY_ENUM_4',
90 ('EXPRESSION', 97 ('EXPRESSION',
91 ['2', '*', '(', ('EXPRESSION', ['1', '+', '1']), ')'])), 98 ['2', '*', '(', ('EXPRESSION', ['1', '+', '1']), ')'])),
92 ('ENUM_FIELD', 99 ('ENUM_FIELD',
93 'MY_ENUM_5', 100 'MY_ENUM_5',
94 ('EXPRESSION', ['1', '+', '2', '*', '2']))])])] 101 ('EXPRESSION', ['1', '+', '2', '*', '2'])),
102 ('ENUM_FIELD',
103 'MY_ENUM_6',
104 ('EXPRESSION',
105 ['-', ('EXPRESSION', ['6', '/', '-', ('EXPRESSION', ['2'])])])),
106 ('ENUM_FIELD',
107 'MY_ENUM_7',
108 ('EXPRESSION',
109 ['3', '|', '(', ('EXPRESSION', ['1', '<<', '2']), ')'])),
110 ('ENUM_FIELD', 'MY_ENUM_8', ('EXPRESSION', ['16', '>>', '1'])),
111 ('ENUM_FIELD',
112 'MY_ENUM_9',
113 ('EXPRESSION', ['1', '^', '15', '&', '8'])),
114 ('ENUM_FIELD', 'MY_ENUM_10', ('EXPRESSION', ['110', '%', '100'])),
115 ('ENUM_FIELD',
116 'MY_ENUM_MINUS_1',
117 ('EXPRESSION', ['~', ('EXPRESSION', ['0'])]))])])]
95 self.assertEquals(mojo_parser.Parse(source, "my_file.mojom"), expected) 118 self.assertEquals(mojo_parser.Parse(source, "my_file.mojom"), expected)
96 119
97 def testNoConditionals(self): 120 def testNoConditionals(self):
98 """Tests that ?: is not allowed.""" 121 """Tests that ?: is not allowed."""
99 source = """\ 122 source = """\
100 module my_module { 123 module my_module {
101 124
102 enum MyEnum { 125 enum MyEnum {
103 MY_ENUM_1 = 1 ? 2 : 3 126 MY_ENUM_1 = 1 ? 2 : 3
104 }; 127 };
105 128
106 } // my_module 129 } // my_module
107 """ 130 """
108 with self.assertRaisesRegexp( 131 with self.assertRaisesRegexp(
109 mojo_lexer.LexError, 132 mojo_lexer.LexError,
110 r"^my_file\.mojom:4: Error: Illegal character '\?'$"): 133 r"^my_file\.mojom:4: Error: Illegal character '\?'$"):
111 mojo_parser.Parse(source, "my_file.mojom") 134 mojo_parser.Parse(source, "my_file.mojom")
112 135
113 136
114 if __name__ == "__main__": 137 if __name__ == "__main__":
115 unittest.main() 138 unittest.main()
OLDNEW
« no previous file with comments | « mojo/public/bindings/pylib/parse/mojo_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698