diff --git a/.continue/prompts/core-util-test.prompt b/.continue/prompts/core-unit-test.prompt similarity index 93% rename from .continue/prompts/core-util-test.prompt rename to .continue/prompts/core-unit-test.prompt index 84aad3bd8..88c95ff06 100644 --- a/.continue/prompts/core-util-test.prompt +++ b/.continue/prompts/core-unit-test.prompt @@ -27,6 +27,7 @@ Jest testing setup includes - import `testConfigHandler` for any ConfigHandler needs - import `testControlPlaneClient` for control plane operations - import `ideSettingsPromise` for any IdeSettings needs +- import `getTestLLM` for any ILLM/BaseLLM needs. Set the `completion` property to the desired completion, e.g. `const llm = await getTestLLM(); llm.completion = "Desired completion";` Do NOT write tests for any files in `core/test`, only use them as helpers for testing other files. If no other files are provided, warn the user and write no tests. diff --git a/core/test/fixtures.ts b/core/test/fixtures.ts index add71d029..42dd6e6c9 100644 --- a/core/test/fixtures.ts +++ b/core/test/fixtures.ts @@ -1,5 +1,6 @@ import { ConfigHandler } from "../config/ConfigHandler"; import { ControlPlaneClient } from "../control-plane/client"; +import { llmFromDescription } from "../llm/llms"; import FileSystemIde from "../util/filesystem"; import { TEST_DIR } from "./testDir"; @@ -18,3 +19,24 @@ export const testConfigHandler = new ConfigHandler( async (text) => {}, testControlPlaneClient, ); + +export const getTestLLM = async () => { + const ideSettings = await ideSettingsPromise; + const config = await testConfigHandler.loadConfig(); + const uniqueId = await testIde.getUniqueId(); + return await llmFromDescription( + { + provider: "mock", + title: "Mock Model", + model: "mock-model", + }, + testIde.readFile.bind(testIde), + uniqueId, + ideSettings, + async (log: string) => { + console.log(log); + }, + config.completionOptions, + config.systemMessage, + ); +}; diff --git a/core/util/dedent.test.ts b/core/util/dedent.test.ts deleted file mode 100644 index 95908ab4a..000000000 --- a/core/util/dedent.test.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { dedent } from "./index"; - -describe("dedent function", () => { - it("should remove common leading whitespace from all lines", () => { - const result = dedent` - Hello - World - ! - `; - expect(result).toBe("Hello\n World\n !"); - }); - - it("should handle strings with no indentation", () => { - const result = dedent`Hello -World -!`; - expect(result).toBe("Hello\nWorld\n!"); - }); - - it("should handle strings with mixed indentation", () => { - const result = dedent` - Hello - World - ! - `; - expect(result).toBe(" Hello\nWorld\n !"); - }); - - it("should remove leading and trailing empty lines", () => { - const result = dedent` - - Hello - World - - `; - expect(result).toBe("Hello\nWorld"); - }); - - it("should handle empty strings", () => { - const result = dedent``; - expect(result).toBe(""); - }); - - it("should handle strings with only whitespace", () => { - const result = dedent` - - `; - expect(result).toBe(""); - }); - - it.skip("should handle strings with tabs", () => { - const result = dedent` - \tHello - \t\tWorld - \t\t\t! -`; - expect(result).toBe("\tHello\n\t\tWorld\n\t\t\t!"); - }); - - it("should handle interpolated values", () => { - const world = "World"; - const result = dedent` - Hello ${world} - How are you? - `; - expect(result).toBe("Hello World\n How are you?"); - }); - - it("should handle multiple interpolated values", () => { - const greeting = "Hello"; - const name = "Alice"; - const question = "How are you?"; - const result = dedent` - ${greeting} ${name} - ${question} - `; - expect(result).toBe("Hello Alice\n How are you?"); - }); - - it("should handle interpolated values with different indentation", () => { - const value1 = "foo"; - const value2 = "bar"; - const result = dedent` - ${value1} - ${value2} - `; - expect(result).toBe("foo\n bar"); - }); - - it("should handle a single line with indentation", () => { - const result = dedent` Hello World!`; - expect(result).toBe("Hello World!"); - }); - - it("should handle a string with only one non-empty line", () => { - const result = dedent` - - Hello World! - - `; - expect(result).toBe("Hello World!"); - }); - - it("should handle a string with Unicode characters", () => { - const result = dedent` - こんにちは - 世界 - `; - expect(result).toBe("こんにちは\n 世界"); - }); - - it("should handle a string with emoji", () => { - const result = dedent` - 🌍 - 🌎 - 🌏 - `; - expect(result).toBe("🌍\n 🌎\n 🌏"); - }); - - it.skip("should handle a string with CRLF line endings", () => { - const result = dedent` - Hello\r - World\r - `; - expect(result).toBe("Hello\r\n World"); - }); - - it("should not count empty lines in the minimum indentation", () => { - const result = dedent` - Hello - - World - `; - - expect(result).toBe("Hello\n\nWorld"); - }); - - it("should work with templated strings", () => { - const language = "typescript"; - const code = "console.log('hello');\nconsole.log('world');"; - - const result = dedent` - This is the prefix of the file: - \`\`\`${language} - ${code} - \`\`\``; - - expect(result).toBe(`\ -This is the prefix of the file: -\`\`\`${language} -${code} -\`\`\``); - }); -}); diff --git a/core/util/index.test.ts b/core/util/index.test.ts index 0d618069c..8f8659103 100644 --- a/core/util/index.test.ts +++ b/core/util/index.test.ts @@ -1,5 +1,6 @@ // File generated by Continue import { + dedent, dedentAndGetCommonWhitespace, deduplicateArray, getLastNPathParts, @@ -198,3 +199,157 @@ describe("dedentAndGetCommonWhitespace", () => { expect(output).toEqual([" line1\nline2\n line3", " "]); }); }); + +describe("dedent function", () => { + it("should remove common leading whitespace from all lines", () => { + const result = dedent` + Hello + World + ! + `; + expect(result).toBe("Hello\n World\n !"); + }); + + it("should handle strings with no indentation", () => { + const result = dedent`Hello +World +!`; + expect(result).toBe("Hello\nWorld\n!"); + }); + + it("should handle strings with mixed indentation", () => { + const result = dedent` + Hello + World + ! + `; + expect(result).toBe(" Hello\nWorld\n !"); + }); + + it("should remove leading and trailing empty lines", () => { + const result = dedent` + + Hello + World + + `; + expect(result).toBe("Hello\nWorld"); + }); + + it("should handle empty strings", () => { + const result = dedent``; + expect(result).toBe(""); + }); + + it("should handle strings with only whitespace", () => { + const result = dedent` + + `; + expect(result).toBe(""); + }); + + it.skip("should handle strings with tabs", () => { + const result = dedent` + \tHello + \t\tWorld + \t\t\t! +`; + expect(result).toBe("\tHello\n\t\tWorld\n\t\t\t!"); + }); + + it("should handle interpolated values", () => { + const world = "World"; + const result = dedent` + Hello ${world} + How are you? + `; + expect(result).toBe("Hello World\n How are you?"); + }); + + it("should handle multiple interpolated values", () => { + const greeting = "Hello"; + const name = "Alice"; + const question = "How are you?"; + const result = dedent` + ${greeting} ${name} + ${question} + `; + expect(result).toBe("Hello Alice\n How are you?"); + }); + + it("should handle interpolated values with different indentation", () => { + const value1 = "foo"; + const value2 = "bar"; + const result = dedent` + ${value1} + ${value2} + `; + expect(result).toBe("foo\n bar"); + }); + + it("should handle a single line with indentation", () => { + const result = dedent` Hello World!`; + expect(result).toBe("Hello World!"); + }); + + it("should handle a string with only one non-empty line", () => { + const result = dedent` + + Hello World! + + `; + expect(result).toBe("Hello World!"); + }); + + it("should handle a string with Unicode characters", () => { + const result = dedent` + こんにちは + 世界 + `; + expect(result).toBe("こんにちは\n 世界"); + }); + + it("should handle a string with emoji", () => { + const result = dedent` + 🌍 + 🌎 + 🌏 + `; + expect(result).toBe("🌍\n 🌎\n 🌏"); + }); + + it.skip("should handle a string with CRLF line endings", () => { + const result = dedent` + Hello\r + World\r + `; + expect(result).toBe("Hello\r\n World"); + }); + + it("should not count empty lines in the minimum indentation", () => { + const result = dedent` + Hello + + World + `; + + expect(result).toBe("Hello\n\nWorld"); + }); + + it("should work with templated strings", () => { + const language = "typescript"; + const code = "console.log('hello');\nconsole.log('world');"; + + const result = dedent` + This is the prefix of the file: + \`\`\`${language} + ${code} + \`\`\``; + + expect(result).toBe(`\ +This is the prefix of the file: +\`\`\`${language} +${code} +\`\`\``); + }); +});