| 1 | /** |
| 2 | * @license |
| 3 | * Copyright 2025 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * NOTICE: This file has been modified from the original Gemini CLI source |
| 7 | * for integration with Continue CLI (cn) |
| 8 | */ |
| 9 | |
| 10 | import { describe, expect, it } from "vitest"; |
| 11 | |
| 12 | import { findLastSafeSplitPoint } from "./messageSplitting.js"; |
| 13 | |
| 14 | describe("markdownUtilities", () => { |
| 15 | describe("findLastSafeSplitPoint", () => { |
| 16 | it("should split at the last double newline if not in a code block", () => { |
| 17 | const content = "paragraph1\n\nparagraph2\n\nparagraph3"; |
| 18 | expect(findLastSafeSplitPoint(content)).toBe(24); // After the second \n\n |
| 19 | }); |
| 20 | |
| 21 | it("should return content.length if no safe split point is found", () => { |
| 22 | const content = "longstringwithoutanysafesplitpoint"; |
| 23 | expect(findLastSafeSplitPoint(content)).toBe(content.length); |
| 24 | }); |
| 25 | |
| 26 | it("should prioritize splitting at \n\n over being at the very end of the string if the end is not in a code block", () => { |
| 27 | const content = "Some text here.\n\nAnd more text here."; |
| 28 | expect(findLastSafeSplitPoint(content)).toBe(17); // after the \n\n |
| 29 | }); |
| 30 | |
| 31 | it("should return content.length if the only \n\n is inside a code block and the end of content is not", () => { |
| 32 | const content = "```\nignore this\n\nnewline\n```KeepThis"; |
| 33 | expect(findLastSafeSplitPoint(content)).toBe(content.length); |
| 34 | }); |
| 35 | |
| 36 | it("should correctly identify the last \n\n even if it is followed by text not in a code block", () => { |
| 37 | const content = |
| 38 | "First part.\n\nSecond part.\n\nThird part, then some more text."; |
| 39 | // Split should be after "Second part.\n\n" |
| 40 | // "First part.\n\n" is 13 chars. "Second part.\n\n" is 14 chars. Total 27. |
| 41 | expect(findLastSafeSplitPoint(content)).toBe(27); |
| 42 | }); |
| 43 | |
| 44 | it("should return content.length if content is empty", () => { |
| 45 | const content = ""; |
| 46 | expect(findLastSafeSplitPoint(content)).toBe(0); |
| 47 | }); |
| 48 | |
| 49 | it("should return content.length if content has no newlines and no code blocks", () => { |
| 50 | const content = "Single line of text"; |
| 51 | expect(findLastSafeSplitPoint(content)).toBe(content.length); |
| 52 | }); |
| 53 | }); |
| 54 | }); |