-
-
Notifications
You must be signed in to change notification settings - Fork 779
/
extract-quoted.test.ts
64 lines (60 loc) · 1.53 KB
/
extract-quoted.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
62
63
64
import { readFile } from 'fs/promises'
import { extractQuoted } from '@unocss/core'
import { describe, expect, test } from 'vitest'
describe('extractString', async () => {
const code = (await readFile('./test/assets/extract-quoted.ts', 'utf-8'))
.replace(/\r\n/g, '\n')
.trim()
test('works', () => {
const strings = extractQuoted(code)
expect(strings).toMatchInlineSnapshot(`
[
"",
"",
"",
"foo",
"bar",
"baz",
"foo\\\\'bar\\\\\\"baz",
"foo\${'bar'}\${'baz'}",
"foo\${'bar'}baz\${\`spam\`}ham eggs",
"foo\${\`spam\${\\"ham\\"}\${'eggs'}\`}\${\`bacon\`}bar",
]
`)
}, 1000)
test('should extract deep template string', () => {
const strings = extractQuoted(code, { deep: true })
expect(strings).toMatchInlineSnapshot(`
[
"",
"",
"",
"foo",
"bar",
"baz",
"foo\\\\'bar\\\\\\"baz",
"bar",
"baz",
"foo\${'bar'}\${'baz'}",
"bar",
"spam",
"foo\${'bar'}baz\${\`spam\`}ham eggs",
"ham",
"eggs",
"spam\${\\"ham\\"}\${'eggs'}",
"bacon",
"foo\${\`spam\${\\"ham\\"}\${'eggs'}\`}\${\`bacon\`}bar",
]
`)
}, 1000)
test('should extract static template only', () => {
const strings = extractQuoted(
code,
{
templateStaticOnly: true,
details: true,
})
.filter(({ value: { length } }) => length)
expect(strings).toMatchSnapshot()
}, 1000)
})