Files
marqdo/tests/wasm/list-records.mjs
T
cflmy 9331af78e2 release(2.8.0): 合入 CHANGELOG/README/发版说明/skills prove 任务;CI 链接指向 doc/releases
- CHANGELOG.md:v2.8.0 条目(中英双语);
- README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明);
- doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制);
- skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/
  require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过);
- 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
2026-11-18 10:29:26 +08:00

28 lines
1.5 KiB
JavaScript
Executable File

import test from "node:test";
import assert from "node:assert/strict";
import {renderListItems} from "../../crates/marqdo-wasm/js/marqdo-bridge.js";
test("typed list children retain text, controls and literal identities",()=>{
const html=renderListItems({tag:"li",items:[{attrs:{"data-id":"row-1"},children:[
{tag:"span",text:'A <tag> "quote" & literal'},
{tag:"button",text:"删",attrs:{type:"button","data-id":'id" & value',disabled:false}}
]}]});
assert.ok(html.includes("A &lt;tag&gt; &quot;quote&quot; &amp; literal"));
assert.ok(html.includes('<button type="button" data-id="id&quot; &amp; value">删</button>'));
assert.ok(!html.includes("<tag>") && !html.includes(" disabled"));
assert.equal(renderListItems({items:["a",{text:"b"}]}),"<li>a</li><li>b</li>");
assert.equal(renderListItems({items:[{html:"<em>explicit legacy</em>"}]}),"<li><em>explicit legacy</em></li>");
});
test("structural lists reject malformed nodes and bounded recursion",()=>{
for(const item of [
{tag:'button onclick="x"',text:"x"},{tag:"script",text:"x"},
{attrs:{"data-id onload":"x"},text:"x"},{attrs:{onclick:"x"},text:"x"},
{attrs:{href:"javascript:alert(1)"},text:"x"},
{children:"not a list"},{text:"ambiguous",children:[]},{tag:"input",children:[{text:"x"}]}
]) assert.throws(()=>renderListItems({items:[item]}),/render_list/);
let deep={text:"leaf"};
for(let i=0;i<34;i++)deep={children:[deep]};
assert.throws(()=>renderListItems({items:[deep]}),/limit/);
assert.throws(()=>renderListItems({items:Array(10001).fill("x")}),/limit/);
});