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