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

Unified Diff: packages/matcher/test/escape_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « packages/matcher/test/core_matchers_test.dart ('k') | packages/matcher/test/iterable_matchers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/matcher/test/escape_test.dart
diff --git a/packages/matcher/test/escape_test.dart b/packages/matcher/test/escape_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..35a18bcff0745c066125dd6be85a1a2b8ec09964
--- /dev/null
+++ b/packages/matcher/test/escape_test.dart
@@ -0,0 +1,63 @@
+// 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:test/test.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('null byte', '\x00', r'\x00');
+ _testEscaping('ASCII control character', '\x11', r'\x11');
+ _testEscaping('delete', '\x7F', r'\x7F');
+ _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\\A null byte\x00A control char\x1D'
+ 'A delete\x7F',
+ r'A new line\nA charriage return\rA form feed\fA backspace\b'
+ r'A tab\tA vertical tab\vA slash\\A null byte\x00A control char\x1D'
+ r'A delete\x7F');
+ });
+
+ 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.');
+ });
+}
« no previous file with comments | « packages/matcher/test/core_matchers_test.dart ('k') | packages/matcher/test/iterable_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698