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

Side by Side 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: nits 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 unified diff | Download patch
« no previous file with comments | « lib/src/util.dart ('k') | test/pretty_print_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library matcher.escape_test;
6
7 import 'package:matcher/src/util.dart';
8 import 'package:unittest/unittest.dart';
9
10 void main() {
11 group('escaping should work with', () {
12 _testEscaping('no escaped chars', 'Hello, world!', 'Hello, world!');
13 _testEscaping('newline', '\n', r'\n');
14 _testEscaping('carriage return', '\r', r'\r');
15 _testEscaping('form feed', '\f', r'\f');
16 _testEscaping('backspace', '\b', r'\b');
17 _testEscaping('tab', '\t', r'\t');
18 _testEscaping('vertical tab', '\v', r'\v');
19 _testEscaping('escape combos', r'\n', r'\\n');
20 _testEscaping('All characters',
21 'A new line\nA charriage return\rA form feed\fA backspace\b'
22 'A tab\tA vertical tab\vA slash\\',
23 r'A new line\nA charriage return\rA form feed\fA backspace\b'
24 r'A tab\tA vertical tab\vA slash\\');
25 });
26
27 group('unequal strings remain unequal when escaped', () {
28 _testUnequalStrings('with a newline', '\n', r'\n');
29 _testUnequalStrings('with slash literals', '\\', r'\\');
30 });
31 }
32
33 /// Creates a [test] with name [name] that verifies [source] escapes to value
34 /// [target].
35 void _testEscaping(String name, String source, String target) {
36 test(name, () {
37 var escaped = escape(source);
38 expect(escaped == target, isTrue,
39 reason: "Expected escaped value: $target\n"
40 " Actual escaped value: $escaped");
41 });
42 }
43
44 /// Creates a [test] with name [name] that ensures two different [String] values
45 /// [s1] and [s2] remain unequal when escaped.
46 void _testUnequalStrings(String name, String s1, String s2) {
47 test(name, () {
48 // Explicitly not using the equals matcher
49 expect(s1 != s2, isTrue, reason: 'The source values should be unequal');
50
51 var escapedS1 = escape(s1);
52 var escapedS2 = escape(s2);
53
54 // Explicitly not using the equals matcher
55 expect(escapedS1 != escapedS2, isTrue,
56 reason: 'Unequal strings, when escaped, should remain unequal.');
57 });
58 }
OLDNEW
« no previous file with comments | « lib/src/util.dart ('k') | test/pretty_print_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698