Files
Aislo/resources/tester/test_est_quantity_total.py
T
eomsangdonandClaude Opus 5.5 892285843d feat(est-test): 워드형 수량산출서 표 보존과 편집 도구
- 가져오기가 WPT 표를 버리던 결함 고침: 표 줄(칸·수량 표지·수식·세로병합) 보존, 문서 읽기 native-quantity-wpt.cjs 로 분리
- 표 셀 합·수량 지정·병합/분리·표 만들기·표 모양, 문단·그림·쪽 삽입/삭제·품명/규격 지정·공종명칭 입력·테두리선·산출근거 양식
- 수량 불러오기·수량목록보기·선택수량복사·내역서 수량붙여넣기(연결)
- ESTX 저장은 표 줄을 건너 문단만 맞춤, 표·서식 편집은 거부

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 18:35:50 +09:00

57 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""EST 테스트 앱 수량산출 누계(원본 ActionAdd Ctrl+U 0x11155c4, 재계산 때 F·a 표지 다시 계산)."""
import json
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
FILES = [
"native-math.js",
"native-formula.js",
"native-text.js",
"native-quantity-total.js",
"native-quantity-wpt.cjs",
"native-quantity.cjs",
]
SCRIPT = r"""(() => {
const sheet = { Code: 'N1', options: { digits: 2, roundMode: 2 }, items: [
{ Code: 'r000001' }, { Code: 'r000002' }, { Code: 'r000003' }, { Code: 'r000004' }],
rows: [
{ LineData: ' \x0e터파기\x0e 2×3 = \x126\x12', markers: ['r000001'] },
{ LineData: ' 1.5×2 = \x123\x12', markers: ['r000002'] },
{ LineData: ' \x16999\x16', markers: [], totals: ['F000001'] },
{ LineData: ' 4×1 = \x124\x12', markers: ['r000003'] },
{ LineData: ' 0.3333×1 = \x120.33\x12', markers: ['r000004'] },
{ LineData: ' \x160\x16', markers: [], totals: ['F00000222'] } ] };
const out = EstQuantity.calculate(sheet);
const totals = out.rows.map((r) => (r.LineData.match(/\x16([^\x16]*)\x16/) || [])[1]).filter(Boolean);
sheet.rows[0].LineData = sheet.rows[0].LineData.replace('2×3', '200×30');
const big = EstQuantity.calculate(sheet).rows[2].LineData.match(/\x16([^\x16]*)\x16/)[1];
const fresh = { Code: 'N2', options: { digits: 1, roundMode: 1 }, items: [], rows: [{ LineData: ' 끝', markers: [] }] };
const name = EstQuantityTotal.insert(fresh, 0, 1);
let inside = ''; try { EstQuantityTotal.insert(fresh, 0, 4); } catch (e) { inside = e.message.slice(0, 5); }
const parsed = EstQuantity.fromWpt('N9', '시험',
'<div><begin Tag=1 Name:"F00000312"/>7<end Tag=1/></div>', [], {});
return { totals, big, name, line: EstText.display(fresh.rows[0].LineData), edited: fresh.markerEdited,
inside, parsed: [parsed.rows[0]?.LineData, parsed.rows[0]?.totals], errors: out.errors };
})()"""
def test_total_is_subtotal_since_name_or_previous_total():
runner = f"""
const fs = require('fs'), vm = require('vm');
const ctx = vm.createContext({{ structuredClone, console }});
for (const f of {json.dumps(FILES)})
vm.runInContext(fs.readFileSync('tools/est-test/' + f, 'utf8'), ctx, {{ filename: f }});
process.stdout.write(JSON.stringify(vm.runInContext({json.dumps(SCRIPT)}, ctx)));
"""
result = json.loads(subprocess.check_output(["node", "-e", runner], cwd=ROOT).decode("utf-8"))
assert result["errors"] == []
assert result["totals"] == ["9", "4.33"]
assert result["big"] == "6,003"
assert result["name"] == "F00000111"
assert result["line"] == " ⟦누계⟧0⟦누계⟧끝"
assert result["edited"] is True
assert result["inside"] == "누계 표지"
assert result["parsed"] == ["\x167\x16", ["F00000312"]]