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('equalsIgnoringCase', () { | |
28 shouldPass('hello', equalsIgnoringCase('HELLO')); | |
29 shouldFail('hi', equalsIgnoringCase('HELLO'), | |
30 "Expected: 'HELLO' ignoring case Actual: 'hi'"); | |
31 }); | |
32 | |
33 test('equalsIgnoringWhitespace', () { | |
34 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | |
35 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | |
36 "Expected: 'hello world' ignoring whitespace " | |
37 "Actual: ' helloworld ' " | |
38 "Which: is 'helloworld' with whitespace compressed"); | |
39 }); | |
40 | |
41 test('startsWith', () { | |
42 shouldPass('hello', startsWith('')); | |
43 shouldPass('hello', startsWith('hell')); | |
44 shouldPass('hello', startsWith('hello')); | |
45 shouldFail('hello', startsWith('hello '), | |
46 "Expected: a string starting with 'hello ' " | |
47 "Actual: 'hello'"); | |
48 }); | |
49 | |
50 test('endsWith', () { | |
51 shouldPass('hello', endsWith('')); | |
52 shouldPass('hello', endsWith('lo')); | |
53 shouldPass('hello', endsWith('hello')); | |
54 shouldFail('hello', endsWith(' hello'), | |
55 "Expected: a string ending with ' hello' " | |
56 "Actual: 'hello'"); | |
57 }); | |
58 | |
59 test('contains', () { | |
60 shouldPass('hello', contains('')); | |
61 shouldPass('hello', contains('h')); | |
62 shouldPass('hello', contains('o')); | |
63 shouldPass('hello', contains('hell')); | |
64 shouldPass('hello', contains('hello')); | |
65 shouldFail('hello', contains(' '), | |
66 "Expected: contains ' ' Actual: 'hello'"); | |
67 }); | |
68 | |
69 test('stringContainsInOrder', () { | |
70 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | |
71 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | |
72 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | |
73 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | |
74 shouldPass('goodbye cruel world', | |
75 stringContainsInOrder(['good', 'bye', 'world'])); | |
76 shouldPass('goodbye cruel world', | |
77 stringContainsInOrder(['goodbye', 'cruel'])); | |
78 shouldPass('goodbye cruel world', | |
79 stringContainsInOrder(['cruel', 'world'])); | |
80 shouldPass('goodbye cruel world', | |
81 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | |
82 shouldFail('goodbye cruel world', | |
83 stringContainsInOrder(['goo', 'cruel', 'bye']), | |
84 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | |
85 "Actual: 'goodbye cruel world'"); | |
86 }); | |
87 | |
88 test('matches', () { | |
89 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | |
90 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | |
91 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | |
92 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); | |
93 }); | |
94 } | |
OLD | NEW |