增加了基础的块功能
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
buildDropIndicatorText,
|
||||
computeSpanTargetStart,
|
||||
mergeBlockTexts,
|
||||
moveContiguousSpan,
|
||||
} from "../src/lib/editor-block-ops.ts";
|
||||
|
||||
const cases = [
|
||||
() => assert.equal(mergeBlockTexts(["A", "B", "C"]), "A\n\nB\n\nC"),
|
||||
() => assert.equal(computeSpanTargetStart(6, 2, 3, 3), 2),
|
||||
() => assert.equal(computeSpanTargetStart(6, 3, 4, 1), 1),
|
||||
() => assert.equal(computeSpanTargetStart(6, 1, 2, 5), 3),
|
||||
() => {
|
||||
const moved = moveContiguousSpan(["A", "B", "C", "D", "E"], 2, 3, 1);
|
||||
assert.equal(moved.changed, true);
|
||||
assert.equal(moved.targetStart, 1);
|
||||
assert.deepEqual(moved.reordered, ["A", "C", "D", "B", "E"]);
|
||||
},
|
||||
() => {
|
||||
const moved = moveContiguousSpan(["A", "B", "C", "D", "E"], 1, 2, 5);
|
||||
assert.equal(moved.changed, true);
|
||||
assert.equal(moved.targetStart, 3);
|
||||
assert.deepEqual(moved.reordered, ["A", "D", "E", "B", "C"]);
|
||||
},
|
||||
() => {
|
||||
const moved = moveContiguousSpan(["A", "B", "C", "D", "E"], 1, 3, 2);
|
||||
assert.equal(moved.changed, false);
|
||||
assert.equal(moved.targetStart, 1);
|
||||
assert.deepEqual(moved.reordered, ["A", "B", "C", "D", "E"]);
|
||||
},
|
||||
() => {
|
||||
assert.equal(buildDropIndicatorText(0, 4), "将插入到第 1 块之前");
|
||||
assert.equal(buildDropIndicatorText(2, 4), "将插入到第 3 块之前");
|
||||
assert.equal(buildDropIndicatorText(9, 4), "将插入到文档末尾");
|
||||
},
|
||||
];
|
||||
|
||||
for (const [index, run] of cases.entries()) {
|
||||
run();
|
||||
console.log(`ok ${index + 1}`);
|
||||
}
|
||||
|
||||
console.log(`All ${cases.length} editor block operation checks passed.`);
|
||||
Reference in New Issue
Block a user