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

Side by Side Diff: test/evaluate_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 | « pubspec.yaml ('k') | test/parser_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("operator:", () {
11 test("conditional", () {
12 _expectEval("true ? true : false", true);
13 _expectEval("true ? false : true", false);
14 _expectEval("false ? true : false", false);
15 _expectEval("false ? false : true", true);
16 });
17
18 test("or", () {
19 _expectEval("true || true", true);
20 _expectEval("true || false", true);
21 _expectEval("false || true", true);
22 _expectEval("false || false", false);
23 });
24
25 test("and", () {
26 _expectEval("true && true", true);
27 _expectEval("true && false", false);
28 _expectEval("false && true", false);
29 _expectEval("false && false", false);
30 });
31
32 test("not", () {
33 _expectEval("!true", false);
34 _expectEval("!false", true);
35 });
36 });
37
38 test("with a semantics function", () {
39 _expectEval("foo", false, semantics: (variable) => variable.contains("a"));
40 _expectEval("bar", true, semantics: (variable) => variable.contains("a"));
41 _expectEval("baz", true, semantics: (variable) => variable.contains("a"));
42 });
43 }
44
45 /// Asserts that [expression] evaluates to [result] against [semantics].
46 ///
47 /// By default, "true" is true and all other variables are "false".
48 void _expectEval(String expression, bool result, {semantics}) {
49 var reason =
50 expect(_eval(expression, semantics: semantics), equals(result),
51 reason: 'Expected "$expression" to evaluate to $result.');
52 }
53
54 /// Returns the result of evaluating [expression] on [semantics].
55 ///
56 /// By default, "true" is true and all other variables are "false".
57 bool _eval(String expression, {semantics}) {
58 var selector = new BooleanSelector.parse(expression);
59 return selector.evaluate(semantics ?? ["true"]);
60 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698