OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library matcher.string_matchers_test; | |
6 | |
7 import 'package:matcher/matcher.dart'; | 5 import 'package:matcher/matcher.dart'; |
8 import 'package:test/test.dart' show test, group, expect; | 6 import 'package:test/test.dart' show test, expect; |
9 | 7 |
10 import 'test_utils.dart'; | 8 import 'test_utils.dart'; |
11 | 9 |
12 void main() { | 10 void main() { |
13 test('Reports mismatches in whitespace and escape sequences', () { | 11 test('Reports mismatches in whitespace and escape sequences', () { |
14 shouldFail('before\nafter', equals('before\\nafter'), | 12 shouldFail('before\nafter', equals('before\\nafter'), |
15 contains('Differ at offset 7')); | 13 contains('Differ at offset 7')); |
16 }); | 14 }); |
17 | 15 |
18 test('collapseWhitespace', () { | 16 test('collapseWhitespace', () { |
(...skipping 25 matching lines...) Expand all Loading... |
44 }); | 42 }); |
45 | 43 |
46 test('equalsIgnoringCase', () { | 44 test('equalsIgnoringCase', () { |
47 shouldPass('hello', equalsIgnoringCase('HELLO')); | 45 shouldPass('hello', equalsIgnoringCase('HELLO')); |
48 shouldFail('hi', equalsIgnoringCase('HELLO'), | 46 shouldFail('hi', equalsIgnoringCase('HELLO'), |
49 "Expected: 'HELLO' ignoring case Actual: 'hi'"); | 47 "Expected: 'HELLO' ignoring case Actual: 'hi'"); |
50 }); | 48 }); |
51 | 49 |
52 test('equalsIgnoringWhitespace', () { | 50 test('equalsIgnoringWhitespace', () { |
53 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | 51 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); |
54 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | 52 shouldFail( |
| 53 ' helloworld ', |
| 54 equalsIgnoringWhitespace('hello world'), |
55 "Expected: 'hello world' ignoring whitespace " | 55 "Expected: 'hello world' ignoring whitespace " |
56 "Actual: ' helloworld ' " | 56 "Actual: ' helloworld ' " |
57 "Which: is 'helloworld' with whitespace compressed"); | 57 "Which: is 'helloworld' with whitespace compressed"); |
58 }); | 58 }); |
59 | 59 |
60 test('startsWith', () { | 60 test('startsWith', () { |
61 shouldPass('hello', startsWith('')); | 61 shouldPass('hello', startsWith('')); |
62 shouldPass('hello', startsWith('hell')); | 62 shouldPass('hello', startsWith('hell')); |
63 shouldPass('hello', startsWith('hello')); | 63 shouldPass('hello', startsWith('hello')); |
64 shouldFail('hello', startsWith('hello '), | 64 shouldFail( |
| 65 'hello', |
| 66 startsWith('hello '), |
65 "Expected: a string starting with 'hello ' " | 67 "Expected: a string starting with 'hello ' " |
66 "Actual: 'hello'"); | 68 "Actual: 'hello'"); |
67 }); | 69 }); |
68 | 70 |
69 test('endsWith', () { | 71 test('endsWith', () { |
70 shouldPass('hello', endsWith('')); | 72 shouldPass('hello', endsWith('')); |
71 shouldPass('hello', endsWith('lo')); | 73 shouldPass('hello', endsWith('lo')); |
72 shouldPass('hello', endsWith('hello')); | 74 shouldPass('hello', endsWith('hello')); |
73 shouldFail('hello', endsWith(' hello'), | 75 shouldFail( |
| 76 'hello', |
| 77 endsWith(' hello'), |
74 "Expected: a string ending with ' hello' " | 78 "Expected: a string ending with ' hello' " |
75 "Actual: 'hello'"); | 79 "Actual: 'hello'"); |
76 }); | 80 }); |
77 | 81 |
78 test('contains', () { | 82 test('contains', () { |
79 shouldPass('hello', contains('')); | 83 shouldPass('hello', contains('')); |
80 shouldPass('hello', contains('h')); | 84 shouldPass('hello', contains('h')); |
81 shouldPass('hello', contains('o')); | 85 shouldPass('hello', contains('o')); |
82 shouldPass('hello', contains('hell')); | 86 shouldPass('hello', contains('hell')); |
83 shouldPass('hello', contains('hello')); | 87 shouldPass('hello', contains('hello')); |
84 shouldFail( | 88 shouldFail( |
85 'hello', contains(' '), "Expected: contains ' ' Actual: 'hello'"); | 89 'hello', contains(' '), "Expected: contains ' ' Actual: 'hello'"); |
86 }); | 90 }); |
87 | 91 |
88 test('stringContainsInOrder', () { | 92 test('stringContainsInOrder', () { |
89 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 93 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
90 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 94 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
91 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 95 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
92 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 96 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
93 shouldPass( | 97 shouldPass( |
94 'goodbye cruel world', stringContainsInOrder(['good', 'bye', 'world'])); | 98 'goodbye cruel world', stringContainsInOrder(['good', 'bye', 'world'])); |
95 shouldPass( | 99 shouldPass( |
96 'goodbye cruel world', stringContainsInOrder(['goodbye', 'cruel'])); | 100 'goodbye cruel world', stringContainsInOrder(['goodbye', 'cruel'])); |
97 shouldPass( | 101 shouldPass( |
98 'goodbye cruel world', stringContainsInOrder(['cruel', 'world'])); | 102 'goodbye cruel world', stringContainsInOrder(['cruel', 'world'])); |
99 shouldPass('goodbye cruel world', | 103 shouldPass('goodbye cruel world', |
100 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 104 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
101 shouldFail('goodbye cruel world', | 105 shouldFail( |
| 106 'goodbye cruel world', |
102 stringContainsInOrder(['goo', 'cruel', 'bye']), | 107 stringContainsInOrder(['goo', 'cruel', 'bye']), |
103 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 108 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
104 "Actual: 'goodbye cruel world'"); | 109 "Actual: 'goodbye cruel world'"); |
105 }); | 110 }); |
106 | 111 |
107 test('matches', () { | 112 test('matches', () { |
108 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 113 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
109 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 114 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
110 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 115 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
111 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); | 116 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); |
112 }); | 117 }); |
113 } | 118 } |
OLD | NEW |