|
1 | 1 | import { describe, it, expect, beforeEach, vi } from "vitest" |
2 | | -import * as fs from "node:fs" |
3 | | -import * as path from "node:path" |
4 | 2 | import { MockWorkspace } from "./MockWorkspace" |
5 | 3 | import * as vscode from "vscode" |
6 | 4 | import { GhostStreamingParser } from "../GhostStreamingParser" |
@@ -123,107 +121,6 @@ describe("GhostProvider", () => { |
123 | 121 | return { testUri, context, mockDocument } |
124 | 122 | } |
125 | 123 |
|
126 | | - // Test cases directory for file-based tests |
127 | | - const TEST_CASES_DIR = path.join(__dirname, "__test_cases__") |
128 | | - |
129 | | - // Helper function to run file-based tests |
130 | | - async function runFileBasedTest(testCaseName: string) { |
131 | | - const testCasePath = path.join(TEST_CASES_DIR, testCaseName) |
132 | | - const inputFilePath = path.join(testCasePath, "input.js") |
133 | | - const diffFilePath = path.join(testCasePath, "response.txt") |
134 | | - const expectedFilePath = path.join(testCasePath, "expected.js") |
135 | | - |
136 | | - const initialContent = fs.readFileSync(inputFilePath, "utf8") |
137 | | - // Read the response file |
138 | | - const response = fs.readFileSync(diffFilePath, "utf8") |
139 | | - const expectedContent = fs.readFileSync(expectedFilePath, "utf8") |
140 | | - |
141 | | - const { testUri, context, mockDocument } = await setupTestDocument(`${testCaseName}/input.js`, initialContent) |
142 | | - |
143 | | - // Parse and apply suggestions |
144 | | - streamingParser.initialize(context) |
145 | | - const parseResult = streamingParser.parseResponse(response, "", "") |
146 | | - |
147 | | - // Apply the changes if we have suggestions |
148 | | - if (parseResult.hasNewSuggestions) { |
149 | | - const fillInSuggestion = parseResult.suggestions.getFillInAtCursor() |
150 | | - if (fillInSuggestion) { |
151 | | - // For FIM (Fill-In-Middle) suggestions, reconstruct the full content |
152 | | - const newContent = fillInSuggestion.prefix + fillInSuggestion.text + fillInSuggestion.suffix |
153 | | - ;(mockDocument as any).updateContent(newContent) |
154 | | - } |
155 | | - } |
156 | | - |
157 | | - const finalContent = mockWorkspace.getDocumentContent(testUri) |
158 | | - // Compare the normalized content |
159 | | - const normalizedFinal = normalizeWhitespace(finalContent) |
160 | | - const normalizedExpected = normalizeWhitespace(expectedContent) |
161 | | - |
162 | | - // For certain tests, we need special handling due to formatting differences |
163 | | - if (testCaseName === "complex-multi-group") { |
164 | | - // For complex-multi-group, normalize the function and comment order |
165 | | - const normalizedForComparison = (content: string) => { |
166 | | - // Remove all whitespace and normalize function declarations with comments |
167 | | - return content.replace(/\/\/\s*([^\n]+)\s*([a-zA-Z]+\([^)]*\))\s*{/g, "$2 { // $1").replace(/\s+/g, "") |
168 | | - } |
169 | | - |
170 | | - const processedFinal = normalizedForComparison(normalizedFinal) |
171 | | - const processedExpected = normalizedForComparison(normalizedExpected) |
172 | | - expect(processedFinal).toBe(processedExpected) |
173 | | - } else if (testCaseName === "partial-mixed-operations") { |
174 | | - // For partial-mixed-operations, compare without whitespace |
175 | | - const strippedFinal = normalizedFinal.replace(/\s+/g, "") |
176 | | - const strippedExpected = normalizedExpected.replace(/\s+/g, "") |
177 | | - expect(strippedFinal).toBe(strippedExpected) |
178 | | - } else { |
179 | | - expect(normalizedFinal).toBe(normalizedExpected) |
180 | | - } |
181 | | - } |
182 | | - |
183 | | - describe("File-based Suggestions", () => { |
184 | | - it("should apply a simple addition from files", async () => { |
185 | | - await runFileBasedTest("simple-addition") |
186 | | - }) |
187 | | - |
188 | | - it("should apply multiple line additions from files", async () => { |
189 | | - await runFileBasedTest("multiple-line-additions") |
190 | | - }) |
191 | | - |
192 | | - it("should apply line deletions from files", async () => { |
193 | | - await runFileBasedTest("line-deletions") |
194 | | - }) |
195 | | - |
196 | | - it("should apply mixed addition and deletion from files", async () => { |
197 | | - await runFileBasedTest("mixed-addition-deletion") |
198 | | - }) |
199 | | - |
200 | | - it("should handle empty diff response from files", async () => { |
201 | | - await runFileBasedTest("empty-diff-response") |
202 | | - }) |
203 | | - |
204 | | - it("should apply function rename and var to const changes from files", async () => { |
205 | | - await runFileBasedTest("function-rename-var-to-const") |
206 | | - }) |
207 | | - }) |
208 | | - |
209 | | - describe("Sequential application", () => { |
210 | | - it("should handle an inverse individual application of mixed operations", async () => { |
211 | | - await runFileBasedTest("sequential-mixed-operations") |
212 | | - }) |
213 | | - |
214 | | - it("should handle sequential partial application of mixed operations", async () => { |
215 | | - await runFileBasedTest("partial-mixed-operations") |
216 | | - }) |
217 | | - |
218 | | - it("should handle random individual application of mixed operations", async () => { |
219 | | - await runFileBasedTest("random-mixed-operations") |
220 | | - }) |
221 | | - |
222 | | - it("should handle complex multi-group operations", async () => { |
223 | | - await runFileBasedTest("complex-multi-group") |
224 | | - }) |
225 | | - }) |
226 | | - |
227 | 124 | describe("Error Handling", () => { |
228 | 125 | it("should handle empty diff responses", async () => { |
229 | 126 | const initialContent = `console.log('test');` |
|
0 commit comments