Path: blob/main/extensions/copilot/src/extension/prompt/test/common/fileTreeParser.spec.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/456import { expect, suite, test } from 'vitest';7import { URI } from '../../../../util/vs/base/common/uri';8import { ChatResponseFileTreePart } from '../../../../vscodeTypes';9import { convertFileTreeToChatResponseFileTree } from '../../common/fileTreeParser';1011suite('convertFileTreeToChatResponseFileTree', () => {12const generatePreviewURI = (filename: string) => URI.file(`/preview/${filename}`);1314test('should convert a simple file tree', () => {15const fileStructure = `16project17├── file1.txt18└── file2.txt19`;2021const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);2223expect(projectName).toBe('project');24expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([25{26name: 'project',27children: [28{ name: 'file1.txt' },29{ name: 'file2.txt' }30]31}32], URI.file('/preview/project')));33});3435test('should handle nested directories', () => {36const fileStructure = `37project38├── dir139│ └── file1.txt40└── dir241└── file2.txt42`;4344const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);4546expect(projectName).toBe('project');47expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([48{49name: 'project',50children: [51{52name: 'dir1',53children: [{ name: 'file1.txt' }]54},55{56name: 'dir2',57children: [{ name: 'file2.txt' }]58}59]60}61], URI.file('/preview/project')));62});6364test('should filter out unwanted files', () => {65const fileStructure = `66project67├── node_modules68├── file1.txt69└── file2.txt70`;7172const { chatResponseTree, projectName } = convertFileTreeToChatResponseFileTree(fileStructure, generatePreviewURI);7374expect(projectName).toBe('project');75expect(chatResponseTree).to.deep.equal(new ChatResponseFileTreePart([76{77name: 'project',78children: [79{ name: 'file1.txt' },80{ name: 'file2.txt' }81]82}83], URI.file('/preview/project')));84});85});868788