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