OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 library quiver.pattern_test; |
| 16 |
| 17 import 'package:test/test.dart'; |
| 18 import 'package:quiver/pattern.dart'; |
| 19 |
| 20 final _specialChars = r'\^$.|+[](){}'; |
| 21 |
| 22 main() { |
| 23 group('escapeRegex', () { |
| 24 test('should escape special characters', () { |
| 25 for (var c in _specialChars.split('')) { |
| 26 expect(escapeRegex(c), '\\$c'); |
| 27 } |
| 28 }); |
| 29 }); |
| 30 |
| 31 group('matchesAny', () { |
| 32 test('should match multiple include patterns', () { |
| 33 expectMatch(matchAny(['a', 'b']), 'a', 0, ['a']); |
| 34 expectMatch(matchAny(['a', 'b']), 'b', 0, ['b']); |
| 35 }); |
| 36 |
| 37 test('should match multiple include patterns (non-zero start)', () { |
| 38 expectMatch(matchAny(['a', 'b']), 'ba', 1, ['a']); |
| 39 expectMatch(matchAny(['a', 'b']), 'aab', 2, ['b']); |
| 40 }); |
| 41 |
| 42 test('should return multiple matches', () { |
| 43 expectMatch(matchAny(['a', 'b']), 'ab', 0, ['a', 'b']); |
| 44 }); |
| 45 |
| 46 test('should return multiple matches (non-zero start)', () { |
| 47 expectMatch(matchAny(['a', 'b', 'c']), 'cab', 1, ['a', 'b']); |
| 48 }); |
| 49 |
| 50 test('should exclude', () { |
| 51 expectMatch( |
| 52 matchAny(['foo', 'bar'], exclude: ['foobar']), 'foobar', 0, []); |
| 53 }); |
| 54 |
| 55 test('should exclude (non-zero start)', () { |
| 56 expectMatch( |
| 57 matchAny(['foo', 'bar'], exclude: ['foobar']), 'xyfoobar', 2, []); |
| 58 }); |
| 59 }); |
| 60 |
| 61 group('matchesFull', () { |
| 62 test('should match a string', () { |
| 63 expect(matchesFull('abcd', 'abcd'), true); |
| 64 expect(matchesFull(new RegExp('a.*d'), 'abcd'), true); |
| 65 }); |
| 66 |
| 67 test('should return false for a partial match', () { |
| 68 expect(matchesFull('abc', 'abcd'), false); |
| 69 expect(matchesFull('bcd', 'abcd'), false); |
| 70 expect(matchesFull(new RegExp('a.*c'), 'abcd'), false); |
| 71 expect(matchesFull(new RegExp('b.*d'), 'abcd'), false); |
| 72 }); |
| 73 }); |
| 74 } |
| 75 |
| 76 expectMatch(Pattern pattern, String str, int start, List<String> matches) { |
| 77 var actual = pattern.allMatches(str, start).map((m) => m.group(0)).toList(); |
| 78 expect(actual, matches); |
| 79 } |
OLD | NEW |