prompt file iteration
This commit is contained in:
parent
2891566920
commit
68dfb3b46a
4 changed files with 178 additions and 155 deletions
|
|
@ -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.
|
||||
|
||||
|
|
@ -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,
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
\`\`\``);
|
||||
});
|
||||
});
|
||||
|
|
@ -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}
|
||||
\`\`\``);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue