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

Unified Diff: test/browser/minitest.dart

Issue 1200233004: fixes #168, dart:js implementation with a test (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: fix error (window not defined) Created 5 years, 6 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 | « test/browser/js_test.html ('k') | test/browser/runtime_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser/minitest.dart
diff --git a/test/browser/minitest.dart b/test/browser/minitest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..96f0b2fa8c1a89328516a9ebe4ba25eec87f996d
--- /dev/null
+++ b/test/browser/minitest.dart
@@ -0,0 +1,79 @@
+// Copyright (c) 2015, 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.
+
+// TODO(jmesserly): replace this with the real package:test.
+// Not possible yet because it uses on async/await which we don't support.
+library minitest;
+
+import 'dom.dart';
+
+final console = (window as dynamic).console;
+
+void group(String name, void body()) {
+ console.group(name);
+ body();
+ console.groupEnd(name);
+}
+
+void test(String name, void body(), {String skip}) {
+ if (skip != null) {
+ console.warn('SKIP $name: $skip');
+ return;
+ }
+ console.log(name);
+ try {
+ body();
+ } catch(e) {
+ console.error(e);
+ }
+}
+
+void expect(Object actual, matcher) {
+ if (matcher is! Matcher) matcher = equals(matcher);
+ if (!matcher(actual)) {
+ throw 'Expect failed to match $actual with $matcher';
+ }
+}
+
+Matcher equals(Object expected) {
+ return (actual) {
+ if (expected is List && actual is List) {
+ int len = expected.length;
+ if (len != actual.length) return false;
+ for (int i = 0; i < len; i++) {
+ if (!equals(expected[i])(actual[i])) return false;
+ }
+ return true;
+ } else {
+ return expected == actual;
+ }
+ };
+}
+
+Matcher same(Object expected) => (actual) => identical(expected, actual);
+Matcher isNot(matcher) {
+ if (matcher is! Matcher) matcher = equals(matcher);
+ return (actual) => !matcher(actual);
+}
+
+bool isNull(actual) => actual == null;
+final Matcher isNotNull = isNot(isNull);
+bool isRangeError(actual) => actual is RangeError;
+bool isNoSuchMethodError(actual) => actual is NoSuchMethodError;
+
+Matcher throwsA(matcher) {
+ if (matcher is! Matcher) matcher = equals(matcher);
+ return (actual) {
+ try {
+ actual();
+ return false;
+ } catch(e) {
+ return matcher(e);
+ }
+ };
+}
+
+final Matcher throws = throwsA((a) => true);
+
+typedef Matcher(actual);
« no previous file with comments | « test/browser/js_test.html ('k') | test/browser/runtime_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698