40 lines
1.9 KiB
Python
40 lines
1.9 KiB
Python
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
from test_est_rea_parity import run
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def test_jdl_basic_tables_use_native_separators_encoding_and_preserve_direct_money():
|
|
p = run(
|
|
"math",
|
|
"""(()=>{
|
|
const p=EstNative.empty();p.name='JDL test';p.options.SourceRefresh=false;
|
|
p.tables.StuffcDat=[{PkID:1,Code:'M',Name:'material',InputTC:100,ValueIndex:4}];
|
|
p.tables.EstMainDat=[{PkID:1,Code:'M',Name:'material',LinkIndex:5,GN:10,GU:100},
|
|
{PkID:2,Code:'FIX',Name:'fixed',GN:0,GC:80,TC:80,CalcIndex:1},
|
|
{PkID:3,Code:'SKIP',Name:'excluded',GN:1,GC:999,TC:999,CalcIndex:3},{PkID:4,LinkIndex:54}];
|
|
p.tables.Wonga=[{Gubun:'G',Name:'material',BaseField:'GC'},{Gubun:'T',Name:'total',VSusic:'G'}];
|
|
return EstNative.calculate(p);
|
|
})()""",
|
|
)
|
|
script = """const fs=require('fs'),j=require('./tools/est-test/jdl.cjs'),a=require('./tools/est-test/archive.cjs');
|
|
const p=JSON.parse(fs.readFileSync(0,'utf8')),empty=structuredClone(p);for(const name of Object.keys(empty.tables))empty.tables[name]=[];
|
|
const out=j.output(p),files=a.unpack(out.bytes),next=j.read(out.bytes,empty);
|
|
const raw=files.get('mainpart.txt');
|
|
process.stdout.write(JSON.stringify({next,files:[...files.keys()],tabs:raw.includes(9),terminator:raw.includes(5),warnings:out.warnings}));"""
|
|
result = json.loads(
|
|
subprocess.check_output(
|
|
["node", "-e", script],
|
|
input=json.dumps(p, ensure_ascii=False).encode("utf-8"),
|
|
cwd=ROOT,
|
|
).decode("utf-8")
|
|
)
|
|
assert result["tabs"] and result["terminator"]
|
|
assert {"Global.ini", "Main.txt", "mainpart.txt", "CostAccount.txt"}.issubset(result["files"])
|
|
assert result["next"]["tables"]["EstMainDat"][-1]["TC"] == 1080
|
|
assert result["next"]["tables"]["Wonga"][-1]["Cost"] == 1080
|
|
assert result["next"]["options"]["AutoCalc"] is False
|
|
assert result["warnings"]
|