|
1 | 1 | import type * as babel from '@babel/types'; |
2 | 2 |
|
3 | 3 | import { parseTemplateBindings } from '../src/index.js'; |
4 | | -import type { NGMicrosyntaxKeyedExpression } from '../src/types.js'; |
| 4 | +import type { |
| 5 | + NGMicrosyntaxKeyedExpression, |
| 6 | + NGMicrosyntaxNode, |
| 7 | +} from '../src/types.js'; |
5 | 8 | import { snapshotAst } from './helpers.js'; |
6 | 9 |
|
7 | | -test.each` |
8 | | - input | types |
9 | | - ${''} | ${[]} |
10 | | - ${' let hero '} | ${['NGMicrosyntaxLet']} |
11 | | - ${' let hero = hello '} | ${['NGMicrosyntaxLet']} |
12 | | - ${' let hero of heroes '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression']} |
13 | | - ${' let hero ; of : heroes '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression']} |
14 | | - ${' as b '} | ${['NGMicrosyntaxAs']} |
15 | | - ${' a '} | ${['NGMicrosyntaxExpression']} |
16 | | - ${' a as b '} | ${['NGMicrosyntaxExpression']} |
17 | | - ${' a , b '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKey']} |
18 | | - ${' a ; b '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKey']} |
19 | | - ${' a ; b c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']} |
20 | | - ${' a ; b : c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']} |
21 | | - ${' a ; b : c as d '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']} |
22 | | - ${' a ; b as c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxAs']} |
23 | | - ${' let "a" = "b" ; "c" as "d" '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxAs']} |
24 | | - ${' let "\\"" '} | ${['NGMicrosyntaxLet']} |
25 | | -`('$input', ({ input, types }) => { |
26 | | - const ast = parseTemplateBindings(input); |
27 | | - expect(snapshotAst(ast, input)).toMatchSnapshot(); |
28 | | - expect(ast.body.map((node) => node.type)).toEqual(types); |
29 | | -}); |
| 10 | +const testCases: { |
| 11 | + input: string; |
| 12 | + types: NGMicrosyntaxNode['type'][]; |
| 13 | + only?: true; |
| 14 | +}[] = [ |
| 15 | + { input: '', types: [] }, |
| 16 | + { input: ' let hero ', types: ['NGMicrosyntaxLet'] }, |
| 17 | + { input: ' let hero = hello ', types: ['NGMicrosyntaxLet'] }, |
| 18 | + { |
| 19 | + input: ' let hero of heroes ', |
| 20 | + types: ['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression'], |
| 21 | + }, |
| 22 | + { |
| 23 | + input: ' let hero ; of : heroes ', |
| 24 | + types: ['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression'], |
| 25 | + }, |
| 26 | + { input: ' as b ', types: ['NGMicrosyntaxAs'] }, |
| 27 | + { input: ' a ', types: ['NGMicrosyntaxExpression'] }, |
| 28 | + { input: ' a as b ', types: ['NGMicrosyntaxExpression'] }, |
| 29 | + { input: ' a , b ', types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKey'] }, |
| 30 | + { input: ' a ; b ', types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKey'] }, |
| 31 | + { |
| 32 | + input: ' a ; b c ', |
| 33 | + types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'], |
| 34 | + }, |
| 35 | + { |
| 36 | + input: ' a ; b : c ', |
| 37 | + types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'], |
| 38 | + }, |
| 39 | + { |
| 40 | + input: ' a ; b : c as d ', |
| 41 | + types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'], |
| 42 | + }, |
| 43 | + { |
| 44 | + input: ' a ; b as c ', |
| 45 | + types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxAs'], |
| 46 | + }, |
| 47 | + { |
| 48 | + input: ' let "a" = "b" ; "c" as "d" ', |
| 49 | + types: ['NGMicrosyntaxLet', 'NGMicrosyntaxAs'], |
| 50 | + }, |
| 51 | + { input: ' let "\\"" ', types: ['NGMicrosyntaxLet'] }, |
| 52 | +]; |
| 53 | + |
| 54 | +const IS_CI = Boolean(process.env.CI); |
| 55 | +for (const { input, types, only } of testCases) { |
| 56 | + if (IS_CI && only) { |
| 57 | + throw new Error(`Unexpected 'only' property`); |
| 58 | + } |
| 59 | + |
| 60 | + (only ? test.only : test)(`'${input}'`, () => { |
| 61 | + const ast = parseTemplateBindings(input); |
| 62 | + expect(snapshotAst(ast, input)).toMatchSnapshot(); |
| 63 | + expect(ast.body.map((node) => node.type)).toEqual(types); |
| 64 | + }); |
| 65 | +} |
30 | 66 |
|
31 | 67 | test('Shorthand', () => { |
32 | 68 | const code = 'someTmpl; context: {app}'; |
|
0 commit comments