fix(m02-cf): 함수 상자 출력 기본 이름을 로직 안에서 겹치지 않게
- addBox(function) 출력 이름 = 「결과 1」 「결과 2」 … (안 쓰인 가장 작은 번호) · A1 머리도 같은 이름 - 이름이 겹치면 link 가 받는 알약을 「이름 (2)」 로 만듦(이미 됨 · 시험 더함) - 시험 14개 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VBToTCGk5dqDKeXCEP3vhk
This commit is contained in:
@@ -188,13 +188,19 @@ export function addBox(
|
||||
);
|
||||
const box: CfBox = { id, kind, name, color: BOX_COLOR[kind], unit: "-", x, y };
|
||||
if (kind === "input") box.input = { mode: "variable", elements: [], variables: [] };
|
||||
if (kind === "function")
|
||||
if (kind === "function") {
|
||||
// 출력 이름은 로직 안에서 겹치지 않게 「결과 1」 「결과 2」 … — 다른 함수 상자의 받는 알약과 섞이지 않음
|
||||
const taken = lg.boxes.flatMap((b) => (b.func ? [b.func.output.name] : []));
|
||||
let n = 1;
|
||||
while (taken.includes(`${tl("Result")} ${n}`)) n++;
|
||||
const out = `${tl("Result")} ${n}`;
|
||||
box.func = {
|
||||
sheet: { id: `s-${id}`, 이름: name, 칸: { A1: { 값: tl("Result") } } },
|
||||
sheet: { id: `s-${id}`, 이름: name, 칸: { A1: { 값: out } } },
|
||||
inputs: [],
|
||||
variables: [],
|
||||
output: { cell: "B1", name: tl("Result"), unit: "-" },
|
||||
output: { cell: "B1", name: out, unit: "-" },
|
||||
};
|
||||
}
|
||||
if (kind === "output") box.output = { cost: "노무비", unit: "-" };
|
||||
return { lg: { ...lg, boxes: [...lg.boxes, box] }, box };
|
||||
}
|
||||
|
||||
@@ -322,3 +322,27 @@ def test_같은_이름_받는_알약은_번호() -> None:
|
||||
"out(x.boxes.find(y => y.id === g.id).func.inputs.map(i => i.port));"
|
||||
)
|
||||
assert got == ["석공", "노무비", "석공 (2)", "할증"]
|
||||
|
||||
|
||||
def test_함수_출력_기본_이름은_겹치지_않음_받는_알약은_번호() -> None:
|
||||
got = _run(
|
||||
"let lg = M.newLogic(); let r = add(lg, 'function'); lg = r.lg; const f1 = r.box;\n"
|
||||
"r = add(lg, 'function'); lg = r.lg; const f2 = r.box;\n"
|
||||
"r = add(lg, 'function'); lg = r.lg; const f3 = r.box;\n"
|
||||
"lg = M.removeBox(lg, f2.id); r = add(lg, 'function'); lg = r.lg; const f4 = r.box;\n"
|
||||
"lg = M.link(lg, { box: f1.id, name: '결과 1' }, { box: f3.id, name: '' }).lg;\n"
|
||||
"lg = M.link(lg, { box: f4.id, name: '결과 2' }, { box: f3.id, name: '' }).lg;\n"
|
||||
"r = add(lg, 'function'); lg = r.lg; const f5 = r.box;\n"
|
||||
"lg = M.updateBox(lg, f5.id, { func: { ...f5.func, output: { ...f5.func.output, name: '결과 1' } } });\n"
|
||||
"lg = M.link(lg, { box: f5.id, name: '결과 1' }, { box: f3.id, name: '' }).lg;\n"
|
||||
"out([[f1, f3, f4, f5].map(b => [b.func.output.name, b.func.sheet.칸.A1.값]),"
|
||||
" lg.boxes.find(b => b.id === f3.id).func.inputs.map(i => i.port)]);"
|
||||
)
|
||||
names, ports = got
|
||||
assert names == [
|
||||
["결과 1", "결과 1"],
|
||||
["결과 3", "결과 3"],
|
||||
["결과 2", "결과 2"],
|
||||
["결과 4", "결과 4"],
|
||||
]
|
||||
assert ports == ["결과 1", "결과 2", "결과 1 (2)"]
|
||||
|
||||
Reference in New Issue
Block a user