2026-01-18 10:34:45 +09:00
|
|
|
const snippets = [
|
|
|
|
|
{
|
|
|
|
|
name: "Should ignore single trailing space after han before New Line before han",
|
2026-06-16 04:40:39 +08:00
|
|
|
code: Array.from(
|
|
|
|
|
{ length: 6 },
|
2026-01-18 10:34:45 +09:00
|
|
|
// less "文" <= [..., "文...文 ", "文...文", ...] => more "文"
|
2026-06-16 04:40:39 +08:00
|
|
|
(_, i) => ["文".repeat(39 + (i >> 1)), i & 1 ? "" : " "],
|
|
|
|
|
)
|
2026-01-18 10:34:45 +09:00
|
|
|
// ["<Line #1>", "<L2>", ...]
|
|
|
|
|
.reduce(
|
|
|
|
|
(previousInputLines, [base, space]) => [
|
|
|
|
|
...previousInputLines,
|
|
|
|
|
`${base}${space}\n`,
|
|
|
|
|
],
|
|
|
|
|
[],
|
|
|
|
|
)
|
|
|
|
|
.join(""),
|
|
|
|
|
// (39 + 40 + 41) * 2 === 40 * 3 * 2 === 40 * 6
|
|
|
|
|
// lineWidth is 80 and "文" is double-width
|
|
|
|
|
// This is being saved for after Chrome and Safari bug is fixed.
|
2026-10-04 12:20:28 +09:00
|
|
|
get output() {
|
|
|
|
|
/* `${"文".repeat(40)}\n`.repeat(6) */
|
|
|
|
|
return this.code.replace(/ (?=\n)/g, "");
|
|
|
|
|
},
|
2026-01-18 10:34:45 +09:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Switches to insert-space (2.x-style) mode
|
|
|
|
|
const afterword = "测试 Test テスト Test";
|
|
|
|
|
const punctuationLike = [
|
|
|
|
|
0x3000, // Fullwidth Space but should be treated like punctuation
|
|
|
|
|
0x301c, // Genuine CJ(K) punctuation
|
|
|
|
|
0xff5e, // Nearly equivalent to U+301C but its Unicode category is "Sm"
|
|
|
|
|
0x1f221, // "end" symbol. Should be placed at end
|
|
|
|
|
];
|
|
|
|
|
const code = `${punctuationLike.map((cp) => `U+${cp.toString(16).toUpperCase()}${String.fromCodePoint(cp)}`).join("\n")} ${afterword}\n`;
|
|
|
|
|
snippets.push({
|
|
|
|
|
name: "Should remove newline around CJ(K) punctuation(-like)",
|
|
|
|
|
code,
|
|
|
|
|
// Note: replaceAll is not supported in Node 14.
|
2026-10-04 12:20:28 +09:00
|
|
|
// In CSS, a line break between a CJK and a non-CJK character is always interchangeable
|
|
|
|
|
// with a space, but Prettier v3 made a design mistake where, in some cases,
|
|
|
|
|
// it was treated as equivalent to being deleted
|
|
|
|
|
// (see https://github.com/prettier/prettier/issues/14936).
|
|
|
|
|
// Therefore, .replace is disabled until it gets fixed in
|
|
|
|
|
// https://github.com/prettier/prettier/pull/16805.
|
|
|
|
|
output: code, // `${code.replace(/\n/g, "")}\n`,
|
2026-01-18 10:34:45 +09:00
|
|
|
});
|
|
|
|
|
}
|
2022-10-19 17:40:59 +09:00
|
|
|
|
2024-01-19 17:20:24 +08:00
|
|
|
runFormatTest(
|
2022-10-19 17:40:59 +09:00
|
|
|
{
|
|
|
|
|
importMeta: import.meta,
|
2026-01-18 10:34:45 +09:00
|
|
|
snippets,
|
2022-10-19 17:40:59 +09:00
|
|
|
},
|
|
|
|
|
["markdown"],
|
|
|
|
|
{ proseWrap: "always" },
|
|
|
|
|
);
|