OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library StatusExpressionTest; | 5 library StatusExpressionTest; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import "../../tools/testing/dart/status_expression.dart"; | 8 import "../../tools/testing/dart/status_expression.dart"; |
9 | 9 |
10 | |
11 class StatusExpressionTest { | 10 class StatusExpressionTest { |
12 static void testMain() { | 11 static void testMain() { |
13 test1(); | 12 test1(); |
14 test2(); | 13 test2(); |
15 test3(); | 14 test3(); |
16 test4(); | 15 test4(); |
17 test5(); | 16 test5(); |
18 test6(); | 17 test6(); |
19 test7(); | 18 test7(); |
20 } | 19 } |
21 | 20 |
22 static void test1() { | 21 static void test1() { |
23 Tokenizer tokenizer = new Tokenizer( | 22 Tokenizer tokenizer = new Tokenizer( |
24 r" $mode == debug && ($arch == chromium || $arch == dartc) "); | 23 r" $mode == debug && ($arch == chromium || $arch == dartc) "); |
25 tokenizer.tokenize(); | 24 tokenizer.tokenize(); |
26 Expect.listEquals(tokenizer.tokens, | 25 Expect.listEquals(tokenizer.tokens, [ |
27 ["\$", "mode", "==", "debug", "&&", "(", "\$", "arch", "==", | 26 "\$", |
28 "chromium", "||", "\$", "arch", "==", "dartc", ")"]); | 27 "mode", |
| 28 "==", |
| 29 "debug", |
| 30 "&&", |
| 31 "(", |
| 32 "\$", |
| 33 "arch", |
| 34 "==", |
| 35 "chromium", |
| 36 "||", |
| 37 "\$", |
| 38 "arch", |
| 39 "==", |
| 40 "dartc", |
| 41 ")" |
| 42 ]); |
29 ExpressionParser parser = | 43 ExpressionParser parser = |
30 new ExpressionParser(new Scanner(tokenizer.tokens)); | 44 new ExpressionParser(new Scanner(tokenizer.tokens)); |
31 BooleanExpression ast = parser.parseBooleanExpression(); | 45 BooleanExpression ast = parser.parseBooleanExpression(); |
32 Expect.equals( | 46 Expect.equals( |
33 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", | 47 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", |
34 ast.toString()); | 48 ast.toString()); |
35 // Test BooleanExpression.evaluate(). | 49 // Test BooleanExpression.evaluate(). |
36 Map environment = new Map(); | 50 Map environment = new Map(); |
37 environment["arch"] = "dartc"; | 51 environment["arch"] = "dartc"; |
38 environment["mode"] = "debug"; | 52 environment["mode"] = "debug"; |
39 Expect.isTrue(ast.evaluate(environment)); | 53 Expect.isTrue(ast.evaluate(environment)); |
40 environment["mode"] = "release"; | 54 environment["mode"] = "release"; |
41 Expect.isFalse(ast.evaluate(environment)); | 55 Expect.isFalse(ast.evaluate(environment)); |
42 environment["arch"] = "ia32"; | 56 environment["arch"] = "ia32"; |
43 Expect.isFalse(ast.evaluate(environment)); | 57 Expect.isFalse(ast.evaluate(environment)); |
44 environment["mode"] = "debug"; | 58 environment["mode"] = "debug"; |
45 Expect.isFalse(ast.evaluate(environment)); | 59 Expect.isFalse(ast.evaluate(environment)); |
46 environment["arch"] = "chromium"; | 60 environment["arch"] = "chromium"; |
47 Expect.isTrue(ast.evaluate(environment)); | 61 Expect.isTrue(ast.evaluate(environment)); |
48 } | 62 } |
49 | 63 |
50 static void test2() { | 64 static void test2() { |
51 Tokenizer tokenizer = new Tokenizer( | 65 Tokenizer tokenizer = new Tokenizer( |
52 r"($arch == dartc || $arch == chromium) && $mode == release"); | 66 r"($arch == dartc || $arch == chromium) && $mode == release"); |
53 tokenizer.tokenize(); | 67 tokenizer.tokenize(); |
54 Expect.listEquals( | 68 Expect.listEquals(tokenizer.tokens, [ |
55 tokenizer.tokens, | 69 "(", |
56 ["(", "\$", "arch", "==", "dartc", "||", "\$", "arch", "==", | 70 "\$", |
57 "chromium", ")", "&&", "\$", "mode", "==", "release"]); | 71 "arch", |
| 72 "==", |
| 73 "dartc", |
| 74 "||", |
| 75 "\$", |
| 76 "arch", |
| 77 "==", |
| 78 "chromium", |
| 79 ")", |
| 80 "&&", |
| 81 "\$", |
| 82 "mode", |
| 83 "==", |
| 84 "release" |
| 85 ]); |
58 } | 86 } |
59 | 87 |
60 static void test3() { | 88 static void test3() { |
61 var thrown; | 89 var thrown; |
62 String input = r" $mode == debug && ($arch==chromium || *$arch == dartc)"; | 90 String input = r" $mode == debug && ($arch==chromium || *$arch == dartc)"; |
63 Tokenizer tokenizer = new Tokenizer(input); | 91 Tokenizer tokenizer = new Tokenizer(input); |
64 try { | 92 try { |
65 tokenizer.tokenize(); | 93 tokenizer.tokenize(); |
66 } on Exception catch (e) { | 94 } on Exception catch (e) { |
67 thrown = e; | 95 thrown = e; |
68 } | 96 } |
69 Expect.equals("FormatException: Syntax error in '$input'", | 97 Expect.equals( |
70 thrown.toString()); | 98 "FormatException: Syntax error in '$input'", thrown.toString()); |
71 } | 99 } |
72 | 100 |
73 static void test4() { | 101 static void test4() { |
74 var thrown; | 102 var thrown; |
75 String input = | 103 String input = |
76 r"($arch == (-dartc || $arch == chromium) && $mode == release"; | 104 r"($arch == (-dartc || $arch == chromium) && $mode == release"; |
77 Tokenizer tokenizer = new Tokenizer(input); | 105 Tokenizer tokenizer = new Tokenizer(input); |
78 try { | 106 try { |
79 tokenizer.tokenize(); | 107 tokenizer.tokenize(); |
80 } on Exception catch (e) { | 108 } on Exception catch (e) { |
81 thrown = e; | 109 thrown = e; |
82 } | 110 } |
83 Expect.equals("FormatException: Syntax error in '$input'", | 111 Expect.equals( |
84 thrown.toString()); | 112 "FormatException: Syntax error in '$input'", thrown.toString()); |
85 } | 113 } |
86 | 114 |
87 static void test5() { | 115 static void test5() { |
88 Tokenizer tokenizer = new Tokenizer( | 116 Tokenizer tokenizer = |
89 r"Skip , Pass if $arch == dartc, Fail || Timeout if " | 117 new Tokenizer(r"Skip , Pass if $arch == dartc, Fail || Timeout if " |
90 r"$arch == chromium && $mode == release"); | 118 r"$arch == chromium && $mode == release"); |
91 tokenizer.tokenize(); | 119 tokenizer.tokenize(); |
92 ExpressionParser parser = | 120 ExpressionParser parser = |
93 new ExpressionParser(new Scanner(tokenizer.tokens)); | 121 new ExpressionParser(new Scanner(tokenizer.tokens)); |
94 SetExpression ast = parser.parseSetExpression(); | 122 SetExpression ast = parser.parseSetExpression(); |
95 Expect.equals( | 123 Expect.equals( |
96 r"((skip || (pass if ($arch == dartc))) || ((fail || timeout) " | 124 r"((skip || (pass if ($arch == dartc))) || ((fail || timeout) " |
97 r"if (($arch == chromium) && ($mode == release))))", | 125 r"if (($arch == chromium) && ($mode == release))))", |
98 ast.toString()); | 126 ast.toString()); |
99 | 127 |
100 // Test SetExpression.evaluate(). | 128 // Test SetExpression.evaluate(). |
(...skipping 11 matching lines...) Expand all Loading... |
112 environment["arch"] = "chromium"; | 140 environment["arch"] = "chromium"; |
113 result = ast.evaluate(environment); | 141 result = ast.evaluate(environment); |
114 Expect.setEquals(["skip"], result); | 142 Expect.setEquals(["skip"], result); |
115 | 143 |
116 environment["mode"] = "release"; | 144 environment["mode"] = "release"; |
117 result = ast.evaluate(environment); | 145 result = ast.evaluate(environment); |
118 Expect.setEquals(["skip", "fail", "timeout"], result); | 146 Expect.setEquals(["skip", "fail", "timeout"], result); |
119 } | 147 } |
120 | 148 |
121 static void test6() { | 149 static void test6() { |
122 Tokenizer tokenizer = new Tokenizer( | 150 Tokenizer tokenizer = |
123 r" $arch == ia32 && $checked || $mode == release "); | 151 new Tokenizer(r" $arch == ia32 && $checked || $mode == release "); |
124 tokenizer.tokenize(); | 152 tokenizer.tokenize(); |
125 ExpressionParser parser = | 153 ExpressionParser parser = |
126 new ExpressionParser(new Scanner(tokenizer.tokens)); | 154 new ExpressionParser(new Scanner(tokenizer.tokens)); |
127 BooleanExpression ast = parser.parseBooleanExpression(); | 155 BooleanExpression ast = parser.parseBooleanExpression(); |
128 Expect.equals( | 156 Expect.equals( |
129 r"((($arch == ia32) && (bool $checked)) || ($mode == release))", | 157 r"((($arch == ia32) && (bool $checked)) || ($mode == release))", |
130 ast.toString()); | 158 ast.toString()); |
131 | 159 |
132 // Test BooleanExpression.evaluate(). | 160 // Test BooleanExpression.evaluate(). |
133 Map environment = new Map(); | 161 Map environment = new Map(); |
(...skipping 14 matching lines...) Expand all Loading... |
148 } | 176 } |
149 | 177 |
150 static void test7() { | 178 static void test7() { |
151 // Test the != operator. | 179 // Test the != operator. |
152 Tokenizer tokenizer = | 180 Tokenizer tokenizer = |
153 new Tokenizer(r"$compiler == dart2js && $runtime != ie9"); | 181 new Tokenizer(r"$compiler == dart2js && $runtime != ie9"); |
154 tokenizer.tokenize(); | 182 tokenizer.tokenize(); |
155 ExpressionParser parser = | 183 ExpressionParser parser = |
156 new ExpressionParser(new Scanner(tokenizer.tokens)); | 184 new ExpressionParser(new Scanner(tokenizer.tokens)); |
157 BooleanExpression ast = parser.parseBooleanExpression(); | 185 BooleanExpression ast = parser.parseBooleanExpression(); |
158 Expect.equals(r"(($compiler == dart2js) && ($runtime != ie9))", | 186 Expect.equals( |
159 ast.toString()); | 187 r"(($compiler == dart2js) && ($runtime != ie9))", ast.toString()); |
160 | 188 |
161 // Test BooleanExpression.evaluate(). | 189 // Test BooleanExpression.evaluate(). |
162 Map environment = new Map(); | 190 Map environment = new Map(); |
163 | 191 |
164 environment["compiler"] = "none"; | 192 environment["compiler"] = "none"; |
165 environment["runtime"] = "ie9"; | 193 environment["runtime"] = "ie9"; |
166 Expect.isFalse(ast.evaluate(environment)); | 194 Expect.isFalse(ast.evaluate(environment)); |
167 environment["runtime"] = "chrome"; | 195 environment["runtime"] = "chrome"; |
168 Expect.isFalse(ast.evaluate(environment)); | 196 Expect.isFalse(ast.evaluate(environment)); |
169 | 197 |
170 environment["compiler"] = "dart2js"; | 198 environment["compiler"] = "dart2js"; |
171 environment["runtime"] = "ie9"; | 199 environment["runtime"] = "ie9"; |
172 Expect.isFalse(ast.evaluate(environment)); | 200 Expect.isFalse(ast.evaluate(environment)); |
173 environment["runtime"] = "chrome"; | 201 environment["runtime"] = "chrome"; |
174 Expect.isTrue(ast.evaluate(environment)); | 202 Expect.isTrue(ast.evaluate(environment)); |
175 } | 203 } |
176 } | 204 } |
177 | 205 |
178 main() { | 206 main() { |
179 StatusExpressionTest.testMain(); | 207 StatusExpressionTest.testMain(); |
180 } | 208 } |
OLD | NEW |