- 헬퍼 동작 그대로(풀이 함수 본문은 옮겨 담음) · 제품 코드 안 고침 - 확인: 이 묶음 헬퍼를 쓰는 시험 428 개 전 417 통과 → 후 417 통과 (시험별 junit 대조 · 어긋남 0) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
110 lines
4.0 KiB
JavaScript
110 lines
4.0 KiB
JavaScript
/* 구조물 측점 왕복 단위검증 헬퍼 — `B05_Profile_UI_Structures_Fields.ts`(측점 칸)와
|
|
* `B05_Profile_UI_Profile_Edit.ts`(계획고 편집 저장소)를 그 자리에서 트랜스파일해 Node 로 돌린다.
|
|
* 확장자가 `.cjs` 인 까닭은 `helper_b05_cut_merged_loop.cjs` 머리와 같다.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { makeLoader } = require("./helper_ts_stub_loader.cjs");
|
|
const CATALOG = require("./helper_322_catalog_module.cjs"); // 구조물 표(322-1)
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
|
|
const { loadTs } = makeLoader({
|
|
root: ROOT,
|
|
requireFor: (full) => (request) =>
|
|
CATALOG.isCatalogRequest(request)
|
|
? CATALOG
|
|
: request.startsWith(".")
|
|
? loadTs(path.join(path.dirname(full), `${request}.ts`))
|
|
: require(request),
|
|
});
|
|
|
|
// 측점 칸이 쓰는 만큼만 흉내 낸 DOM
|
|
function fakeElement() {
|
|
const listeners = {};
|
|
const classes = new Set();
|
|
return {
|
|
value: "",
|
|
children: [],
|
|
style: {},
|
|
dataset: {},
|
|
classList: {
|
|
add: (c) => classes.add(c),
|
|
remove: (c) => classes.delete(c),
|
|
toggle: (c, on) => (on ? classes.add(c) : classes.delete(c)),
|
|
contains: (c) => classes.has(c),
|
|
},
|
|
setAttribute() {},
|
|
append(...kids) {
|
|
this.children.push(...kids);
|
|
},
|
|
appendChild(kid) {
|
|
this.children.push(kid);
|
|
return kid;
|
|
},
|
|
addEventListener: (type, fn) => (listeners[type] = listeners[type] || []).push(fn),
|
|
fire: (type) => (listeners[type] || []).forEach((fn) => fn({ type })),
|
|
};
|
|
}
|
|
global.document = { createElement: () => fakeElement(), createTextNode: () => fakeElement() };
|
|
|
|
const { stationFields } = loadTs(
|
|
path.join(ROOT, "B05_Profile", "B05_Profile_UI_Structures_Fields.ts"),
|
|
);
|
|
const { createProfileEditStore } = loadTs(
|
|
path.join(ROOT, "B05_Profile", "B05_Profile_UI_Profile_Edit.ts"),
|
|
);
|
|
|
|
const INTERVAL = 20;
|
|
const out = {};
|
|
const fields = stationFields("기준", () => INTERVAL);
|
|
|
|
// ① 실어 둔 값은 칸을 안 고치면 그대로(표시는 6 + 3 · 칸도 정수 m 167)
|
|
fields.write(123.37, INTERVAL);
|
|
out.shown = [fields.station.value, fields.remainder.value];
|
|
out.untouched = fields.read(INTERVAL, true);
|
|
fields.write(123.3721, INTERVAL);
|
|
out.untouchedRaw = fields.read(INTERVAL, true);
|
|
// 옛 소수 119.8 — 다시 열면 5 + 20 으로 보이고 그대로 읽힘
|
|
fields.write(119.8, INTERVAL);
|
|
out.r119 = [fields.station.value, fields.remainder.value, fields.read(INTERVAL, true)];
|
|
fields.write(123.3721, INTERVAL);
|
|
// 사용자가 잔여를 고치면 친 값으로
|
|
fields.remainder.value = "5.2";
|
|
fields.remainder.fire("change");
|
|
out.edited = fields.read(INTERVAL, true);
|
|
// 같은 글로 되돌려 치면 — 여전히 실어 둔 값(칸 글이 쓴 그대로)
|
|
fields.write(123.37, INTERVAL);
|
|
fields.remainder.value = "3";
|
|
out.retypedSame = fields.read(INTERVAL, true);
|
|
// 넘침 정규화(1 + 30 → 2 + 10)는 친 값으로
|
|
fields.station.value = "1";
|
|
fields.remainder.value = "30";
|
|
fields.remainder.fire("change");
|
|
out.normalized = [fields.station.value, fields.remainder.value, fields.read(INTERVAL, true)];
|
|
// 비운 폼은 읽기 null
|
|
fields.write(null, INTERVAL);
|
|
out.cleared = fields.read(INTERVAL, false);
|
|
|
|
// ② 계획고 편집 — 측점이 0.005m 안으로 옮겨 오면 편집을 옮기고, 아니면 지움
|
|
const saved = { station_offsets: { 123.372: 0.5, "200.000": 0.3 }, curve_radii: { 123.372: 40 } };
|
|
const store = createProfileEditStore(null, saved, () => {});
|
|
store.resetStation(123.372, 123.37);
|
|
out.moved = store.edits();
|
|
store.resetStation(200);
|
|
out.deleted = store.edits();
|
|
|
|
// 화면 표기 한 벌 — 거리는 정수로 보이기만(PLAN 20장 · 119.8 → 5+20)
|
|
const { stationLabel, stationPartsLabel } = loadTs(
|
|
path.join(ROOT, "common_util", "common_util_station.ts"),
|
|
);
|
|
out.labels = [
|
|
stationLabel(119.8, INTERVAL),
|
|
stationLabel(120, INTERVAL),
|
|
stationLabel(84.3, INTERVAL),
|
|
stationLabel(123.37, INTERVAL),
|
|
stationPartsLabel(5, 19.8),
|
|
];
|
|
|
|
process.stdout.write(JSON.stringify(out));
|