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.java.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 - java', () => {
16
17
afterAll(() => _dispose());
18
19
async function run(annotatedSrc: string) {
20
return srcWithAnnotatedNodeToDoc(
21
WASMLanguage.Java,
22
annotatedSrc,
23
);
24
}
25
26
test('should return root node for empty source', async () => {
27
28
const result = await run('<<>>');
29
30
expect(result).toMatchInlineSnapshot(`"<PROGRAM></PROGRAM>"`);
31
});
32
33
34
test('use correct identifier name for a method', async () => {
35
const result = await run(
36
outdent`
37
package com.mycompany.app;
38
39
public class MyMath
40
{
41
public String check<<>>Sign(int number) {
42
if ( number > 0 ) {
43
return "positive";
44
} else if ( number < 0 ) {
45
return "negative";
46
} else {
47
throw new IllegalArgumentException("Number had no sign");
48
}
49
}
50
51
/**
52
* Reverses the sign of a given number
53
* @param number the input number
54
* @return a number with reversed sign
55
*/
56
public int reverseNumber(int number) {
57
return -number;
58
}
59
}
60
`,
61
);
62
expect(result).toMatchInlineSnapshot(`
63
"package com.mycompany.app;
64
65
public class MyMath
66
{
67
<METHOD_DECLARATION>public String <IDENT>checkSign</IDENT>(int number) {
68
if ( number > 0 ) {
69
return "positive";
70
} else if ( number < 0 ) {
71
return "negative";
72
} else {
73
throw new IllegalArgumentException("Number had no sign");
74
}
75
}</METHOD_DECLARATION>
76
77
/**
78
* Reverses the sign of a given number
79
* @param number the input number
80
* @return a number with reversed sign
81
*/
82
public int reverseNumber(int number) {
83
return -number;
84
}
85
}"
86
`);
87
});
88
});
89
90