-
-
Notifications
You must be signed in to change notification settings - Fork 779
/
autocomplete-fuzzy.test.ts
51 lines (43 loc) · 1.24 KB
/
autocomplete-fuzzy.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
import { createAutocomplete } from '@unocss/autocomplete'
import { createGenerator } from '@unocss/core'
import { describe, expect, it } from 'vitest'
import presetUno from '@unocss/preset-uno'
describe('autocomplete-fuzzy', () => {
const uno = createGenerator({
presets: [
presetUno(),
],
shortcuts: [
{
'foo': 'text-red',
'foo-bar': 'text-red',
},
[/^bg-mode-(.+)$/, ([, mode]) => `bg-blend-${mode}`, { autocomplete: ['bg-mode-(color|normal)'] }],
],
})
const ac = createAutocomplete(uno, {
matchType: 'fuzzy',
})
it('static', async () => {
expect(await ac.suggest('itct'))
.includes('items-center')
expect(await ac.suggest('jc'))
.includes('justify-center')
})
it('variant', async () => {
expect(await ac.suggest('tsm'))
.includes('text-sm')
expect(await ac.suggest('tbl5'))
.includes('text-blue-500')
})
it('shortcuts', async () => {
expect(await ac.suggest('fb'))
.includes('foo-bar')
expect(await ac.suggest('bmc'))
.includes('bg-mode-color')
})
it('order', async () => {
const suggestions = await ac.suggest('ga')
expect(suggestions.indexOf('gap-0')).toBeLessThan(suggestions.indexOf('gap-1'))
})
})