# -*- coding: utf-8 -*- """545-1 측점 표기 거울 — D04 `station_label`(py) ↔ `common_util_station.ts` `stationLabel(…, 1)`.""" import json import subprocess import sys from pathlib import Path PROJECT_ROOT = Path(__file__).resolve().parents[2] if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) from D04_PlanConfirm.D04_PlanConfirm_Export import station_label # noqa: E402 TS = PROJECT_ROOT / "common_util" / "common_util_station.ts" TYPESCRIPT = PROJECT_ROOT / "config" / "node_modules" / "typescript" VALUES = [ 0, 19.96, 20, 39.99, 100, 1234.5, 1234.56, 1234.44, 1234.05, 1234.95, 61 * 20 + 14.5, 812.345, ] SCRIPT = r""" const ts = require(process.argv[1]); const src = require("fs").readFileSync(process.argv[2], "utf8"); const js = ts.transpileModule(src, { compilerOptions: { module: ts.ModuleKind.CommonJS } }).outputText; const box = { exports: {} }; new Function("exports", "module", js)(box.exports, box); process.stdout.write(JSON.stringify(JSON.parse(process.argv[3]).map((v) => box.exports.stationLabel(v, 20, 1)))); """ def test_파이썬과_TS_측점_표기_같음(): proc = subprocess.run( ["node", "-e", SCRIPT, str(TYPESCRIPT), str(TS), json.dumps(VALUES)], capture_output=True, text=True, encoding="utf-8", timeout=60, ) assert proc.returncode == 0, proc.stderr assert json.loads(proc.stdout) == [station_label(v) for v in VALUES] def test_표기_꼴(): assert station_label(1234.5) == "61+14.5" assert station_label(0) == "0+0" assert station_label(39.99) == "2+0"