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

Unified Diff: utils/tests/string_encoding/DUnit.dart

Issue 9233041: String encoding utility methods and tests for Unicode, UTF-8, -16 and -32. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates from initial review. Created 8 years, 11 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
Index: utils/tests/string_encoding/DUnit.dart
diff --git a/utils/tests/string_encoding/DUnit.dart b/utils/tests/string_encoding/DUnit.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7120ddc451f6ffc9f407a3a8a97d7a274dc812ac
--- /dev/null
+++ b/utils/tests/string_encoding/DUnit.dart
@@ -0,0 +1,117 @@
+#!/usr/bin/env dart
+// Copyright (c) 2011, 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.
+
+#library("DUnit");
+
+typedef void Test();
+typedef TestResult SynchTest();
+typedef Future<TestResult> AsynchTest();
+
+class TestSuite {
+ TestSuite() : _tests = <SynchTest>[];
+
+ void registerTestClass(TestClass tests) {
+ tests.registerTests(this);
+ }
+
+ void _registerTest(SynchTest test) {
+ _tests.add(test);
+ }
+
+ void run() {
+ reportResults(runTests());
+ }
+
+ List<TestResult> runTests() {
+ List<TestResult> results = <TestResult>[];
+ for(Function test in _tests) {
+ results.add(test());
+ }
+ return results;
+ }
+
+ void reportResults(List<TestResult> results) {
+ if(results.every(bool _(TestResult r) => r is PassedTest)) {
+ print("OK -- ALL TESTS PASS (${results.length} run)");
+ } else {
+ for(TestResult r in
+ results.filter(bool _(TestResult r) => !(r is PassedTest))) {
+ print(r);
+ }
+ int passedTests =
+ results.filter(bool _(TestResult r) => r is PassedTest).length;
+ int failures =
+ results.filter(bool _(TestResult r) => r is FailedTest).length;
+ int errors =
+ results.filter(bool _(TestResult r) => r is TestError).length;
+ print("FAIL -- TESTS RUN: ${results.length}");
+ print(" PASSED: ${passedTests}");
+ print(" FAILED: ${failures}");
+ print(" ERRORS: ${errors}");
+ }
+ }
+
+ List<SynchTest> _tests;
+}
+
+interface TestResult {
+ String get testDescription();
+}
+
+class PassedTest implements TestResult {
+ const PassedTest(String this._testDescription);
+ String get testDescription() => _testDescription;
+ final String _testDescription;
+ String toString() => _testDescription;
+}
+
+class _ExceptionResult {
+ const _ExceptionResult(String this._testDescription, var this._exception);
+
+ String get testDescription() => _testDescription;
+ final String _testDescription;
+
+ Object get exception() => _exception;
+ final _exception;
+}
+
+class FailedTest extends _ExceptionResult implements TestResult {
+ FailedTest(String testDescription, var exception) :
+ super(testDescription, exception);
+
+ String toString() => ">>> Test failure in ${_testDescription} " +
+ "with:\n${exception}\n";
+}
+
+class TestError extends _ExceptionResult implements TestResult {
+ TestError(String testDescription, var exception) :
+ super(testDescription, exception);
+
+ String toString() => ">>> Test error caught in " +
+ "${_testDescription} with:\n${exception}\n";
+}
+
+class TestClass {
+ void register(String description, Function test, TestSuite suite) {
+ suite._registerTest(TestResult _() {
+ setUp();
+ try {
+ test();
+ tearDown();
+ return new PassedTest(description);
+ } catch (ExpectException x) {
+ tearDown();
+ return new FailedTest(description, x);
+ } catch (var x) {
+ tearDown();
+ return new TestError(description, x);
+ }
+ });
+ }
+
+ abstract void registerTests(TestSuite suite);
+ void setUp() {}
+ void tearDown() {}
+}

Powered by Google App Engine
This is Rietveld 408576698