Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: test/to_string_test.dart

Issue 1712793002: Add the content of the package. (Closed) Base URL: git@github.com:dart-lang/boolean_selector@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/scanner_test.dart ('k') | test/validate_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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
7 import 'package:boolean_selector/boolean_selector.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) =>
84 new BooleanSelector.parse(selector).toString();
OLDNEW
« no previous file with comments | « test/scanner_test.dart ('k') | test/validate_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698