-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpreprocess.test.ts
More file actions
66 lines (63 loc) · 2.25 KB
/
preprocess.test.ts
File metadata and controls
66 lines (63 loc) · 2.25 KB
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
65
66
import { describe, expect, test } from 'vitest';
import {
codeToGlimmerAst,
preprocessTemplateRange,
TEMPLATE_IDENTIFIER
} from '../../src/parse/preprocess.js';
const TEST_CASES = [
{
code: '<template>hi</template>',
expected: [`${TEMPLATE_IDENTIFIER}\`hi \``],
},
{
code: '<template>/* hi */</template>',
expected: [`${TEMPLATE_IDENTIFIER}\`~* hi *~ \``],
},
{
code: '<template><div>hi</div></template>',
expected: [`${TEMPLATE_IDENTIFIER}\`<div>hi<~div> \``],
},
{
code: '<template>{{#if true}}hi{{/if}}</template>',
expected: [`${TEMPLATE_IDENTIFIER}\`{{#if true}}hi{{~if}} \``],
},
{
code: '<template>////////////////</template>',
expected: [`${TEMPLATE_IDENTIFIER}\`~~~~~~~~~~~~~~~~ \``],
},
{
code: '<template>💩</template>',
expected: [`${TEMPLATE_IDENTIFIER}\`💩 \``],
},
{
code: 'const a = <template>foo</template>; const b = <template>bar</template>;',
expected: [
`const a = ${TEMPLATE_IDENTIFIER}\`foo \`; const b = <template>bar</template>;`,
`const a = <template>foo</template>; const b = ${TEMPLATE_IDENTIFIER}\`bar \`;`,
],
},
{
code: `const a = <template>💩💩💩💩💩💩💩</template>; const b = <template>💩</template>`,
expected: [
`const a = ${TEMPLATE_IDENTIFIER}\`💩💩💩💩💩💩💩 \`; const b = <template>💩</template>`,
`const a = <template>💩💩💩💩💩💩💩</template>; const b = ${TEMPLATE_IDENTIFIER}\`💩 \``,
],
},
{
code: 'class Thing { <template>hello</template> }',
expected: [`class Thing { static{${TEMPLATE_IDENTIFIER}\`hello \`} }`],
}
];
const FILE_NAME = 'foo.gts';
describe('preprocess', () => {
for (const testCase of TEST_CASES) {
test(`preprocessTemplateRange ${testCase.code}`, () => {
const templates = codeToGlimmerAst(testCase.code, FILE_NAME);
for (const [index, template] of templates.entries()) {
const received = preprocessTemplateRange(template, testCase.code);
expect(received).toEqual(testCase.expected[index]);
expect(received).toHaveLength(testCase.code.length);
}
});
}
});