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:test/test.dart' show test, group, expect; |
| 9 |
| 10 import 'test_utils.dart'; |
| 11 |
| 12 void main() { |
| 13 test('Reports mismatches in whitespace and escape sequences', () { |
| 14 shouldFail('before\nafter', equals('before\\nafter'), |
| 15 contains('Differ at offset 7')); |
| 16 }); |
| 17 |
| 18 test('collapseWhitespace', () { |
| 19 var source = '\t\r\n hello\t\r\n world\r\t \n'; |
| 20 expect(collapseWhitespace(source), 'hello world'); |
| 21 }); |
| 22 |
| 23 test('isEmpty', () { |
| 24 shouldPass('', isEmpty); |
| 25 shouldFail(null, isEmpty, startsWith("Expected: empty Actual: <null>")); |
| 26 shouldFail(0, isEmpty, startsWith("Expected: empty Actual: <0>")); |
| 27 shouldFail('a', isEmpty, startsWith("Expected: empty Actual: 'a'")); |
| 28 }); |
| 29 |
| 30 // Regression test for: https://code.google.com/p/dart/issues/detail?id=21562 |
| 31 test('isNot(isEmpty)', () { |
| 32 shouldPass('a', isNot(isEmpty)); |
| 33 shouldFail('', isNot(isEmpty), 'Expected: not empty Actual: \'\''); |
| 34 shouldFail(null, isNot(isEmpty), |
| 35 startsWith('Expected: not empty Actual: <null>')); |
| 36 }); |
| 37 |
| 38 test('isNotEmpty', () { |
| 39 shouldFail('', isNotEmpty, startsWith("Expected: non-empty Actual: ''")); |
| 40 shouldFail( |
| 41 null, isNotEmpty, startsWith("Expected: non-empty Actual: <null>")); |
| 42 shouldFail(0, isNotEmpty, startsWith("Expected: non-empty Actual: <0>")); |
| 43 shouldPass('a', isNotEmpty); |
| 44 }); |
| 45 |
| 46 test('equalsIgnoringCase', () { |
| 47 shouldPass('hello', equalsIgnoringCase('HELLO')); |
| 48 shouldFail('hi', equalsIgnoringCase('HELLO'), |
| 49 "Expected: 'HELLO' ignoring case Actual: 'hi'"); |
| 50 }); |
| 51 |
| 52 test('equalsIgnoringWhitespace', () { |
| 53 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); |
| 54 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), |
| 55 "Expected: 'hello world' ignoring whitespace " |
| 56 "Actual: ' helloworld ' " |
| 57 "Which: is 'helloworld' with whitespace compressed"); |
| 58 }); |
| 59 |
| 60 test('startsWith', () { |
| 61 shouldPass('hello', startsWith('')); |
| 62 shouldPass('hello', startsWith('hell')); |
| 63 shouldPass('hello', startsWith('hello')); |
| 64 shouldFail('hello', startsWith('hello '), |
| 65 "Expected: a string starting with 'hello ' " |
| 66 "Actual: 'hello'"); |
| 67 }); |
| 68 |
| 69 test('endsWith', () { |
| 70 shouldPass('hello', endsWith('')); |
| 71 shouldPass('hello', endsWith('lo')); |
| 72 shouldPass('hello', endsWith('hello')); |
| 73 shouldFail('hello', endsWith(' hello'), |
| 74 "Expected: a string ending with ' hello' " |
| 75 "Actual: 'hello'"); |
| 76 }); |
| 77 |
| 78 test('contains', () { |
| 79 shouldPass('hello', contains('')); |
| 80 shouldPass('hello', contains('h')); |
| 81 shouldPass('hello', contains('o')); |
| 82 shouldPass('hello', contains('hell')); |
| 83 shouldPass('hello', contains('hello')); |
| 84 shouldFail( |
| 85 'hello', contains(' '), "Expected: contains ' ' Actual: 'hello'"); |
| 86 }); |
| 87 |
| 88 test('stringContainsInOrder', () { |
| 89 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
| 90 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
| 91 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
| 92 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
| 93 shouldPass( |
| 94 'goodbye cruel world', stringContainsInOrder(['good', 'bye', 'world'])); |
| 95 shouldPass( |
| 96 'goodbye cruel world', stringContainsInOrder(['goodbye', 'cruel'])); |
| 97 shouldPass( |
| 98 'goodbye cruel world', stringContainsInOrder(['cruel', 'world'])); |
| 99 shouldPass('goodbye cruel world', |
| 100 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
| 101 shouldFail('goodbye cruel world', |
| 102 stringContainsInOrder(['goo', 'cruel', 'bye']), |
| 103 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
| 104 "Actual: 'goodbye cruel world'"); |
| 105 }); |
| 106 |
| 107 test('matches', () { |
| 108 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
| 109 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
| 110 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
| 111 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); |
| 112 }); |
| 113 } |
OLD | NEW |