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

Unified Diff: test/escape_test.dart

Issue 891463004: Correctly match and print strings with escaped values (Closed) Base URL: https://github.com/dart-lang/matcher.git@master
Patch Set: also fixed prettyPrint Created 5 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
Index: test/escape_test.dart
diff --git a/test/escape_test.dart b/test/escape_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..035967c0a5f9f80bbddc0fdf0a5f97e9e29d3e74
--- /dev/null
+++ b/test/escape_test.dart
@@ -0,0 +1,58 @@
+// 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.
+
+library matcher.escape_test;
+
+import 'package:matcher/src/util.dart';
+import 'package:unittest/unittest.dart';
+
+void main() {
+ group('escaping should work with', () {
+ _testEscaping('no escaped chars', 'Hello, world!', 'Hello, world!');
+ _testEscaping('newline', '\n', r'\n');
+ _testEscaping('carriage return', '\r', r'\r');
+ _testEscaping('form feed', '\f', r'\f');
+ _testEscaping('backspace', '\b', r'\b');
+ _testEscaping('tab', '\t', r'\t');
+ _testEscaping('vertical tab', '\v', r'\v');
+ _testEscaping('escape combos', r'\n', r'\\n');
+ _testEscaping('All characters',
+ 'A new line\nA charriage return\rA form feed\fA backspace\b'
+ 'A tab\tA vertical tab\vA slash\\',
+ r'A new line\nA charriage return\rA form feed\fA backspace\b'
+ r'A tab\tA vertical tab\vA slash\\');
+ });
+
+ group('unequal strings remain unequal when escaped', () {
+ _testUnequalStrings('with a newline', '\n', r'\n');
+ _testUnequalStrings('with slash literals', '\\', r'\\');
+ });
+}
+
+/// Creates a [test] with name [name] that verifies [source] escapes to value
+/// [target].
+void _testEscaping(String name, String source, String target) {
+ test(name, () {
+ var escaped = escape(source);
+ expect(escaped == target, isTrue,
+ reason: "Expected escaped value: $target\n"
+ " Actual escaped value: $escaped");
+ });
+}
+
+/// Creates a [test] with name [name] that ensures two different [String] values
+/// [s1] and [s2] remain unequal when escaped.
+void _testUnequalStrings(String name, String s1, String s2) {
+ test(name, () {
+ // Explicitly not using the equals matcher
+ expect(s1 != s2, isTrue, reason: 'The source values should be unequal');
+
+ var escapedS1 = escape(s1);
+ var escapedS2 = escape(s2);
+
+ // Explicitly not using the equals matcher
+ expect(escapedS1 != escapedS2, isTrue,
+ reason: 'Unequal strings, when escaped, should remain unequal.');
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698