Chromium Code Reviews| 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 && ! $unchecked || $mode == release "); | |
| 83 Expect.equals( | |
| 84 r"((($arch == ia32) && (bool ! $unchecked)) || ($mode == release))", | |
| 85 expression.toString()); | |
| 86 | |
| 87 var environment = <String, dynamic>{ | |
|
Bob Nystrom
2017/06/01 23:07:46
This map needs to be wrapped in new TestEnvironmen
Lasse Reichstein Nielsen
2017/06/07 08:51:48
Done.
| |
| 88 "arch": "ia32", | |
| 89 "unchecked": false, | |
|
Bob Nystrom
2017/06/01 23:07:45
Nit: Would you mind using "checked" for this?
It
Lasse Reichstein Nielsen
2017/06/07 08:51:48
Sure. This was just the "minimal diff" from the te
| |
| 90 "mode": "debug" | |
| 91 }; | |
| 92 | |
| 93 Expect.isTrue(expression.evaluate(environment)); | |
| 94 environment["mode"] = "release"; | |
| 95 Expect.isTrue(expression.evaluate(environment)); | |
| 96 environment["unchecked"] = true; | |
|
Bob Nystrom
2017/06/01 23:07:45
"true" and "false" need to be explicitly stringifi
Lasse Reichstein Nielsen
2017/06/07 08:51:48
Done.
| |
| 97 Expect.isTrue(expression.evaluate(environment)); | |
| 98 environment["mode"] = "debug"; | |
| 99 Expect.isFalse(expression.evaluate(environment)); | |
| 100 environment["arch"] = "arm"; | |
| 101 Expect.isFalse(expression.evaluate(environment)); | |
| 102 environment["unchecked"] = false; | |
| 103 Expect.isFalse(expression.evaluate(environment)); | |
| 104 } | |
| 105 | |
| 79 void testNotEqual() { | 106 void testNotEqual() { |
| 80 // Test the != operator. | 107 // Test the != operator. |
| 81 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); | 108 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); |
| 82 Expect.equals( | 109 Expect.equals( |
| 83 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString()); | 110 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString()); |
| 84 | 111 |
| 85 // Test BooleanExpression.evaluate(). | 112 // Test BooleanExpression.evaluate(). |
| 86 var environment = new TestEnvironment({ | 113 var environment = new TestEnvironment({ |
| 87 "compiler": "none", | 114 "compiler": "none", |
| 88 "runtime": "ie9", | 115 "runtime": "ie9", |
| 89 }); | 116 }); |
| 90 | 117 |
| 91 Expect.isFalse(expression.evaluate(environment)); | 118 Expect.isFalse(expression.evaluate(environment)); |
| 92 environment["runtime"] = "chrome"; | 119 environment["runtime"] = "chrome"; |
| 93 Expect.isFalse(expression.evaluate(environment)); | 120 Expect.isFalse(expression.evaluate(environment)); |
| 94 | 121 |
| 95 environment["compiler"] = "dart2js"; | 122 environment["compiler"] = "dart2js"; |
| 96 environment["runtime"] = "ie9"; | 123 environment["runtime"] = "ie9"; |
| 97 Expect.isFalse(expression.evaluate(environment)); | 124 Expect.isFalse(expression.evaluate(environment)); |
| 98 environment["runtime"] = "chrome"; | 125 environment["runtime"] = "chrome"; |
| 99 Expect.isTrue(expression.evaluate(environment)); | 126 Expect.isTrue(expression.evaluate(environment)); |
| 100 } | 127 } |
| OLD | NEW |