mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 11:21:07 +00:00
test: dedupe utility and config suites
This commit is contained in:
@@ -2,6 +2,19 @@ import { describe, expect, it } from "vitest";
|
||||
import { stripReasoningTagsFromText } from "./reasoning-tags.js";
|
||||
|
||||
describe("stripReasoningTagsFromText", () => {
|
||||
const expectStrippedCases = (
|
||||
cases: ReadonlyArray<{
|
||||
input: string;
|
||||
expected: string;
|
||||
opts?: Parameters<typeof stripReasoningTagsFromText>[1];
|
||||
name?: string;
|
||||
}>,
|
||||
) => {
|
||||
for (const { input, expected, opts, name } of cases) {
|
||||
expect(stripReasoningTagsFromText(input, opts), name).toBe(expected);
|
||||
}
|
||||
};
|
||||
|
||||
describe("basic functionality", () => {
|
||||
it("returns text unchanged when no reasoning tags present", () => {
|
||||
const input = "Hello, this is a normal message.";
|
||||
@@ -27,9 +40,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
expected: "X Y",
|
||||
},
|
||||
] as const;
|
||||
for (const { name, input, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input), name).toBe(expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
|
||||
it("strips multiple reasoning blocks", () => {
|
||||
@@ -65,9 +76,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
expected: "```\n<think>code</think>\n```\nvisible",
|
||||
},
|
||||
] as const;
|
||||
for (const { input, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input)).toBe(expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -127,9 +136,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
expected: "Start `unclosed end",
|
||||
},
|
||||
] as const;
|
||||
for (const { input, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input)).toBe(expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
|
||||
it("handles nested and final tag behavior", () => {
|
||||
@@ -151,9 +158,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
expected: "A visible B",
|
||||
},
|
||||
] as const;
|
||||
for (const { input, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input)).toBe(expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
|
||||
it("handles unicode, attributes, and case-insensitive tag names", () => {
|
||||
@@ -171,9 +176,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
expected: "A B",
|
||||
},
|
||||
] as const;
|
||||
for (const { input, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input)).toBe(expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
|
||||
it("handles long content and pathological backtick patterns efficiently", () => {
|
||||
@@ -194,7 +197,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
const cases = [
|
||||
{ mode: "strict" as const, expected: "Before" },
|
||||
{ mode: "preserve" as const, expected: "Before unclosed content after" },
|
||||
];
|
||||
] as const;
|
||||
for (const { mode, expected } of cases) {
|
||||
expect(stripReasoningTagsFromText(input, { mode })).toBe(expected);
|
||||
}
|
||||
@@ -226,9 +229,7 @@ describe("stripReasoningTagsFromText", () => {
|
||||
opts: { trim: "start" as const },
|
||||
},
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
expect(stripReasoningTagsFromText(testCase.input, testCase.opts)).toBe(testCase.expected);
|
||||
}
|
||||
expectStrippedCases(cases);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user