Skip to content

Commit

Permalink
test(codeCompletion): expand tests for calculateReplaceRangeBySemiCol…
Browse files Browse the repository at this point in the history
…on to cover various semicolon scenarios
  • Loading branch information
Sma1lboy committed Dec 12, 2024
1 parent 6d9f9b5 commit 289df5d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 8 deletions.
1 change: 0 additions & 1 deletion clients/tabby-agent/src/codeCompletion/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { ConfigData } from "../config/type";
import path from "path";
import hashObject from "object-hash";
import { splitLines, isBlank, regOnlyAutoClosingCloseChars, findUnpairedAutoClosingChars } from "../utils/string";
import { logger } from "./postprocess/base";

export type CompletionRequest = {
filepath: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,117 @@ import { calculateReplaceRangeBySemiColon } from "./calculateReplaceRangeBySemiC
describe("postprocess", () => {
describe("calculateReplaceRangeBySemiColon", () => {
const filter = calculateReplaceRangeBySemiColon;

it("should handle semicolon in string concatenation", async () => {
const context = documentContext`
const content = "hello world";
const a = "nihao" + ║;
`;
const content = "hello world";
const a = "nihao" + ║;
`;
context.language = "typescript";
const completion = {
text: inline`
├content;┤
`,
};
const expected = {
text: inline`
├content;┤
`,
replaceSuffix: ";",
};
await assertFilterResult(filter, context, completion, expected);
});

it("should handle semicolon at the end of a statement", async () => {
const context = documentContext`
const content = "hello world"║;
`;
context.language = "typescript";
const completion = {
text: inline`
├;┤
`,
};
const expected = {
text: inline`
├;┤
`,
replaceSuffix: ";",
};
await assertFilterResult(filter, context, completion, expected);
});

it("should not handle any semicolon at the end of a statement", async () => {
const context = documentContext`
const content = "hello world"║
`;
context.language = "typescript";
const completion = {
text: inline`
├┤
`,
};
const expected = {
text: inline`
├┤
`,
replaceSuffix: "",
};
await assertFilterResult(filter, context, completion, expected);
});

it("should not modify if no semicolon in completion text", async () => {
const context = documentContext`
const content = "hello world"║
`;
context.language = "typescript";
const completion = {
text: inline`
├content┤
`,
};
const expected = {
text: inline`
├content┤
`,
replaceSuffix: "",
};
await assertFilterResult(filter, context, completion, expected);
});

it("should handle multiple semicolons in completion text", async () => {
const context = documentContext`
const content = "hello world"║;
`;
context.language = "typescript";
const completion = {
text: inline`
├content;;┤
`,
};
const expected = {
text: inline`
├content;;┤
`,
replaceSuffix: ";",
};
await assertFilterResult(filter, context, completion, expected);
});

it("should handle semicolon in the middle of a statement", async () => {
const context = documentContext`
const content = "hello; world"║;
`;
context.language = "typescript";
const completion = {
text: inline`
├content;┤
`,
├content;┤
`,
};
const expected = {
text: inline`
├content;┤
`,
├content;┤
`,
replaceSuffix: ";",
};
await assertFilterResult(filter, context, completion, expected);
Expand Down

0 comments on commit 289df5d

Please sign in to comment.