Elffuss BraidHub

kikocis/continue public

main · 2.7 KiBRawPermalink
1// Generated by continue
2// core/indexing/chunk/basic.test.ts
3
4import { basicChunker } from "./basic.js";
5import { countTokensAsync } from "../../llm/countTokens";
6import { ChunkWithoutID } from "../../index";
7
8// jest.mock("../../llm/countTokens", () => ({
9// countTokensAsync: jest.fn(),
10// }));
11
12describe.skip("basicChunker", () => {
13 beforeEach(() => {
14 jest.resetAllMocks();
15 });
16
17 it("should yield no chunks for empty content", async () => {
18 const contents = "";
19 const maxChunkSize = 10;
20 const chunks: ChunkWithoutID[] = [];
21
22 for await (const chunk of basicChunker(contents, maxChunkSize)) {
23 chunks.push(chunk);
24 }
25
26 expect(chunks).toHaveLength(0);
27 });
28
29 it("should yield a single chunk if whole content fits within the max size", async () => {
30 (countTokensAsync as jest.Mock).mockResolvedValue(1);
31 const contents = "line1\nline2\nline3";
32 const maxChunkSize = 10;
33 const expectedChunks: ChunkWithoutID[] = [
34 { content: "line1\nline2\nline3\n", startLine: 0, endLine: 2 },
35 ];
36
37 const chunks: ChunkWithoutID[] = [];
38 for await (const chunk of basicChunker(contents, maxChunkSize)) {
39 chunks.push(chunk);
40 }
41
42 expect(chunks).toEqual(expectedChunks);
43 });
44
45 it("should yield multiple chunks when content exceeds the max size", async () => {
46 (countTokensAsync as jest.Mock).mockImplementation(async (line: string) => {
47 if (line === "line3") return 5;
48 return 3; // Mock returning 3 tokens per line except for "line3"
49 });
50
51 const contents = "line1\nline2\nline3\nline4\nline5";
52 const maxChunkSize = 8;
53 const expectedChunks: ChunkWithoutID[] = [
54 { content: "line1\nline2\n", startLine: 0, endLine: 1 },
55 { content: "line3\n", startLine: 2, endLine: 2 },
56 { content: "line4\nline5\n", startLine: 3, endLine: 4 },
57 ];
58
59 const chunks: ChunkWithoutID[] = [];
60 for await (const chunk of basicChunker(contents, maxChunkSize)) {
61 chunks.push(chunk);
62 }
63
64 expect(chunks).toEqual(expectedChunks);
65 });
66
67 it("should skip lines that exceed the max chunk size", async () => {
68 (countTokensAsync as jest.Mock).mockImplementation(async (line: string) => {
69 if (line === "line3") return 15; // Making it explicitly exceed max size
70 return 3;
71 });
72
73 const contents = "line1\nline2\nline3\nline4\nline5";
74 const maxChunkSize = 8;
75 const expectedChunks: ChunkWithoutID[] = [
76 { content: "line1\nline2\n", startLine: 0, endLine: 1 },
77 { content: "line4\nline5\n", startLine: 3, endLine: 4 },
78 ];
79
80 const chunks: ChunkWithoutID[] = [];
81 for await (const chunk of basicChunker(contents, maxChunkSize)) {
82 chunks.push(chunk);
83 }
84
85 expect(chunks).toEqual(expectedChunks);
86 });
87});