|
5 | 5 | ******************************************************************************/ |
6 | 6 |
|
7 | 7 | import { describe, expect, test } from 'vitest'; |
| 8 | +import type { AstNode, Reference } from 'langium'; |
8 | 9 | import { AstUtils, EmptyFileSystem, GrammarAST } from 'langium'; |
9 | 10 | import { createLangiumGrammarServices } from 'langium/grammar'; |
10 | 11 |
|
| 12 | +interface TestNode extends AstNode { |
| 13 | + readonly $type: 'MyType'; |
| 14 | + readonly $container?: TestNode; |
| 15 | + str: string; |
| 16 | + strArr: string[] |
| 17 | + optStr?: string; |
| 18 | + optStrArr?: string[]; |
| 19 | + bool: boolean; |
| 20 | + boolArr: boolean[]; |
| 21 | + optBool?: boolean; |
| 22 | + optBoolArr?: boolean[]; |
| 23 | + int: number; |
| 24 | + intArr: number[]; |
| 25 | + optInt?: number; |
| 26 | + optIntArr?: number[]; |
| 27 | + ref: Reference<TestNode>; |
| 28 | + refArr: Array<Reference<TestNode>>; |
| 29 | + optRef?: Reference<TestNode>; |
| 30 | + optRefArr?: Array<Reference<TestNode>>; |
| 31 | + ctn: TestNode; |
| 32 | + ctnArr: TestNode[]; |
| 33 | + optCtn?: TestNode; |
| 34 | + optCtnArr?: PartialTestNode[]; |
| 35 | +} |
| 36 | + |
| 37 | +interface PartialTestNode extends AstNode { |
| 38 | + readonly $type: 'MyType'; |
| 39 | + readonly $container?: PartialTestNode; |
| 40 | + str?: string; |
| 41 | + strArr: string[] |
| 42 | + optStr?: string; |
| 43 | + optStrArr?: string[]; |
| 44 | + bool: boolean; |
| 45 | + boolArr: boolean[]; |
| 46 | + optBool?: boolean; |
| 47 | + optBoolArr?: boolean[]; |
| 48 | + int?: number; |
| 49 | + intArr: number[]; |
| 50 | + optInt?: number; |
| 51 | + optIntArr?: number[]; |
| 52 | + ref?: Reference<PartialTestNode>; |
| 53 | + refArr: Array<Reference<PartialTestNode>>; |
| 54 | + optRef?: Reference<PartialTestNode>; |
| 55 | + optRefArr?: Array<Reference<PartialTestNode>>; |
| 56 | + ctn?: PartialTestNode; |
| 57 | + ctnArr: PartialTestNode[]; |
| 58 | + optCtn?: PartialTestNode; |
| 59 | + optCtnArr?: PartialTestNode[]; |
| 60 | +} |
| 61 | +export const expectType = <Type>(_: Type): void => void 0; |
| 62 | + |
11 | 63 | describe('AST Utils', () => { |
12 | 64 |
|
13 | 65 | test('Streaming ast works with range', () => { |
@@ -41,4 +93,9 @@ describe('AST Utils', () => { |
41 | 93 | expect(names).toEqual(['OverlapBefore', 'Inside', 'OverlapAfter']); |
42 | 94 | }); |
43 | 95 |
|
| 96 | + test('should transform DeepPartialAstNode<TestNode> to PartialTestNode', () => { |
| 97 | + type ResultType = AstUtils.DeepPartialAstNode<TestNode>; |
| 98 | + expectType<PartialTestNode>((null as unknown) as ResultType); |
| 99 | + expectType<ResultType>((null as unknown) as PartialTestNode); |
| 100 | + }); |
44 | 101 | }); |
0 commit comments