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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/parser_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/evaluate_test.dart
diff --git a/test/evaluate_test.dart b/test/evaluate_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f7cc20868dfbdaabad20b49ea059ab7c9cd7caad
--- /dev/null
+++ b/test/evaluate_test.dart
@@ -0,0 +1,60 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:test/test.dart';
+
+import 'package:boolean_selector/boolean_selector.dart';
+
+void main() {
+ group("operator:", () {
+ test("conditional", () {
+ _expectEval("true ? true : false", true);
+ _expectEval("true ? false : true", false);
+ _expectEval("false ? true : false", false);
+ _expectEval("false ? false : true", true);
+ });
+
+ test("or", () {
+ _expectEval("true || true", true);
+ _expectEval("true || false", true);
+ _expectEval("false || true", true);
+ _expectEval("false || false", false);
+ });
+
+ test("and", () {
+ _expectEval("true && true", true);
+ _expectEval("true && false", false);
+ _expectEval("false && true", false);
+ _expectEval("false && false", false);
+ });
+
+ test("not", () {
+ _expectEval("!true", false);
+ _expectEval("!false", true);
+ });
+ });
+
+ test("with a semantics function", () {
+ _expectEval("foo", false, semantics: (variable) => variable.contains("a"));
+ _expectEval("bar", true, semantics: (variable) => variable.contains("a"));
+ _expectEval("baz", true, semantics: (variable) => variable.contains("a"));
+ });
+}
+
+/// Asserts that [expression] evaluates to [result] against [semantics].
+///
+/// By default, "true" is true and all other variables are "false".
+void _expectEval(String expression, bool result, {semantics}) {
+ var reason =
+ expect(_eval(expression, semantics: semantics), equals(result),
+ reason: 'Expected "$expression" to evaluate to $result.');
+}
+
+/// Returns the result of evaluating [expression] on [semantics].
+///
+/// By default, "true" is true and all other variables are "false".
+bool _eval(String expression, {semantics}) {
+ var selector = new BooleanSelector.parse(expression);
+ return selector.evaluate(semantics ?? ["true"]);
+}
« 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