OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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:unittest/unittest.dart'; |
| 6 import 'package:unittest/src/backend/platform_selector/ast.dart'; |
| 7 import 'package:unittest/src/backend/platform_selector/parser.dart'; |
| 8 |
| 9 void main() { |
| 10 group("toString() for", () { |
| 11 test("a variable is its name", () { |
| 12 _expectToString("foo"); |
| 13 _expectToString("a-b"); |
| 14 }); |
| 15 |
| 16 group("not", () { |
| 17 test("doesn't parenthesize a variable", () => _expectToString("!a")); |
| 18 test("doesn't parenthesize a nested not", () => _expectToString("!!a")); |
| 19 test("parenthesizes an or", () => _expectToString("!(a || b)")); |
| 20 test("parenthesizes an and", () => _expectToString("!(a && b)")); |
| 21 test("parenthesizes a condition", () => _expectToString("!(a ? b : c)")); |
| 22 }); |
| 23 |
| 24 group("or", () { |
| 25 test("doesn't parenthesize variables", () => _expectToString("a || b")); |
| 26 test("doesn't parenthesize nots", () => _expectToString("!a || !b")); |
| 27 |
| 28 test("doesn't parenthesize ors", () { |
| 29 _expectToString("a || b || c || d"); |
| 30 _expectToString("((a || b) || c) || d", "a || b || c || d"); |
| 31 }); |
| 32 |
| 33 test("parenthesizes ands", () => |
| 34 _expectToString("a && b || c && d", "(a && b) || (c && d)")); |
| 35 |
| 36 test("parenthesizes conditions", () => |
| 37 _expectToString("(a ? b : c) || (e ? f : g)")); |
| 38 }); |
| 39 |
| 40 group("and", () { |
| 41 test("doesn't parenthesize variables", () => _expectToString("a && b")); |
| 42 test("doesn't parenthesize nots", () => _expectToString("!a && !b")); |
| 43 |
| 44 test("parenthesizes ors", () => |
| 45 _expectToString("(a || b) && (c || d)", "(a || b) && (c || d)")); |
| 46 |
| 47 test("doesn't parenthesize ands", () { |
| 48 _expectToString("a && b && c && d"); |
| 49 _expectToString("((a && b) && c) && d", "a && b && c && d"); |
| 50 }); |
| 51 |
| 52 test("parenthesizes conditions", () => |
| 53 _expectToString("(a ? b : c) && (e ? f : g)")); |
| 54 }); |
| 55 |
| 56 group("conditional", () { |
| 57 test("doesn't parenthesize variables", () => |
| 58 _expectToString("a ? b : c")); |
| 59 |
| 60 test("doesn't parenthesize nots", () => _expectToString("!a ? !b : !c")); |
| 61 |
| 62 test("doesn't parenthesize ors", () => |
| 63 _expectToString("a || b ? c || d : e || f")); |
| 64 |
| 65 test("doesn't parenthesize ands", () => |
| 66 _expectToString("a && b ? c && d : e && f")); |
| 67 |
| 68 test("parenthesizes non-trailing conditions", () { |
| 69 _expectToString("(a ? b : c) ? (e ? f : g) : h ? i : j"); |
| 70 _expectToString("(a ? b : c) ? (e ? f : g) : (h ? i : j)", |
| 71 "(a ? b : c) ? (e ? f : g) : h ? i : j"); |
| 72 }); |
| 73 }); |
| 74 }); |
| 75 } |
| 76 |
| 77 void _expectToString(String selector, [String result]) { |
| 78 if (result == null) result = selector; |
| 79 expect(_toString(selector), equals(result), |
| 80 reason: 'Expected toString of "$selector" to be "$result".'); |
| 81 } |
| 82 |
| 83 String _toString(String selector) => new Parser(selector).parse().toString(); |
OLD | NEW |