mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-11-30 19:26:59 +08:00
* chore: remove code only tests used - AppCountBar, AppToggleGroup, ManagementListSearch and utils/tomlUtils have no production importer; drop them with their tests. - Drop test-only exports: sumSpeedTotals, useSessionMessagesQuery (and its @/lib/query re-export), OMO_SLIM_DISABLEABLE_AGENTS, and the re-exports of flattenModels/formatPrice and HERMES_PROVIDER_SOURCE_*; tests import from the defining modules. - Drop the unused i18n key sessionManager.reader.exportShort. - env_checker scans shell rc files under get_home_dir() instead of $HOME, so it follows the same home (and test-home) as everything else. * chore(sessions): remove the unused reveal-path overrides sessionsApi.revealPath duplicated what PathChip already invokes, and SessionMarkdown's onRevealPath / PathChip's onReveal were only ever passed by tests. The Show in Finder button keeps calling reveal_session_path; the test now checks that command instead of the override.
67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { parse as parseToml } from "smol-toml";
|
||
import { describe, expect, it } from "vitest";
|
||
import { normalizeTomlText } from "@/utils/textNormalization";
|
||
|
||
describe("normalizeTomlText", () => {
|
||
it("normalizes smart quotes used as string delimiters", () => {
|
||
expect(normalizeTomlText("command = “npx”\nargs = [‘-y’]")).toBe(
|
||
"command = \"npx\"\nargs = ['-y']",
|
||
);
|
||
expect(normalizeTomlText("[mcp_servers."demo"]")).toBe(
|
||
'[mcp_servers."demo"]',
|
||
);
|
||
});
|
||
|
||
it("keeps smart quotes inside strings opened by ASCII quotes", () => {
|
||
const input = [
|
||
'a = "don’t"',
|
||
'b = "say“hello”"',
|
||
"c = 'don’t'",
|
||
'd = """multi “line” ’text’"""',
|
||
"e = '''it’s'''",
|
||
'f = "escaped \\" then “x”"',
|
||
].join("\n");
|
||
expect(normalizeTomlText(input)).toBe(input);
|
||
});
|
||
|
||
it("keeps quotes of the other family inside smart-quoted strings", () => {
|
||
expect(normalizeTomlText("a = “don’t”")).toBe('a = "don’t"');
|
||
expect(parseToml(normalizeTomlText("a = “don’t”")).a).toBe("don’t");
|
||
});
|
||
|
||
it("closes an ASCII-opened string with a smart quote when nothing else closes it", () => {
|
||
// 编辑器逐字归一化后,输入法打出的左引号已是 ASCII,右引号仍是弯引号
|
||
expect(normalizeTomlText('model = "gpt”\nx = 1')).toBe(
|
||
'model = "gpt"\nx = 1',
|
||
);
|
||
expect(normalizeTomlText("name = 'abc’")).toBe("name = 'abc'");
|
||
});
|
||
|
||
it("repairs smart closers that are followed by more ASCII quotes on the line", () => {
|
||
// 合法文档不会走到这里:只有严格结果解析失败时才把字符串里的弯引号当闭合符
|
||
expect(normalizeTomlText('args = ["npx”, "-y"]')).toBe(
|
||
'args = ["npx", "-y"]',
|
||
);
|
||
expect(normalizeTomlText('model = "gpt” # "example"')).toBe(
|
||
'model = "gpt" # "example"',
|
||
);
|
||
});
|
||
|
||
it("turns escaped smart double quotes into ASCII escapes", () => {
|
||
const normalized = normalizeTomlText("args = [“say \\“hello\\””]");
|
||
expect(normalized).toBe('args = ["say \\"hello\\""]');
|
||
expect(parseToml(normalized).args).toEqual(['say "hello"']);
|
||
});
|
||
|
||
it("leaves comments untouched", () => {
|
||
const input = "# “comment” it’s\nkey = “v” # don’t";
|
||
expect(normalizeTomlText(input)).toBe(
|
||
'# “comment” it’s\nkey = "v" # don’t',
|
||
);
|
||
});
|
||
|
||
it("does not touch unterminated strings beyond their opening quote", () => {
|
||
expect(normalizeTomlText("x = “abc")).toBe('x = "abc');
|
||
});
|
||
});
|