OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library matcher.string_matchers_test; | |
6 | |
7 import 'package:matcher/matcher.dart'; | |
8 import 'package:unittest/unittest.dart' show test, group; | |
9 | |
10 import 'test_utils.dart'; | |
11 | |
12 void main() { | |
13 initUtils(); | |
14 | |
15 test('collapseWhitespace', () { | |
16 var source = '\t\r\n hello\t\r\n world\r\t \n'; | |
17 expect(collapseWhitespace(source), 'hello world'); | |
18 }); | |
19 | |
20 test('isEmpty', () { | |
21 shouldPass('', isEmpty); | |
22 shouldFail(null, isEmpty, "Expected: empty Actual: <null>"); | |
23 shouldFail(0, isEmpty, "Expected: empty Actual: <0>"); | |
24 shouldFail('a', isEmpty, "Expected: empty Actual: 'a'"); | |
25 }); | |
26 | |
27 test('isNotEmpty', () { | |
28 shouldFail('', isNotEmpty, "Expected: non-empty Actual: ''"); | |
29 shouldFail(null, isNotEmpty, "Expected: non-empty Actual: <null>"); | |
30 shouldFail(0, isNotEmpty, "Expected: non-empty Actual: <0>"); | |
31 shouldPass('a', isNotEmpty); | |
32 }); | |
33 | |
34 test('equalsIgnoringCase', () { | |
35 shouldPass('hello', equalsIgnoringCase('HELLO')); | |
36 shouldFail('hi', equalsIgnoringCase('HELLO'), | |
37 "Expected: 'HELLO' ignoring case Actual: 'hi'"); | |
38 }); | |
39 | |
40 test('equalsIgnoringWhitespace', () { | |
41 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | |
42 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | |
43 "Expected: 'hello world' ignoring whitespace " | |
44 "Actual: ' helloworld ' " | |
45 "Which: is 'helloworld' with whitespace compressed"); | |
46 }); | |
47 | |
48 test('startsWith', () { | |
49 shouldPass('hello', startsWith('')); | |
50 shouldPass('hello', startsWith('hell')); | |
51 shouldPass('hello', startsWith('hello')); | |
52 shouldFail('hello', startsWith('hello '), | |
53 "Expected: a string starting with 'hello ' " | |
54 "Actual: 'hello'"); | |
55 }); | |
56 | |
57 test('endsWith', () { | |
58 shouldPass('hello', endsWith('')); | |
59 shouldPass('hello', endsWith('lo')); | |
60 shouldPass('hello', endsWith('hello')); | |
61 shouldFail('hello', endsWith(' hello'), | |
62 "Expected: a string ending with ' hello' " | |
63 "Actual: 'hello'"); | |
64 }); | |
65 | |
66 test('contains', () { | |
67 shouldPass('hello', contains('')); | |
68 shouldPass('hello', contains('h')); | |
69 shouldPass('hello', contains('o')); | |
70 shouldPass('hello', contains('hell')); | |
71 shouldPass('hello', contains('hello')); | |
72 shouldFail('hello', contains(' '), | |
73 "Expected: contains ' ' Actual: 'hello'"); | |
74 }); | |
75 | |
76 test('stringContainsInOrder', () { | |
77 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | |
78 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | |
79 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | |
80 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | |
81 shouldPass('goodbye cruel world', | |
82 stringContainsInOrder(['good', 'bye', 'world'])); | |
83 shouldPass('goodbye cruel world', | |
84 stringContainsInOrder(['goodbye', 'cruel'])); | |
85 shouldPass('goodbye cruel world', | |
86 stringContainsInOrder(['cruel', 'world'])); | |
87 shouldPass('goodbye cruel world', | |
88 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | |
89 shouldFail('goodbye cruel world', | |
90 stringContainsInOrder(['goo', 'cruel', 'bye']), | |
91 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | |
92 "Actual: 'goodbye cruel world'"); | |
93 }); | |
94 | |
95 test('matches', () { | |
96 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | |
97 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | |
98 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | |
99 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); | |
100 }); | |
101 } | |
OLD | NEW |