Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/test/common/fileTreeParser.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
7
import { expect, suite, test } from 'vitest';
8
import { URI } from '../../../../util/vs/base/common/uri';
9
import { ChatResponseFileTreePart } from '../../../../vscodeTypes';
10
import { convertFileTreeToChatResponseFileTree } from '../../common/fileTreeParser';
11
12
suite('convertFileTreeToChatResponseFileTree', () => {
13
const generatePreviewURI = (filename: string) => URI.file(`/preview/${filename}`);
14
15
test('should convert a simple file tree', () => {
16
const fileStructure = `
17
project
18
├── file1.txt
19
└── file2.txt
20
`;
21
22
const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);
23
24
expect(projectName).toBe('project');
25
expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([
26
{
27
name: 'project',
28
children: [
29
{ name: 'file1.txt' },
30
{ name: 'file2.txt' }
31
]
32
}
33
], URI.file('/preview/project')));
34
});
35
36
test('should handle nested directories', () => {
37
const fileStructure = `
38
project
39
├── dir1
40
│ └── file1.txt
41
└── dir2
42
└── file2.txt
43
`;
44
45
const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);
46
47
expect(projectName).toBe('project');
48
expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([
49
{
50
name: 'project',
51
children: [
52
{
53
name: 'dir1',
54
children: [{ name: 'file1.txt' }]
55
},
56
{
57
name: 'dir2',
58
children: [{ name: 'file2.txt' }]
59
}
60
]
61
}
62
], URI.file('/preview/project')));
63
});
64
65
test('should filter out unwanted files', () => {
66
const fileStructure = `
67
project
68
├── node_modules
69
├── file1.txt
70
└── file2.txt
71
`;
72
73
const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);
74
75
expect(projectName).toBe('project');
76
expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([
77
{
78
name: 'project',
79
children: [
80
{ name: 'file1.txt' },
81
{ name: 'file2.txt' }
82
]
83
}
84
], URI.file('/preview/project')));
85
});
86
});
87
88