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