59 lines
2.4 KiB
JavaScript
59 lines
2.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { setupDom } from "./helpers.mjs";
|
|
import { createJuzhen } from "../dist/juzhen.mjs";
|
|
|
|
for (const minLength of [ 6.5, Infinity, NaN, -Infinity, 1e21 ])
|
|
{
|
|
test("longWord:無效計數 " + minLength + " 回退六字,不靜默停用", () =>
|
|
{
|
|
const { dom, document } = setupDom('<p>configuration</p>');
|
|
const jz = createJuzhen({ jiya: false, spacing: false, jinze: false, orphan: false,
|
|
longWord: { minLength } });
|
|
try
|
|
{
|
|
jz.render(document.body);
|
|
assert.equal(jz.options.longWord.minLength, 6);
|
|
assert.equal(document.querySelectorAll('[data-jz="longWord"]').length, 1);
|
|
assert.equal(document.body.textContent, "configuration");
|
|
jz.revert(document.body);
|
|
assert.equal(document.querySelector("p").innerHTML, "configuration");
|
|
}
|
|
finally { jz.disconnect(); dom.window.close(); }
|
|
});
|
|
}
|
|
|
|
for (const chars of [ Infinity, NaN, -Infinity ])
|
|
{
|
|
test("orphan:非有限計數 " + chars + " 回退兩字", () =>
|
|
{
|
|
const { dom, document } = setupDom('<p>甲乙丙丁</p>');
|
|
const jz = createJuzhen({ jiya: false, spacing: false, jinze: false, longWord: false,
|
|
orphan: { chars } });
|
|
try
|
|
{
|
|
jz.render(document.body);
|
|
assert.equal(jz.options.orphan.chars, 2);
|
|
assert.equal(document.querySelector("jz-orphan").textContent, "丙丁");
|
|
jz.revert(document.body);
|
|
assert.equal(document.querySelector("p").innerHTML, "甲乙丙丁");
|
|
}
|
|
finally { jz.disconnect(); dom.window.close(); }
|
|
});
|
|
}
|
|
|
|
test("有效計數:longWord 整數閾值及 orphan 小數向下取整維持既有行為", () =>
|
|
{
|
|
const { dom, document } = setupDom('<p>abcdef abcdefg甲乙丙丁</p>');
|
|
const jz = createJuzhen({ jiya: false, spacing: false, jinze: false,
|
|
longWord: { minLength: 7 }, orphan: { chars: 2.5 } });
|
|
try
|
|
{
|
|
jz.render(document.body);
|
|
assert.equal(jz.options.orphan.chars, 2);
|
|
assert.deepEqual(Array.from(document.querySelectorAll('[data-jz="longWord"]'), (el) => el.textContent), [ "abcdefg" ]);
|
|
assert.equal(document.querySelector("jz-orphan").textContent, "丙丁");
|
|
}
|
|
finally { jz.revert(document.body); jz.disconnect(); dom.window.close(); }
|
|
});
|