OLD | NEW |
---|---|
(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:unittest/unittest.dart'; | |
8 | |
9 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.
| |
10 | |
11 void main() { | |
12 group('escaping should work with', () { | |
13 _testEscaping('no escaped chars', 'Hello, world!', 'Hello, world!'); | |
14 _testEscaping('newline', '\n', r'\n'); | |
15 _testEscaping('carriage return', '\r', r'\r'); | |
16 _testEscaping('form feed', '\f', r'\f'); | |
17 _testEscaping('backspace', '\b', r'\b'); | |
18 _testEscaping('tab', '\t', r'\t'); | |
19 _testEscaping('vertical tab', '\v', r'\v'); | |
20 _testEscaping('escape combos', r'\n', r'\\n'); | |
21 }); | |
22 | |
23 group('unequal strings remain unequal when escaped', () { | |
24 _testUnequalStrings('with a newline', '\n', r'\n'); | |
25 _testUnequalStrings('with slash literals', '\\', r'\\'); | |
26 }); | |
27 } | |
28 | |
29 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.
| |
30 test(k, () { | |
31 expect(escape(source) == target, isTrue); | |
32 }); | |
33 } | |
34 | |
35 void _testUnequalStrings(String name, String s1, String s2) { | |
36 test(name, () { | |
37 // Explicitly not using the equals matcher | |
38 expect(s1 != s2, isTrue, reason: 'The source values should be unequal'); | |
39 | |
40 var escapedS1 = escape(s1); | |
41 var escapedS2 = escape(s2); | |
42 | |
43 // Explicitly not using the equals matcher | |
44 expect(escapedS1 != escapedS2, isTrue, | |
45 reason: 'Unequal strings, when escaped, should remain unequal.'); | |
46 }); | |
47 } | |
OLD | NEW |