/* M02 구조물 라이브러리 자료(`M02_MasterTemplete_TreePanel_Model.ts`) 단위검증 헬퍼 — 트랜스파일해 Node 로 돌리고 JSON 으로 냄. */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const file = path.join(__dirname, "..", "..", "M02_MasterTemplete", "M02_MasterTemplete_TreePanel_Model.ts"); const js = ts.transpileModule(fs.readFileSync(file, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; new Function("exports", "module", "require", js)(box.exports, box, require); const m = box.exports; const item = (열, 경로, key) => ({ key, 열, 경로, 이름: 경로.join(" "), 단위: "m", 일위대가: null }); const view = { 판: "v1", 폴더: [["빈 폴더"], ["돌기슭막이", "빈 아래"]], items: [ item("c1", ["돌기슭막이", "메쌓기", "1.2m"], "SS000001"), item("c2", ["돌기슭막이", "찰쌓기"], "SS000002"), item("c3", ["다섯", "둘", "셋", "넷", "잎"], "SS000003"), item("c4", ["최상위 항목"], "SS000004"), ], }; const shape = (n) => ({ path: n.path, items: n.items.map((i) => i.열), folders: n.folders.map(shape), }); const all = m.buildFolders(view); const found = m.buildFolders(view, "찰쌓기"); process.stdout.write( JSON.stringify({ all: shape(all), count: m.countItems(all), found: shape(found), foundCount: m.countItems(found), none: shape(m.buildFolders(view, "없는말")), folders: m.listFolders(all), ancestors: m.ancestorsOf(view, "c3"), ancestorsTop: m.ancestorsOf(view, "c4"), ancestorsNone: m.ancestorsOf(view, "zz"), under: [ m.isUnder(["a", "b"], ["a"]), m.isUnder(["a"], ["a"]), m.isUnder(["a"], ["a", "b"]), m.isUnder(["x"], ["a"]), ], leaf: m.leafName(view.items[0]), dir: m.folderOf(view.items[0]), byKey: m.buildFolders(view, "ss000003").items.length + m.buildFolders(view, "SS000003").folders.length, // 찾기 AND(PLAN 29-6) — 낱말 모두 · 대소문자 무시 · 순서 무관 · 빈 글 = 참 and: [ m.matchText(["돌기슭막이", "메쌓기", "SS000001", "m"], "메쌓기 ss000001"), m.matchText(["돌기슭막이", "메쌓기", "SS000001", "m"], "ss000001 돌기슭"), m.matchText(["돌기슭막이", "메쌓기", "SS000001", "m"], "메쌓기 찰쌓기"), m.matchText(["UC3-000001", "브레인 측구", null, "배수"], ""), m.matchText(["UC3-000001", "브레인 측구", null, "배수"], "측구 배수"), ], andTree: m.countItems(m.buildFolders(view, "돌기슭막이 찰쌓기")), }), );