Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/parser/test/node/getNodeToDocument.cpp.spec.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { outdent } from 'outdent';
7
import { afterAll, expect, suite, test } from 'vitest';
8
import {
9
_dispose
10
} from '../../node/parserImpl';
11
import { WASMLanguage } from '../../node/treeSitterLanguages';
12
import { srcWithAnnotatedNodeToDoc } from './getNodeToDocument.util';
13
14
15
suite('getNodeToDocument - cpp', () => {
16
17
afterAll(() => _dispose());
18
19
async function run(annotatedSrc: string, includeSelection = false) {
20
return srcWithAnnotatedNodeToDoc(
21
WASMLanguage.Cpp,
22
annotatedSrc,
23
includeSelection,
24
);
25
}
26
27
test('basic function', async () => {
28
const result = await run(
29
outdent`
30
void foo() {
31
<<>>
32
}
33
`,
34
true
35
);
36
expect(result).toMatchInlineSnapshot(`
37
"<FUNCTION_DEFINITION>void <IDENT>foo</IDENT>() {
38
<SELECTION></SELECTION>
39
}</FUNCTION_DEFINITION>"
40
`);
41
});
42
43
test('function with qualified identifier and qualified return type - selection in body', async () => {
44
const result = await run(
45
outdent`
46
Foo::Bar baz::foo() {
47
<<>>
48
}
49
`,
50
true
51
);
52
expect(result).toMatchInlineSnapshot(`
53
"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {
54
<SELECTION></SELECTION>
55
}</FUNCTION_DEFINITION>"
56
`);
57
});
58
59
test('function with qualified identifier and qualified return type - selection on return type', async () => {
60
const result = await run(
61
outdent`
62
<<Foo::Bar>> baz::foo() {
63
64
}
65
`
66
);
67
expect(result).toMatchInlineSnapshot(`
68
"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {
69
70
}</FUNCTION_DEFINITION>"
71
`);
72
});
73
74
test('function with qualified identifier and qualified return type - selection on function qualified identifier', async () => {
75
const result = await run(
76
outdent`
77
Foo::Bar baz<<>>::foo() {
78
79
}
80
`
81
);
82
expect(result).toMatchInlineSnapshot(`
83
"<FUNCTION_DEFINITION>Foo::Bar <IDENT>baz::foo</IDENT>() {
84
85
}</FUNCTION_DEFINITION>"
86
`);
87
});
88
});
89
90