| Index: tests/standalone/status_expression_test.dart
|
| diff --git a/tests/standalone/status_expression_test.dart b/tests/standalone/status_expression_test.dart
|
| index 4f7949500e5a89ed2d3b77589b21be819b4e1d03..870670674ad5f7984f993eb63e555bb88962b311 100644
|
| --- a/tests/standalone/status_expression_test.dart
|
| +++ b/tests/standalone/status_expression_test.dart
|
| @@ -7,202 +7,86 @@ library StatusExpressionTest;
|
| import "package:expect/expect.dart";
|
| import "../../tools/testing/dart/status_expression.dart";
|
|
|
| -class StatusExpressionTest {
|
| - static void testMain() {
|
| - test1();
|
| - test2();
|
| - test3();
|
| - test4();
|
| - test5();
|
| - test6();
|
| - test7();
|
| - }
|
| -
|
| - static void test1() {
|
| - Tokenizer tokenizer = new Tokenizer(
|
| - r" $mode == debug && ($arch == chromium || $arch == dartc) ");
|
| - tokenizer.tokenize();
|
| - Expect.listEquals(tokenizer.tokens, [
|
| - "\$",
|
| - "mode",
|
| - "==",
|
| - "debug",
|
| - "&&",
|
| - "(",
|
| - "\$",
|
| - "arch",
|
| - "==",
|
| - "chromium",
|
| - "||",
|
| - "\$",
|
| - "arch",
|
| - "==",
|
| - "dartc",
|
| - ")"
|
| - ]);
|
| - ExpressionParser parser =
|
| - new ExpressionParser(new Scanner(tokenizer.tokens));
|
| - BooleanExpression ast = parser.parseBooleanExpression();
|
| - Expect.equals(
|
| - r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))",
|
| - ast.toString());
|
| - // Test BooleanExpression.evaluate().
|
| - Map environment = new Map();
|
| - environment["arch"] = "dartc";
|
| - environment["mode"] = "debug";
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - environment["mode"] = "release";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["arch"] = "ia32";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["mode"] = "debug";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["arch"] = "chromium";
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - }
|
| -
|
| - static void test2() {
|
| - Tokenizer tokenizer = new Tokenizer(
|
| - r"($arch == dartc || $arch == chromium) && $mode == release");
|
| - tokenizer.tokenize();
|
| - Expect.listEquals(tokenizer.tokens, [
|
| - "(",
|
| - "\$",
|
| - "arch",
|
| - "==",
|
| - "dartc",
|
| - "||",
|
| - "\$",
|
| - "arch",
|
| - "==",
|
| - "chromium",
|
| - ")",
|
| - "&&",
|
| - "\$",
|
| - "mode",
|
| - "==",
|
| - "release"
|
| - ]);
|
| - }
|
| -
|
| - static void test3() {
|
| - var thrown;
|
| - String input = r" $mode == debug && ($arch==chromium || *$arch == dartc)";
|
| - Tokenizer tokenizer = new Tokenizer(input);
|
| - try {
|
| - tokenizer.tokenize();
|
| - } on Exception catch (e) {
|
| - thrown = e;
|
| - }
|
| - Expect.equals(
|
| - "FormatException: Syntax error in '$input'", thrown.toString());
|
| - }
|
| -
|
| - static void test4() {
|
| - var thrown;
|
| - String input =
|
| - r"($arch == (-dartc || $arch == chromium) && $mode == release";
|
| - Tokenizer tokenizer = new Tokenizer(input);
|
| - try {
|
| - tokenizer.tokenize();
|
| - } on Exception catch (e) {
|
| - thrown = e;
|
| - }
|
| - Expect.equals(
|
| - "FormatException: Syntax error in '$input'", thrown.toString());
|
| - }
|
| -
|
| - static void test5() {
|
| - Tokenizer tokenizer =
|
| - new Tokenizer(r"Skip , Pass if $arch == dartc, Fail || Timeout if "
|
| - r"$arch == chromium && $mode == release");
|
| - tokenizer.tokenize();
|
| - ExpressionParser parser =
|
| - new ExpressionParser(new Scanner(tokenizer.tokens));
|
| - SetExpression ast = parser.parseSetExpression();
|
| - Expect.equals(
|
| - r"((skip || (pass if ($arch == dartc))) || ((fail || timeout) "
|
| - r"if (($arch == chromium) && ($mode == release))))",
|
| - ast.toString());
|
| -
|
| - // Test SetExpression.evaluate().
|
| - Map environment = new Map();
|
| - environment["arch"] = "ia32";
|
| - environment["checked"] = true;
|
| - environment["mode"] = "debug";
|
| - Set<String> result = ast.evaluate(environment);
|
| - Expect.setEquals(["skip"], result);
|
| -
|
| - environment["arch"] = "dartc";
|
| - result = ast.evaluate(environment);
|
| - Expect.setEquals(["skip", "pass"], result);
|
| -
|
| - environment["arch"] = "chromium";
|
| - result = ast.evaluate(environment);
|
| - Expect.setEquals(["skip"], result);
|
| -
|
| - environment["mode"] = "release";
|
| - result = ast.evaluate(environment);
|
| - Expect.setEquals(["skip", "fail", "timeout"], result);
|
| - }
|
| -
|
| - static void test6() {
|
| - Tokenizer tokenizer =
|
| - new Tokenizer(r" $arch == ia32 && $checked || $mode == release ");
|
| - tokenizer.tokenize();
|
| - ExpressionParser parser =
|
| - new ExpressionParser(new Scanner(tokenizer.tokens));
|
| - BooleanExpression ast = parser.parseBooleanExpression();
|
| - Expect.equals(
|
| - r"((($arch == ia32) && (bool $checked)) || ($mode == release))",
|
| - ast.toString());
|
| -
|
| - // Test BooleanExpression.evaluate().
|
| - Map environment = new Map();
|
| - environment["arch"] = "ia32";
|
| - environment["checked"] = true;
|
| - environment["mode"] = "debug";
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - environment["mode"] = "release";
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - environment["checked"] = false;
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - environment["mode"] = "debug";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["arch"] = "arm";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["checked"] = true;
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - }
|
| -
|
| - static void test7() {
|
| - // Test the != operator.
|
| - Tokenizer tokenizer =
|
| - new Tokenizer(r"$compiler == dart2js && $runtime != ie9");
|
| - tokenizer.tokenize();
|
| - ExpressionParser parser =
|
| - new ExpressionParser(new Scanner(tokenizer.tokens));
|
| - BooleanExpression ast = parser.parseBooleanExpression();
|
| - Expect.equals(
|
| - r"(($compiler == dart2js) && ($runtime != ie9))", ast.toString());
|
| +main() {
|
| + testExpression();
|
| + testSyntaxError();
|
| + testBoolean();
|
| + testNotEqual();
|
| +}
|
|
|
| - // Test BooleanExpression.evaluate().
|
| - Map environment = new Map();
|
| +void testExpression() {
|
| + var expression = Expression
|
| + .parse(r" $mode == debug && ($arch == chromium || $arch == dartc) ");
|
| + Expect.equals(
|
| + r"(($mode == debug) && (($arch == chromium) || ($arch == dartc)))",
|
| + expression.toString());
|
| +
|
| + // Test BooleanExpression.evaluate().
|
| + var environment = <String, dynamic>{"arch": "dartc", "mode": "debug"};
|
| +
|
| + Expect.isTrue(expression.evaluate(environment));
|
| + environment["mode"] = "release";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["arch"] = "ia32";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["mode"] = "debug";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["arch"] = "chromium";
|
| + Expect.isTrue(expression.evaluate(environment));
|
| +}
|
|
|
| - environment["compiler"] = "none";
|
| - environment["runtime"] = "ie9";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["runtime"] = "chrome";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| +void testSyntaxError() {
|
| + var input = r"($arch == (-dartc || $arch == chromium) && $mode == release";
|
| + Expect.throws(() {
|
| + Expression.parse(input);
|
| + }, (e) => e.toString() == "FormatException: Syntax error in '$input'");
|
| +}
|
|
|
| - environment["compiler"] = "dart2js";
|
| - environment["runtime"] = "ie9";
|
| - Expect.isFalse(ast.evaluate(environment));
|
| - environment["runtime"] = "chrome";
|
| - Expect.isTrue(ast.evaluate(environment));
|
| - }
|
| +void testBoolean() {
|
| + var expression =
|
| + Expression.parse(r" $arch == ia32 && $checked || $mode == release ");
|
| + Expect.equals(r"((($arch == ia32) && (bool $checked)) || ($mode == release))",
|
| + expression.toString());
|
| +
|
| + // Test BooleanExpression.evaluate().
|
| + var environment = <String, dynamic>{
|
| + "arch": "ia32",
|
| + "checked": true,
|
| + "mode": "debug"
|
| + };
|
| +
|
| + Expect.isTrue(expression.evaluate(environment));
|
| + environment["mode"] = "release";
|
| + Expect.isTrue(expression.evaluate(environment));
|
| + environment["checked"] = false;
|
| + Expect.isTrue(expression.evaluate(environment));
|
| + environment["mode"] = "debug";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["arch"] = "arm";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["checked"] = true;
|
| + Expect.isFalse(expression.evaluate(environment));
|
| }
|
|
|
| -main() {
|
| - StatusExpressionTest.testMain();
|
| +void testNotEqual() {
|
| + // Test the != operator.
|
| + var expression = Expression.parse(r"$compiler == dart2js && $runtime != ie9");
|
| + Expect.equals(
|
| + r"(($compiler == dart2js) && ($runtime != ie9))", expression.toString());
|
| +
|
| + // Test BooleanExpression.evaluate().
|
| + var environment = <String, dynamic>{
|
| + "compiler": "none",
|
| + "runtime": "ie9",
|
| + };
|
| +
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["runtime"] = "chrome";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| +
|
| + environment["compiler"] = "dart2js";
|
| + environment["runtime"] = "ie9";
|
| + Expect.isFalse(expression.evaluate(environment));
|
| + environment["runtime"] = "chrome";
|
| + Expect.isTrue(expression.evaluate(environment));
|
| }
|
|
|