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

Unified Diff: test/pretty_print_test.dart

Issue 1135653004: pkg/(unit)test: include a copy of old matcher (Closed) Base URL: https://github.com/dart-lang/test.git@stable
Patch Set: another nit Created 5 years, 7 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/operator_matchers_test.dart ('k') | test/prints_matcher_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/pretty_print_test.dart
diff --git a/test/pretty_print_test.dart b/test/pretty_print_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6717a56f5861dde40b0717c0e52bc94b2b4241f7
--- /dev/null
+++ b/test/pretty_print_test.dart
@@ -0,0 +1,193 @@
+// Copyright (c) 2013, 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 unittest.matcher.pretty_print_test;
+
+import 'package:unittest/unittest.dart';
+import 'package:unittest/src/matcher/pretty_print.dart';
+
+void main() {
+ test('with primitive objects', () {
+ expect(prettyPrint(12), equals('<12>'));
+ expect(prettyPrint(12.13), equals('<12.13>'));
+ expect(prettyPrint(true), equals('<true>'));
+ expect(prettyPrint(null), equals('<null>'));
+ expect(prettyPrint(() => 12), matches(r'<Closure(: \(\) => dynamic)?>'));
+ });
+
+ group('with a string', () {
+ test('containing simple characters', () {
+ expect(prettyPrint('foo'), equals("'foo'"));
+ });
+
+ test('containing newlines', () {
+ expect(prettyPrint('foo\nbar\nbaz'), equals("'foo\\n'\n"
+ " 'bar\\n'\n"
+ " 'baz'"));
+ });
+
+ test('containing escapable characters', () {
+ expect(
+ prettyPrint("foo\rbar\tbaz'qux\v"), equals(r"'foo\rbar\tbaz\'qux\v'"));
+ });
+ });
+
+ group('with an iterable', () {
+ test('containing primitive objects', () {
+ expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']"));
+ });
+
+ test('containing a multiline string', () {
+ expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n"
+ " 'foo',\n"
+ " 'bar\\n'\n"
+ " 'baz\\n'\n"
+ " 'bip',\n"
+ " 'qux'\n"
+ "]"));
+ });
+
+ test('containing a matcher', () {
+ expect(prettyPrint(['foo', endsWith('qux')]),
+ equals("['foo', <a string ending with 'qux'>]"));
+ });
+
+ test("that's under maxLineLength", () {
+ expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 30),
+ equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
+ });
+
+ test("that's over maxLineLength", () {
+ expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 29),
+ equals("[\n"
+ " 0,\n"
+ " 1,\n"
+ " 2,\n"
+ " 3,\n"
+ " 4,\n"
+ " 5,\n"
+ " 6,\n"
+ " 7,\n"
+ " 8,\n"
+ " 9\n"
+ "]"));
+ });
+
+ test("factors indentation into maxLineLength", () {
+ expect(prettyPrint(["foo\nbar", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],],
+ maxLineLength: 30), equals("[\n"
+ " 'foo\\n'\n"
+ " 'bar',\n"
+ " [\n"
+ " 0,\n"
+ " 1,\n"
+ " 2,\n"
+ " 3,\n"
+ " 4,\n"
+ " 5,\n"
+ " 6,\n"
+ " 7,\n"
+ " 8,\n"
+ " 9\n"
+ " ]\n"
+ "]"));
+ });
+
+ test("that's under maxItems", () {
+ expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10),
+ equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
+ });
+
+ test("that's over maxItems", () {
+ expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9),
+ equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]"));
+ });
+
+ test("that's recursive", () {
+ var list = [1, 2, 3];
+ list.add(list);
+ expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]"));
+ });
+ });
+
+ group("with a map", () {
+ test('containing primitive objects', () {
+ expect(prettyPrint({'foo': 1, 'bar': true}),
+ equals("{'foo': 1, 'bar': true}"));
+ });
+
+ test('containing a multiline string key', () {
+ expect(prettyPrint({'foo\nbar': 1, 'bar': true}), equals("{\n"
+ " 'foo\\n'\n"
+ " 'bar': 1,\n"
+ " 'bar': true\n"
+ "}"));
+ });
+
+ test('containing a multiline string value', () {
+ expect(prettyPrint({'foo': 'bar\nbaz', 'qux': true}), equals("{\n"
+ " 'foo': 'bar\\n'\n"
+ " 'baz',\n"
+ " 'qux': true\n"
+ "}"));
+ });
+
+ test('containing a multiline string key/value pair', () {
+ expect(prettyPrint({'foo\nbar': 'baz\nqux'}), equals("{\n"
+ " 'foo\\n'\n"
+ " 'bar': 'baz\\n'\n"
+ " 'qux'\n"
+ "}"));
+ });
+
+ test('containing a matcher key', () {
+ expect(prettyPrint({endsWith('bar'): 'qux'}),
+ equals("{<a string ending with 'bar'>: 'qux'}"));
+ });
+
+ test('containing a matcher value', () {
+ expect(prettyPrint({'foo': endsWith('qux')}),
+ equals("{'foo': <a string ending with 'qux'>}"));
+ });
+
+ test("that's under maxLineLength", () {
+ expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 32),
+ equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
+ });
+
+ test("that's over maxLineLength", () {
+ expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 31),
+ equals("{\n"
+ " '0': 1,\n"
+ " '2': 3,\n"
+ " '4': 5,\n"
+ " '6': 7\n"
+ "}"));
+ });
+
+ test("factors indentation into maxLineLength", () {
+ expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}],
+ maxLineLength: 32), equals("[\n"
+ " 'foo\\n'\n"
+ " 'bar',\n"
+ " {\n"
+ " '0': 1,\n"
+ " '2': 3,\n"
+ " '4': 5,\n"
+ " '6': 7\n"
+ " }\n"
+ "]"));
+ });
+
+ test("that's under maxItems", () {
+ expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4),
+ equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
+ });
+
+ test("that's over maxItems", () {
+ expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3),
+ equals("{'0': 1, '2': 3, ...}"));
+ });
+ });
+}
« no previous file with comments | « test/operator_matchers_test.dart ('k') | test/prints_matcher_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698