32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import {
|
|
findSpeechSelectionStartOffset,
|
|
splitSpeechTextIntoChunks,
|
|
} from "./speechStartOptions";
|
|
|
|
describe("findSpeechSelectionStartOffset", () => {
|
|
it("finds the reading start from selected reply text", () => {
|
|
const text = "第一段内容。\n\n第二段 包含空格。\n第三段内容。";
|
|
|
|
expect(findSpeechSelectionStartOffset(text, "第二段 包含空格")).toBe(
|
|
text.indexOf("第二段"),
|
|
);
|
|
expect(findSpeechSelectionStartOffset(text, "第三段")).toBe(text.indexOf("第三段"));
|
|
expect(findSpeechSelectionStartOffset(text, "不存在")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("splitSpeechTextIntoChunks", () => {
|
|
it("splits long text into bounded chunks", () => {
|
|
const text = Array.from({ length: 80 }, (_, index) => `第${index}句内容足够长。`).join("");
|
|
const chunks = splitSpeechTextIntoChunks(text);
|
|
|
|
expect(chunks.length).toBeGreaterThan(1);
|
|
expect(chunks.every((chunk) => chunk.length <= 520)).toBe(true);
|
|
expect(chunks.join("")).toBe(text);
|
|
});
|
|
|
|
it("keeps short text as one chunk", () => {
|
|
expect(splitSpeechTextIntoChunks("短句。")).toEqual(["短句。"]);
|
|
});
|
|
});
|