feat(est-test): 수량산출 누계 계산과 넣기
- 원본 누계 표지(F·a)를 읽어 계산마다 소계로 다시 구함 - 산출 줄 커서 자리에 누계 넣기, 표지 반올림 방식·자리 반영 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""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.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"]]
|
||||
Reference in New Issue
Block a user