-
Notifications
You must be signed in to change notification settings - Fork 181
/
fuzzy-highlight.test.ts
61 lines (60 loc) · 1.84 KB
/
fuzzy-highlight.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import fuzzyHighlight from './fuzzy-highlight';
describe('fuzzyHighlight', () => {
it('should match full haystack', () => {
fuzzyHighlight('cartwheel', 'cartwheel').should.deep.equal({
matched: true,
matches: [{from: 0, to: 9}],
highlight: '**cartwheel**'
});
});
it('should match part of the haystack', () => {
fuzzyHighlight('car', 'cartwheel').should.deep.equal({
matched: true,
matches: [{from: 0, to: 3}],
highlight: '**car**twheel'
});
fuzzyHighlight('cwhl', 'cartwheel').should.deep.equal({
matched: true,
matches: [{from: 0, to: 1}, {from: 4, to: 6}, {from: 8, to: 9}],
highlight: '**c**art**wh**ee**l**'
});
fuzzyHighlight('cwheel', 'cartwheel').should.deep.equal({
matched: true,
matches: [{from: 0, to: 1}, {from: 4, to: 9}],
highlight: '**c**art**wheel**'
});
});
it('shouldn\'t match needle with extra symbols', () => {
fuzzyHighlight('cwheeel', 'cartwheel').should.deep.equal({
matched: false,
matches: [],
highlight: 'cartwheel'
});
});
it('shouldn\'t match needle with false order', () => {
fuzzyHighlight('lw', 'cartwheel').should.deep.equal({
matched: false,
matches: [],
highlight: 'cartwheel'
});
});
it('should be case-insensitive by default', () => {
fuzzyHighlight('cAr', 'Cartwheel').should.deep.equal({
matched: true,
matches: [{from: 0, to: 3}],
highlight: '**Car**twheel'
});
});
it('should allow case-sensitivity as an option', () => {
fuzzyHighlight('cAr', 'Cartwheel', true).should.deep.equal({
matched: false,
matches: [],
highlight: 'Cartwheel'
});
fuzzyHighlight('Car', 'Cartwheel', true).should.deep.equal({
matched: true,
matches: [{from: 0, to: 3}],
highlight: '**Car**twheel'
});
});
});