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.'); |
+ }); |
+} |