OLD | NEW |
| (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 #library("StatusExpressionTest"); | |
6 | |
7 #import("../../../tools/testing/dart/status_expression.dart"); | |
8 | |
9 | |
10 class StatusExpressionTest { | |
11 static void testMain() { | |
12 test1(); | |
13 test2(); | |
14 test3(); | |
15 test4(); | |
16 test5(); | |
17 test6(); | |
18 } | |
19 | |
20 static void test1() { | |
21 Tokenizer tokenizer = new Tokenizer( | |
22 @" $mode == debug && ($arch == chromium || $arch == dartc) "); | |
23 tokenizer.tokenize(); | |
24 Expect.listEquals(tokenizer.tokens, | |
25 ["\$", "mode", "==", "debug", "&&", "(", "\$", "arch", "==", | |
26 "chromium", "||", "\$", "arch", "==", "dartc", ")"]); | |
27 ExpressionParser parser = | |
28 new ExpressionParser(new Scanner(tokenizer.tokens)); | |
29 BooleanExpression ast = parser.parseBooleanExpression(); | |
30 Expect.equals( | |
31 @"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))", | |
32 ast.toString()); | |
33 // Test BooleanExpression.evaluate(). | |
34 Map environment = new Map(); | |
35 environment["arch"] = "dartc"; | |
36 environment["mode"] = "debug"; | |
37 Expect.isTrue(ast.evaluate(environment)); | |
38 environment["mode"] = "release"; | |
39 Expect.isFalse(ast.evaluate(environment)); | |
40 environment["arch"] = "ia32"; | |
41 Expect.isFalse(ast.evaluate(environment)); | |
42 environment["mode"] = "debug"; | |
43 Expect.isFalse(ast.evaluate(environment)); | |
44 environment["arch"] = "chromium"; | |
45 Expect.isTrue(ast.evaluate(environment)); | |
46 } | |
47 | |
48 static void test2() { | |
49 Tokenizer tokenizer = new Tokenizer( | |
50 @"($arch == dartc || $arch == chromium) && $mode == release"); | |
51 tokenizer.tokenize(); | |
52 Expect.listEquals( | |
53 tokenizer.tokens, | |
54 ["(", "\$", "arch", "==", "dartc", "||", "\$", "arch", "==", | |
55 "chromium", ")", "&&", "\$", "mode", "==", "release"]); | |
56 } | |
57 | |
58 static void test3() { | |
59 var thrown; | |
60 String input = @" $mode == debug && ($arch==chromium || *$arch == dartc)"; | |
61 Tokenizer tokenizer = new Tokenizer(input); | |
62 try { | |
63 tokenizer.tokenize(); | |
64 } catch (Exception e) { | |
65 thrown = e; | |
66 } | |
67 Expect.equals("Syntax error in '$input'", thrown.toString()); | |
68 } | |
69 | |
70 static void test4() { | |
71 var thrown; | |
72 String input = | |
73 @"($arch == (-dartc || $arch == chromium) && $mode == release"; | |
74 Tokenizer tokenizer = new Tokenizer(input); | |
75 try { | |
76 tokenizer.tokenize(); | |
77 } catch (Exception e) { | |
78 thrown = e; | |
79 } | |
80 Expect.equals("Syntax error in '$input'", thrown.toString()); | |
81 } | |
82 | |
83 static void test5() { | |
84 Tokenizer tokenizer = new Tokenizer( | |
85 @"Skip , Pass if $arch == dartc, Fail || Timeout if " + | |
86 @"$arch == chromium && $mode == release"); | |
87 tokenizer.tokenize(); | |
88 ExpressionParser parser = | |
89 new ExpressionParser(new Scanner(tokenizer.tokens)); | |
90 SetExpression ast = parser.parseSetExpression(); | |
91 Expect.equals( | |
92 @"((skip || (pass if ($arch == dartc))) || ((fail || timeout) " + | |
93 @"if (($arch == chromium) && ($mode == release))))", | |
94 ast.toString()); | |
95 | |
96 // Test SetExpression.evaluate(). | |
97 Map environment = new Map(); | |
98 environment["arch"] = "ia32"; | |
99 environment["checked"] = true; | |
100 environment["mode"] = "debug"; | |
101 Set<String> result = ast.evaluate(environment); | |
102 Expect.setEquals(["skip"], result); | |
103 | |
104 environment["arch"] = "dartc"; | |
105 result = ast.evaluate(environment); | |
106 Expect.setEquals(["skip", "pass"], result); | |
107 | |
108 environment["arch"] = "chromium"; | |
109 result = ast.evaluate(environment); | |
110 Expect.setEquals(["skip"], result); | |
111 | |
112 environment["mode"] = "release"; | |
113 result = ast.evaluate(environment); | |
114 Expect.setEquals(["skip", "fail", "timeout"], result); | |
115 } | |
116 | |
117 static void test6() { | |
118 Tokenizer tokenizer = new Tokenizer( | |
119 @" $arch == ia32 && $checked || $mode == release "); | |
120 tokenizer.tokenize(); | |
121 ExpressionParser parser = | |
122 new ExpressionParser(new Scanner(tokenizer.tokens)); | |
123 BooleanExpression ast = parser.parseBooleanExpression(); | |
124 Expect.equals( | |
125 @"((($arch == ia32) && (bool $checked)) || ($mode == release))", | |
126 ast.toString()); | |
127 | |
128 // Test BooleanExpression.evaluate(). | |
129 Map environment = new Map(); | |
130 environment["arch"] = "ia32"; | |
131 environment["checked"] = true; | |
132 environment["mode"] = "debug"; | |
133 Expect.isTrue(ast.evaluate(environment)); | |
134 environment["mode"] = "release"; | |
135 Expect.isTrue(ast.evaluate(environment)); | |
136 environment["checked"] = false; | |
137 Expect.isTrue(ast.evaluate(environment)); | |
138 environment["mode"] = "debug"; | |
139 Expect.isFalse(ast.evaluate(environment)); | |
140 environment["arch"] = "arm"; | |
141 Expect.isFalse(ast.evaluate(environment)); | |
142 environment["checked"] = true; | |
143 Expect.isFalse(ast.evaluate(environment)); | |
144 } | |
145 } | |
146 | |
147 main() { | |
148 StatusExpressionTest.testMain(); | |
149 } | |
OLD | NEW |