- 원본처럼 공식 명칭·본문 목록 편집, 단가산출에 본문 줄 넣기 - 옛 EST Plus mach_Text.dat 구공식변환 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.4 KiB
Python
49 lines
2.4 KiB
Python
"""EST 테스트 앱 기계경비 공식 모음(원본 TfrmMachGongSic·TfrmMachText·구공식변환 0xd90c60)."""
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def test_old_file_parse_and_insert(tmp_path):
|
|
script = r"""
|
|
const fs = require('fs'), vm = require('vm');
|
|
const ctx = vm.createContext({ TextDecoder, DataView, Uint8Array });
|
|
vm.runInContext(fs.readFileSync('tools/est-test/native-mach-formula.js', 'utf8'), ctx);
|
|
const rec = (head, a, b) => {
|
|
const r = Buffer.alloc(394); r.writeInt32LE(head, 5);
|
|
const ea = Buffer.from(a, 'latin1'), eb = Buffer.from(b, 'latin1');
|
|
r[0x16] = ea.length; ea.copy(r, 0x17); r[0x49] = eb.length; eb.copy(r, 0x4a); return r;
|
|
};
|
|
const file = Buffer.concat([rec(1, 'Back', 'hoe'), rec(0, 'Q = ', '1.0'), rec(0, 'E = 0.7', ''), rec(2, 'Dozer', ''), rec(0, 'f = 1', '')]);
|
|
ctx.bytes = new Uint8Array(file);
|
|
const parsed = vm.runInContext('EstMachFormula.parseOld(bytes)', ctx);
|
|
let bad = ''; try { vm.runInContext('EstMachFormula.parseOld(new Uint8Array(10))', ctx); } catch (e) { bad = e.message.slice(0, 6); }
|
|
ctx.p = { tables: { CostMainDat: [{ PkID: 3, Index: 1, Code: 'D1' }, { PkID: 4, LineData: '끝' }] } };
|
|
ctx.body = 'Q = 1\rE = 0.7\r';
|
|
const count = vm.runInContext('EstMachFormula.insertInto(p, 0, body)', ctx);
|
|
process.stdout.write(JSON.stringify({ parsed, bad, count, rows: ctx.p.tables.CostMainDat.map((r) => [r.PkID, r.LineData ?? null]) }));
|
|
"""
|
|
out = json.loads(subprocess.check_output(["node", "-e", script], cwd=ROOT).decode("utf-8"))
|
|
assert out["parsed"] == [
|
|
{"name": "Backhoe", "body": "Q = 1.0\rE = 0.7\r", "index": 1},
|
|
{"name": "Dozer", "body": "f = 1\r", "index": 2},
|
|
]
|
|
assert out["bad"] == "구공식 파일"
|
|
assert out["count"] == 2
|
|
assert out["rows"] == [[3, None], [5, "Q = 1"], [6, "E = 0.7"], [4, "끝"]]
|
|
|
|
|
|
def test_store_accepts_machine_formula_kind(tmp_path):
|
|
script = """
|
|
const f = require(process.cwd() + '/tools/est-test/forms-store.cjs');
|
|
f.save(process.argv[1], { kind: 'machformula', name: '백호', data: { index: 1, body: 'Q = 1' } });
|
|
process.stdout.write(JSON.stringify(f.read(process.argv[1]).map((x) => [x.kind, x.name])));
|
|
"""
|
|
out = json.loads(
|
|
subprocess.check_output(["node", "-e", script, str(tmp_path)], cwd=ROOT).decode("utf-8")
|
|
)
|
|
assert out == [["machformula", "백호"]]
|