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; | 5 library matcher.string_matchers_test; |
6 | 6 |
7 import 'package:matcher/matcher.dart'; | 7 import 'package:matcher/matcher.dart'; |
8 import 'package:unittest/unittest.dart' show test, group; | 8 import 'package:unittest/unittest.dart' show test, group; |
9 | 9 |
10 import 'test_utils.dart'; | 10 import 'test_utils.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 shouldFail(null, isEmpty, startsWith("Expected: empty Actual: <null>")); | 22 shouldFail(null, isEmpty, startsWith("Expected: empty Actual: <null>")); |
23 shouldFail(0, isEmpty, startsWith("Expected: empty Actual: <0>")); | 23 shouldFail(0, isEmpty, startsWith("Expected: empty Actual: <0>")); |
24 shouldFail('a', isEmpty, startsWith("Expected: empty Actual: 'a'")); | 24 shouldFail('a', isEmpty, startsWith("Expected: empty Actual: 'a'")); |
25 }); | 25 }); |
26 | 26 |
27 // Regression test for: https://code.google.com/p/dart/issues/detail?id=21562 | 27 // Regression test for: https://code.google.com/p/dart/issues/detail?id=21562 |
28 test('isNot(isEmpty)', () { | 28 test('isNot(isEmpty)', () { |
29 shouldPass('a', isNot(isEmpty)); | 29 shouldPass('a', isNot(isEmpty)); |
30 shouldFail('', isNot(isEmpty), 'Expected: not empty Actual: \'\''); | 30 shouldFail('', isNot(isEmpty), 'Expected: not empty Actual: \'\''); |
31 shouldFail(null, isNot(isEmpty), | 31 shouldFail(null, isNot(isEmpty), |
32 startsWith('Expected: not empty Actual: <null>')); | 32 startsWith('Expected: not empty Actual: <null>')); |
33 }); | 33 }); |
34 | 34 |
35 test('isNotEmpty', () { | 35 test('isNotEmpty', () { |
36 shouldFail('', isNotEmpty, startsWith("Expected: non-empty Actual: ''")); | 36 shouldFail('', isNotEmpty, startsWith("Expected: non-empty Actual: ''")); |
37 shouldFail(null, isNotEmpty, | 37 shouldFail( |
38 startsWith("Expected: non-empty Actual: <null>")); | 38 null, isNotEmpty, startsWith("Expected: non-empty Actual: <null>")); |
39 shouldFail(0, isNotEmpty, startsWith("Expected: non-empty Actual: <0>")); | 39 shouldFail(0, isNotEmpty, startsWith("Expected: non-empty Actual: <0>")); |
40 shouldPass('a', isNotEmpty); | 40 shouldPass('a', isNotEmpty); |
41 }); | 41 }); |
42 | 42 |
43 test('equalsIgnoringCase', () { | 43 test('equalsIgnoringCase', () { |
44 shouldPass('hello', equalsIgnoringCase('HELLO')); | 44 shouldPass('hello', equalsIgnoringCase('HELLO')); |
45 shouldFail('hi', equalsIgnoringCase('HELLO'), | 45 shouldFail('hi', equalsIgnoringCase('HELLO'), |
46 "Expected: 'HELLO' ignoring case Actual: 'hi'"); | 46 "Expected: 'HELLO' ignoring case Actual: 'hi'"); |
47 }); | 47 }); |
48 | 48 |
(...skipping 22 matching lines...) Expand all Loading... |
71 "Expected: a string ending with ' hello' " | 71 "Expected: a string ending with ' hello' " |
72 "Actual: 'hello'"); | 72 "Actual: 'hello'"); |
73 }); | 73 }); |
74 | 74 |
75 test('contains', () { | 75 test('contains', () { |
76 shouldPass('hello', contains('')); | 76 shouldPass('hello', contains('')); |
77 shouldPass('hello', contains('h')); | 77 shouldPass('hello', contains('h')); |
78 shouldPass('hello', contains('o')); | 78 shouldPass('hello', contains('o')); |
79 shouldPass('hello', contains('hell')); | 79 shouldPass('hello', contains('hell')); |
80 shouldPass('hello', contains('hello')); | 80 shouldPass('hello', contains('hello')); |
81 shouldFail('hello', contains(' '), | 81 shouldFail( |
82 "Expected: contains ' ' Actual: 'hello'"); | 82 'hello', contains(' '), "Expected: contains ' ' Actual: 'hello'"); |
83 }); | 83 }); |
84 | 84 |
85 test('stringContainsInOrder', () { | 85 test('stringContainsInOrder', () { |
86 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 86 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
87 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 87 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
88 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 88 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
89 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 89 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
| 90 shouldPass( |
| 91 'goodbye cruel world', stringContainsInOrder(['good', 'bye', 'world'])); |
| 92 shouldPass( |
| 93 'goodbye cruel world', stringContainsInOrder(['goodbye', 'cruel'])); |
| 94 shouldPass( |
| 95 'goodbye cruel world', stringContainsInOrder(['cruel', 'world'])); |
90 shouldPass('goodbye cruel world', | 96 shouldPass('goodbye cruel world', |
91 stringContainsInOrder(['good', 'bye', 'world'])); | 97 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
92 shouldPass('goodbye cruel world', | |
93 stringContainsInOrder(['goodbye', 'cruel'])); | |
94 shouldPass('goodbye cruel world', | |
95 stringContainsInOrder(['cruel', 'world'])); | |
96 shouldPass('goodbye cruel world', | |
97 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | |
98 shouldFail('goodbye cruel world', | 98 shouldFail('goodbye cruel world', |
99 stringContainsInOrder(['goo', 'cruel', 'bye']), | 99 stringContainsInOrder(['goo', 'cruel', 'bye']), |
100 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 100 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
101 "Actual: 'goodbye cruel world'"); | 101 "Actual: 'goodbye cruel world'"); |
102 }); | 102 }); |
103 | 103 |
104 test('matches', () { | 104 test('matches', () { |
105 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 105 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
106 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 106 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
107 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 107 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
108 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); | 108 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); |
109 }); | 109 }); |
110 } | 110 } |
OLD | NEW |