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

Side by Side Diff: tests/standalone/status_expression_test.dart

Issue 2984203002: Move the status file parser into its own package. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « tests/standalone/standalone.status ('k') | tools/testing/dart/command.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:expect/expect.dart";
6
7 import "../../tools/testing/dart/environment.dart";
8 import "../../tools/testing/dart/status_expression.dart";
9
10 class TestEnvironment implements Environment {
11 final Map<String, String> _values;
12
13 TestEnvironment(this._values);
14
15 /// Looks up the value of the variable with [name].
16 String lookUp(String name) => _values[name];
17
18 operator []=(String key, String value) => _values[key] = value;
19 }
20
21 main() {
22 testExpression();
23 testSyntaxError();
24 testBoolean();
25 testNotBoolean();
26 testNotEqual();
27 }
28
29 void testExpression() {
30 var expression = Expression
31 .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) ");
32 Expect.equals(
33 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))",
34 expression.toString());
35
36 // Test BooleanExpression.evaluate().
37 var environment = new TestEnvironment({"arch": "dartc", "mode": "debug"});
38
39 Expect.isTrue(expression.evaluate(environment));
40 environment["mode"] = "release";
41 Expect.isFalse(expression.evaluate(environment));
42 environment["arch"] = "ia32";
43 Expect.isFalse(expression.evaluate(environment));
44 environment["mode"] = "debug";
45 Expect.isFalse(expression.evaluate(environment));
46 environment["arch"] = "chromium";
47 Expect.isTrue(expression.evaluate(environment));
48 }
49
50 void testSyntaxError() {
51 var input = r"($arch == (-dartc || $arch == chromium) && $mode == release";
52 Expect.throws(() {
53 Expression.parse(input);
54 }, (e) => e.toString() == "FormatException: Syntax error in '$input'");
55 }
56
57 void testBoolean() {
58 var expression =
59 Expression.parse(r" $arch == ia32 && $checked || $mode == release ");
60 Expect.equals(r"((($arch == ia32) && (bool $checked)) || ($mode == release))",
61 expression.toString());
62
63 // Test BooleanExpression.evaluate().
64 var environment =
65 new TestEnvironment({"arch": "ia32", "checked": "true", "mode": "debug"});
66
67 Expect.isTrue(expression.evaluate(environment));
68 environment["mode"] = "release";
69 Expect.isTrue(expression.evaluate(environment));
70 environment["checked"] = "false";
71 Expect.isTrue(expression.evaluate(environment));
72 environment["mode"] = "debug";
73 Expect.isFalse(expression.evaluate(environment));
74 environment["arch"] = "arm";
75 Expect.isFalse(expression.evaluate(environment));
76 environment["checked"] = "true";
77 Expect.isFalse(expression.evaluate(environment));
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
103 void testNotEqual() {
104 // Test the != operator.
105 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9");
106 Expect.equals(
107 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString());
108
109 // Test BooleanExpression.evaluate().
110 var environment = new TestEnvironment({
111 "compiler": "none",
112 "runtime": "ie9",
113 });
114
115 Expect.isFalse(expression.evaluate(environment));
116 environment["runtime"] = "chrome";
117 Expect.isFalse(expression.evaluate(environment));
118
119 environment["compiler"] = "dart2js";
120 environment["runtime"] = "ie9";
121 Expect.isFalse(expression.evaluate(environment));
122 environment["runtime"] = "chrome";
123 Expect.isTrue(expression.evaluate(environment));
124 }
OLDNEW
« no previous file with comments | « tests/standalone/standalone.status ('k') | tools/testing/dart/command.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698