"""근거(메모) WPTools 글 형식 읽기·쓰기: 문단·굵게·표 칸·그림 원문 보존."""
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
SOURCE = (
"\r\n"
""
"<근거> A&B
\r\n\r\n"
""
'x \r\n
\r\n'
)
def node(script):
code = (
"const W=require(process.argv[1]);const S=process.argv[2];"
f"console.log(JSON.stringify(({script})()))"
)
out = subprocess.check_output(
["node", "-e", code, str(ROOT / "tools/est-test/native-memo-wpt.cjs"), SOURCE],
text=True,
encoding="utf-8",
)
return json.loads(out)
def test_read_paragraphs_bold_table_and_object():
nodes = node("()=>W.read(S)")
assert nodes[0] == {
"p": [{"text": "<근거>", "bold": True}, {"text": " A&B", "bold": False}]
}
assert nodes[1] == {"p": []}
assert nodes[2]["table"] == [
[[{"p": [{"text": "공종", "bold": False}]}], [{"p": [{"text": "1.5", "bold": True}]}]]
]
assert nodes[3]["p"][0] == {"text": "x ", "bold": False}
assert nodes[3]["p"][1]["object"].startswith("{const n=W.read(S),w=W.write(n);"
"return {same:JSON.stringify(W.read(w))===JSON.stringify(n),ascii:/^[\\x00-\\x7e]*$/.test(w),"
"html:W.html(n)}}"
)
assert result["same"] is True
assert result["ascii"] is True
assert "<근거>" in result["html"]
assert 'data-obj="0"' in result["html"] and "