|
| 1 | +import isMatch from '../src' |
| 2 | + |
| 3 | +describe('FOO', () => { |
| 4 | + it('should return true if matches words', () => { |
| 5 | + const arr = ['zhong', 'guo', 'zhong', 'che'] |
| 6 | + expect(isMatch(arr, 'zhong')).toBeTruthy() |
| 7 | + expect(isMatch(arr, 'guo')).toBeTruthy() |
| 8 | + expect(isMatch(arr, 'zhongg')).toBeTruthy() |
| 9 | + expect(isMatch(arr, 'guozhong')).toBeTruthy() |
| 10 | + }) |
| 11 | + |
| 12 | + test('should return true if matches words case-insensitive', () => { |
| 13 | + const arr = ['zhong', 'guo', 'zhong', 'che'] |
| 14 | + expect(isMatch(arr, 'Zhong')).toBeTruthy() |
| 15 | + expect(isMatch(arr, 'GUO')).toBeTruthy() |
| 16 | + expect(isMatch(arr, 'ZHONGG')).toBeTruthy() |
| 17 | + expect(isMatch(arr, 'guoZhong')).toBeTruthy() |
| 18 | + }) |
| 19 | + |
| 20 | + test('should matches first letter of each word from beginning', () => { |
| 21 | + const arr = ['zhong', 'guo', 'zhong', 'che'] |
| 22 | + expect(isMatch(arr, 'ZG')).toBeTruthy() |
| 23 | + expect(isMatch(arr, 'ZGZC')).toBeTruthy() |
| 24 | + expect(isMatch(arr, 'GZ')).toBeFalsy() |
| 25 | + }) |
| 26 | + |
| 27 | + test('should match from the beginning', () => { |
| 28 | + const arr = ['zhong', 'guo', 'zhong', 'che'] |
| 29 | + const config = { wordFromStart: true } |
| 30 | + expect(isMatch(arr, 'zhong', config)).toBeTruthy() |
| 31 | + expect(isMatch(arr, 'guo', config)).toBeFalsy() |
| 32 | + expect(isMatch(arr, 'zhongg', config)).toBeTruthy() |
| 33 | + expect(isMatch(arr, 'guozhong', config)).toBeFalsy() |
| 34 | + }) |
| 35 | + |
| 36 | + test('should matches first letter of each word', () => { |
| 37 | + const arr = ['zhong', 'guo', 'zhong', 'che'] |
| 38 | + const config = { letterFromStart: false } |
| 39 | + expect(isMatch(arr, 'ZG', config)).toBeTruthy() |
| 40 | + expect(isMatch(arr, 'ZGZC', config)).toBeTruthy() |
| 41 | + expect(isMatch(arr, 'GZ', config)).toBeTruthy() |
| 42 | + }) |
| 43 | + |
| 44 | + test('should matches first letter of each word', () => { |
| 45 | + const arr = ['bin', 'jiang', 'ji', 'tuan'] |
| 46 | + expect(isMatch(arr, 'jituan')).toBeTruthy() |
| 47 | + }) |
| 48 | + |
| 49 | + test('should matches chinese', () => { |
| 50 | + const arr = ['滨', '江', '集', '团'] |
| 51 | + expect(isMatch(arr, '滨江')).toBeTruthy() |
| 52 | + expect(isMatch(arr, '集团')).toBeTruthy() |
| 53 | + expect(isMatch(arr, '滨江集团')).toBeTruthy() |
| 54 | + }) |
| 55 | +}); |
0 commit comments