Skip to content

Commit c6fbad4

Browse files
Merge pull request #883 from typed-ember/nvp/character-testing
Add character tests
2 parents 8c08e8a + 733e5fd commit c6fbad4

File tree

3 files changed

+144
-26
lines changed

3 files changed

+144
-26
lines changed

packages/environment-ember-template-imports/__tests__/transformation.test.ts

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,40 @@ describe('Environment: ETI', () => {
2727
});
2828
});
2929

30-
test('handles multi-byte characters', () => {
31-
let source = [
32-
`const a = <template>one 💩</template>;`,
33-
`const b = <template>two</template>;`,
34-
`const c = "‘foo’";`,
35-
`const d = <template>four</template>;`,
36-
].join('\n');
37-
38-
let result = preprocess(source, 'index.gts');
30+
describe('character testing', () => {
31+
test('‘, 💩', () => {
32+
let source = [
33+
`const a = <template>one 💩</template>;`,
34+
`const b = <template>two</template>;`,
35+
`const c = "‘foo’";`,
36+
`const d = <template>four</template>;`,
37+
].join('\n');
38+
39+
let result = preprocess(source, 'index.gts');
40+
41+
expect(result.contents).toMatchInlineSnapshot(`
42+
"const a = [___T\`one 💩\`];
43+
const b = [___T\`two\`];
44+
const c = "‘foo’";
45+
const d = [___T\`four\`];"
46+
`);
47+
});
3948

40-
expect(result.contents).toMatchInlineSnapshot(`
41-
"const a = [___T\`one 💩\`];
42-
const b = [___T\`two\`];
43-
const c = "‘foo’";
44-
const d = [___T\`four\`];"
45-
`);
46-
});
49+
test('$', () => {
50+
let source = '<template>${{dollarAmount}}</template>;';
4751

48-
test('handles the $ character', () => {
49-
let source = '<template>${{dollarAmount}}</template>;';
52+
let result = preprocess(source, 'index.gts');
5053

51-
let result = preprocess(source, 'index.gts');
54+
expect(result.contents).toMatchInlineSnapshot('"[___T`\\${{dollarAmount}}`];"');
55+
});
5256

53-
expect(result.contents).toMatchInlineSnapshot('"[___T`\\${{dollarAmount}}`];"');
54-
});
57+
test('`', () => {
58+
let source = '<template>`code`</template>;';
5559

56-
test('handles the ` character', () => {
57-
let source = '<template>`code`</template>;';
60+
let result = preprocess(source, 'index.gts');
5861

59-
let result = preprocess(source, 'index.gts');
60-
61-
expect(result.contents).toMatchInlineSnapshot('"[___T`\\`code\\``];"');
62+
expect(result.contents).toMatchInlineSnapshot('"[___T`\\`code\\``];"');
63+
});
6264
});
6365

6466
test('multiple templates', () => {
@@ -199,6 +201,66 @@ describe('Environment: ETI', () => {
199201
);
200202
});
201203

204+
describe('character testing', () => {
205+
test('‘, 💩', () => {
206+
let source = [
207+
`const a = <template>one 💩</template>;`,
208+
`const b = <template>two</template>;`,
209+
`const c = "‘foo’";`,
210+
`const d = <template>four</template>;`,
211+
].join('\n');
212+
213+
let { sourceFile } = applyTransform(source);
214+
215+
expect(sourceFile.text).toMatchInlineSnapshot(`
216+
"const a = [___T\`one 💩\`];
217+
const b = [___T\`two\`];
218+
const c = "‘foo’";
219+
const d = [___T\`four\`];"
220+
`);
221+
});
222+
223+
test('$', () => {
224+
let source = 'const foo = 2;\n\n<template>${{foo}}</template>\n';
225+
let { sourceFile } = applyTransform(source);
226+
227+
expect(sourceFile.text).toMatchInlineSnapshot(`
228+
"const foo = 2;
229+
230+
[___T\`\\\${{foo}}\`]
231+
"
232+
`);
233+
});
234+
235+
test('`', () => {
236+
let source = '<template>`code`</template>;';
237+
let { meta, sourceFile } = applyTransform(source);
238+
let templateNode = (sourceFile.statements[1] as ts.ExpressionStatement).expression;
239+
240+
let start = source.indexOf('<template>');
241+
let contentStart = start + '<template>'.length;
242+
let contentEnd = source.indexOf('</template>');
243+
let end = contentEnd + '</template>'.length;
244+
245+
expect(meta).toEqual(
246+
new Map([
247+
[
248+
templateNode,
249+
{
250+
prepend: 'export default ',
251+
templateLocation: {
252+
start,
253+
contentStart,
254+
contentEnd,
255+
end,
256+
},
257+
},
258+
],
259+
]),
260+
);
261+
});
262+
});
263+
202264
test('single template with satisfies', () => {
203265
let source = stripIndent`
204266
import type { TOC } from '@ember/component/template-only';

test-packages/package-test-core/__tests__/language-server/diagnostic-augmentation.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ describe('Language Server: Diagnostic Augmentation', () => {
3737
expect(diagnostics).toMatchInlineSnapshot();
3838
});
3939

40+
describe('unicode and other special characters', () => {
41+
describe('$', () => {
42+
test('GitHub Issue#840', async () => {
43+
let diagnostics = await requestDiagnostics(
44+
'ts-template-imports-app/src/ephemeral-index.gts',
45+
'glimmer-ts',
46+
[
47+
'const foo = 2;',
48+
// https://github.com/typed-ember/glint/issues/879
49+
'<template>',
50+
' ${{foo}}',
51+
'</template>',
52+
].join('\n'),
53+
);
54+
55+
expect(diagnostics).toMatchInlineSnapshot(`[]`);
56+
});
57+
});
58+
});
59+
4060
test('expected argument count', async () => {
4161
let diagnostics = await requestDiagnostics(
4262
'ts-template-imports-app/src/ephemeral-index.gts',

test-packages/package-test-core/__tests__/transform/rewrite.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,5 +1063,41 @@ describe('Transform: rewriteModule', () => {
10631063
`);
10641064
});
10651065
});
1066+
1067+
describe('unicode and other special characters', () => {
1068+
describe('$', () => {
1069+
test('GitHub Issue#840 - does not error', () => {
1070+
const emberTemplateImportsEnvironment = GlintEnvironment.load(['ember-template-imports']);
1071+
1072+
let script = {
1073+
filename: 'test.gts',
1074+
contents: [
1075+
// https://github.com/typed-ember/glint/issues/879
1076+
'<template>',
1077+
' ${{foo}}',
1078+
'</template>',
1079+
].join('\n'),
1080+
};
1081+
1082+
let transformedModule = rewriteModule(ts, { script }, emberTemplateImportsEnvironment);
1083+
1084+
expect.soft(transformedModule?.errors?.length).toBe(0);
1085+
expect.soft(transformedModule?.errors).toMatchInlineSnapshot(`[]`);
1086+
expect.soft(transformedModule?.transformedContents).toMatchInlineSnapshot(`
1087+
"
1088+
// @ts-expect-error
1089+
({} as typeof import('./__glint-hacky-nonexistent.gts'));
1090+
1091+
// @ts-expect-error
1092+
({} as typeof import('./__glint-hacky-nonexistent.gjs'));
1093+
1094+
export default ({} as typeof import("@glint/environment-ember-template-imports/-private/dsl")).templateExpression(function(__glintRef__, __glintDSL__: typeof import("@glint/environment-ember-template-imports/-private/dsl")) {
1095+
__glintDSL__.emitContent(__glintDSL__.resolveOrReturn(foo)());
1096+
__glintRef__; __glintDSL__;
1097+
})"
1098+
`);
1099+
});
1100+
});
1101+
});
10661102
});
10671103
});

0 commit comments

Comments
 (0)