OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 "package:status_file/environment.dart"; | 7 import "package:status_file/environment.dart"; |
8 import "package:status_file/src/expression.dart"; | 8 import "package:status_file/src/expression.dart"; |
9 | 9 |
10 class TestEnvironment implements Environment { | 10 class TestEnvironment implements Environment { |
(...skipping 15 matching lines...) Expand all Loading... |
26 testExpression(); | 26 testExpression(); |
27 testSyntaxError(); | 27 testSyntaxError(); |
28 testBoolean(); | 28 testBoolean(); |
29 testNotBoolean(); | 29 testNotBoolean(); |
30 testNotEqual(); | 30 testNotEqual(); |
31 } | 31 } |
32 | 32 |
33 void testExpression() { | 33 void testExpression() { |
34 var expression = Expression | 34 var expression = Expression |
35 .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) "); | 35 .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) "); |
36 Expect.equals( | 36 Expect.equals(r"$mode == debug && ($arch == chromium || $arch == dartc)", |
37 r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", | |
38 expression.toString()); | 37 expression.toString()); |
39 | 38 |
40 // Test BooleanExpression.evaluate(). | 39 // Test BooleanExpression.evaluate(). |
41 var environment = new TestEnvironment({"arch": "dartc", "mode": "debug"}); | 40 var environment = new TestEnvironment({"arch": "dartc", "mode": "debug"}); |
42 | 41 |
43 Expect.isTrue(expression.evaluate(environment)); | 42 Expect.isTrue(expression.evaluate(environment)); |
44 environment["mode"] = "release"; | 43 environment["mode"] = "release"; |
45 Expect.isFalse(expression.evaluate(environment)); | 44 Expect.isFalse(expression.evaluate(environment)); |
46 environment["arch"] = "ia32"; | 45 environment["arch"] = "ia32"; |
47 Expect.isFalse(expression.evaluate(environment)); | 46 Expect.isFalse(expression.evaluate(environment)); |
48 environment["mode"] = "debug"; | 47 environment["mode"] = "debug"; |
49 Expect.isFalse(expression.evaluate(environment)); | 48 Expect.isFalse(expression.evaluate(environment)); |
50 environment["arch"] = "chromium"; | 49 environment["arch"] = "chromium"; |
51 Expect.isTrue(expression.evaluate(environment)); | 50 Expect.isTrue(expression.evaluate(environment)); |
52 } | 51 } |
53 | 52 |
54 void testSyntaxError() { | 53 void testSyntaxError() { |
55 var input = r"($arch == (-dartc || $arch == chromium) && $mode == release"; | 54 var input = r"($arch == (-dartc || $arch == chromium) && $mode == release"; |
56 Expect.throws(() { | 55 Expect.throws(() { |
57 Expression.parse(input); | 56 Expression.parse(input); |
58 }, (e) => e.toString() == "FormatException: Syntax error in '$input'"); | 57 }, (e) => e.toString() == "FormatException: Syntax error in '$input'"); |
59 } | 58 } |
60 | 59 |
61 void testBoolean() { | 60 void testBoolean() { |
62 var expression = | 61 var expression = |
63 Expression.parse(r" $arch == ia32 && $checked || $mode == release "); | 62 Expression.parse(r" $arch == ia32 && $checked || $mode == release "); |
64 Expect.equals(r"((($arch == ia32) && (bool $checked)) || ($mode == release))", | 63 Expect.equals( |
65 expression.toString()); | 64 r"$arch == ia32 && $checked || $mode == release", expression.toString()); |
66 | 65 |
67 // Test BooleanExpression.evaluate(). | 66 // Test BooleanExpression.evaluate(). |
68 var environment = | 67 var environment = |
69 new TestEnvironment({"arch": "ia32", "checked": "true", "mode": "debug"}); | 68 new TestEnvironment({"arch": "ia32", "checked": "true", "mode": "debug"}); |
70 | 69 |
71 Expect.isTrue(expression.evaluate(environment)); | 70 Expect.isTrue(expression.evaluate(environment)); |
72 environment["mode"] = "release"; | 71 environment["mode"] = "release"; |
73 Expect.isTrue(expression.evaluate(environment)); | 72 Expect.isTrue(expression.evaluate(environment)); |
74 environment["checked"] = "false"; | 73 environment["checked"] = "false"; |
75 Expect.isTrue(expression.evaluate(environment)); | 74 Expect.isTrue(expression.evaluate(environment)); |
76 environment["mode"] = "debug"; | 75 environment["mode"] = "debug"; |
77 Expect.isFalse(expression.evaluate(environment)); | 76 Expect.isFalse(expression.evaluate(environment)); |
78 environment["arch"] = "arm"; | 77 environment["arch"] = "arm"; |
79 Expect.isFalse(expression.evaluate(environment)); | 78 Expect.isFalse(expression.evaluate(environment)); |
80 environment["checked"] = "true"; | 79 environment["checked"] = "true"; |
81 Expect.isFalse(expression.evaluate(environment)); | 80 Expect.isFalse(expression.evaluate(environment)); |
82 } | 81 } |
83 | 82 |
84 void testNotBoolean() { | 83 void testNotBoolean() { |
85 var expression = | 84 var expression = |
86 Expression.parse(r" $arch == ia32 && ! $checked || $mode == release "); | 85 Expression.parse(r" $arch == ia32 && ! $checked || $mode == release "); |
87 Expect.equals( | 86 Expect.equals( |
88 r"((($arch == ia32) && (bool ! $checked)) || ($mode == release))", | 87 r"$arch == ia32 && !$checked || $mode == release", expression.toString()); |
89 expression.toString()); | |
90 | 88 |
91 var environment = new TestEnvironment( | 89 var environment = new TestEnvironment( |
92 {"arch": "ia32", "checked": "false", "mode": "debug"}); | 90 {"arch": "ia32", "checked": "false", "mode": "debug"}); |
93 | 91 |
94 Expect.isTrue(expression.evaluate(environment)); | 92 Expect.isTrue(expression.evaluate(environment)); |
95 environment["mode"] = "release"; | 93 environment["mode"] = "release"; |
96 Expect.isTrue(expression.evaluate(environment)); | 94 Expect.isTrue(expression.evaluate(environment)); |
97 environment["checked"] = "true"; | 95 environment["checked"] = "true"; |
98 Expect.isTrue(expression.evaluate(environment)); | 96 Expect.isTrue(expression.evaluate(environment)); |
99 environment["mode"] = "debug"; | 97 environment["mode"] = "debug"; |
100 Expect.isFalse(expression.evaluate(environment)); | 98 Expect.isFalse(expression.evaluate(environment)); |
101 environment["arch"] = "arm"; | 99 environment["arch"] = "arm"; |
102 Expect.isFalse(expression.evaluate(environment)); | 100 Expect.isFalse(expression.evaluate(environment)); |
103 environment["checked"] = "false"; | 101 environment["checked"] = "false"; |
104 Expect.isFalse(expression.evaluate(environment)); | 102 Expect.isFalse(expression.evaluate(environment)); |
105 } | 103 } |
106 | 104 |
107 void testNotEqual() { | 105 void testNotEqual() { |
108 // Test the != operator. | 106 // Test the != operator. |
109 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); | 107 var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9"); |
110 Expect.equals( | 108 Expect.equals( |
111 r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString()); | 109 r"$compiler == dart2js && $runtime != ie9", expression.toString()); |
112 | 110 |
113 // Test BooleanExpression.evaluate(). | 111 // Test BooleanExpression.evaluate(). |
114 var environment = new TestEnvironment({ | 112 var environment = new TestEnvironment({ |
115 "compiler": "none", | 113 "compiler": "none", |
116 "runtime": "ie9", | 114 "runtime": "ie9", |
117 }); | 115 }); |
118 | 116 |
119 Expect.isFalse(expression.evaluate(environment)); | 117 Expect.isFalse(expression.evaluate(environment)); |
120 environment["runtime"] = "chrome"; | 118 environment["runtime"] = "chrome"; |
121 Expect.isFalse(expression.evaluate(environment)); | 119 Expect.isFalse(expression.evaluate(environment)); |
122 | 120 |
123 environment["compiler"] = "dart2js"; | 121 environment["compiler"] = "dart2js"; |
124 environment["runtime"] = "ie9"; | 122 environment["runtime"] = "ie9"; |
125 Expect.isFalse(expression.evaluate(environment)); | 123 Expect.isFalse(expression.evaluate(environment)); |
126 environment["runtime"] = "chrome"; | 124 environment["runtime"] = "chrome"; |
127 Expect.isTrue(expression.evaluate(environment)); | 125 Expect.isTrue(expression.evaluate(environment)); |
128 } | 126 } |
OLD | NEW |