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

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: cleanup Created 5 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
« lib/src/escape.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/escape_test.dart
diff --git a/test/escape_test.dart b/test/escape_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b38a1d20c5bdc7262d2228864d95b4156da4fba4
--- /dev/null
+++ b/test/escape_test.dart
@@ -0,0 +1,47 @@
+// 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:unittest/unittest.dart';
+
+import 'package:matcher/src/escape.dart';
nweiz 2015/02/04 01:34:46 All "package:" imports should be in a single block
kevmoo 2015/02/04 05:28:21 Done.
+
+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');
+ });
+
+ group('unequal strings remain unequal when escaped', () {
+ _testUnequalStrings('with a newline', '\n', r'\n');
+ _testUnequalStrings('with slash literals', '\\', r'\\');
+ });
+}
+
+void _testEscaping(String k, String source, String target) {
nweiz 2015/02/04 01:34:46 Document these functions and don't use single-lett
kevmoo 2015/02/04 05:28:21 Done.
+ test(k, () {
+ expect(escape(source) == target, isTrue);
+ });
+}
+
+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.');
+ });
+}
« lib/src/escape.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698