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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 import "../../tools/testing/dart/environment.dart"; | 7 import "../../tools/testing/dart/environment.dart"; |
8 import "../../tools/testing/dart/status_expression.dart"; | 8 import "../../tools/testing/dart/status_expression.dart"; |
9 | 9 |
10 class TestEnvironment implements Environment { | 10 class TestEnvironment implements Environment { |
11 final Map<String, String> _values; | 11 final Map<String, String> _values; |
12 | 12 |
13 TestEnvironment(this._values); | 13 TestEnvironment(this._values); |
14 | 14 |
15 /// Looks up the value of the variable with [name]. | 15 /// Looks up the value of the variable with [name]. |
16 String lookUp(String name) => _values[name]; | 16 String lookUp(String name) => _values[name]; |
17 | 17 |
18 operator []=(String key, String value) => _values[key] = value; | 18 operator []=(String key, String value) => _values[key] = value; |
19 } | 19 } |
20 | 20 |
21 main() { | 21 main() { |
22 testExpression(); | 22 testExpression(); |
23 testSyntaxError(); | 23 testSyntaxError(); |
24 testBoolean(); | 24 testBoolean(); |
| 25 testNotBoolean(); |
25 testNotEqual(); | 26 testNotEqual(); |
26 } | 27 } |
27 | 28 |
28 void testExpression() { | 29 void testExpression() { |
29 var expression = Expression | 30 var expression = Expression |
30 .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) "); | 31 .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) "); |
31 Expect.equals( | 32 Expect.equals( |
32 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", | 33 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", |
33 expression.toString()); | 34 expression.toString()); |
34 | 35 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 environment["checked"] = "false"; | 70 environment["checked"] = "false"; |
70 Expect.isTrue(expression.evaluate(environment)); | 71 Expect.isTrue(expression.evaluate(environment)); |
71 environment["mode"] = "debug"; | 72 environment["mode"] = "debug"; |
72 Expect.isFalse(expression.evaluate(environment)); | 73 Expect.isFalse(expression.evaluate(environment)); |
73 environment["arch"] = "arm"; | 74 environment["arch"] = "arm"; |
74 Expect.isFalse(expression.evaluate(environment)); | 75 Expect.isFalse(expression.evaluate(environment)); |
75 environment["checked"] = "true"; | 76 environment["checked"] = "true"; |
76 Expect.isFalse(expression.evaluate(environment)); | 77 Expect.isFalse(expression.evaluate(environment)); |
77 } | 78 } |
78 | 79 |
| 80 void testNotBoolean() { |
| 81 var expression = |
| 82 Expression.parse(r" $arch == ia32 && ! $checked || $mode == release "); |
| 83 Expect.equals( |
| 84 r"((($arch == ia32) && (bool ! $checked)) || ($mode == release))", |
| 85 expression.toString()); |
| 86 |
| 87 var environment = new TestEnvironment( |
| 88 {"arch": "ia32", "checked": "false", "mode": "debug"}); |
| 89 |
| 90 Expect.isTrue(expression.evaluate(environment)); |
| 91 environment["mode"] = "release"; |
| 92 Expect.isTrue(expression.evaluate(environment)); |
| 93 environment["checked"] = "true"; |
| 94 Expect.isTrue(expression.evaluate(environment)); |
| 95 environment["mode"] = "debug"; |
| 96 Expect.isFalse(expression.evaluate(environment)); |
| 97 environment["arch"] = "arm"; |
| 98 Expect.isFalse(expression.evaluate(environment)); |
| 99 environment["checked"] = "false"; |
| 100 Expect.isFalse(expression.evaluate(environment)); |
| 101 } |
| 102 |
79 void testNotEqual() { | 103 void testNotEqual() { |
80 // Test the != operator. | 104 // Test the != operator. |
81 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); | 105 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); |
82 Expect.equals( | 106 Expect.equals( |
83 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString()); | 107 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString()); |
84 | 108 |
85 // Test BooleanExpression.evaluate(). | 109 // Test BooleanExpression.evaluate(). |
86 var environment = new TestEnvironment({ | 110 var environment = new TestEnvironment({ |
87 "compiler": "none", | 111 "compiler": "none", |
88 "runtime": "ie9", | 112 "runtime": "ie9", |
89 }); | 113 }); |
90 | 114 |
91 Expect.isFalse(expression.evaluate(environment)); | 115 Expect.isFalse(expression.evaluate(environment)); |
92 environment["runtime"] = "chrome"; | 116 environment["runtime"] = "chrome"; |
93 Expect.isFalse(expression.evaluate(environment)); | 117 Expect.isFalse(expression.evaluate(environment)); |
94 | 118 |
95 environment["compiler"] = "dart2js"; | 119 environment["compiler"] = "dart2js"; |
96 environment["runtime"] = "ie9"; | 120 environment["runtime"] = "ie9"; |
97 Expect.isFalse(expression.evaluate(environment)); | 121 Expect.isFalse(expression.evaluate(environment)); |
98 environment["runtime"] = "chrome"; | 122 environment["runtime"] = "chrome"; |
99 Expect.isTrue(expression.evaluate(environment)); | 123 Expect.isTrue(expression.evaluate(environment)); |
100 } | 124 } |
OLD | NEW |