Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MgChuAcyBqUkhHMTXomQC7
89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
"""스프레드시트 단위 Φ(PLAN 81-5 · `spreadsheet_toolbar.ts`) — 길이 묶음 끝에 Φ · 숫자 앞에 붙임.
|
|
|
|
형식 코드 갈래(`attachUnitToFormat`)는 Node 로 함수를 떼어 돌리고, 칸 글 · 편집기 갈래는 글로 확인
|
|
(화면 조작은 ORCA).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
TOOLBAR = ROOT / "A00_Common" / "spreadsheet" / "spreadsheet_toolbar.ts"
|
|
|
|
|
|
def _text() -> str:
|
|
return TOOLBAR.read_text(encoding="utf-8")
|
|
|
|
|
|
@pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없음")
|
|
def test_형식_코드_앞_단위_뒤_단위():
|
|
src = _text()
|
|
prefix = re.search(r"^(?:export )?const UNIT_PREFIX = .*;$", src, re.M)
|
|
func = re.search(r"^(?:export )?function attachUnitToFormat[\s\S]*?^}", src, re.M)
|
|
assert prefix and func
|
|
script = (
|
|
prefix.group(0).replace("export ", "")
|
|
+ "\n"
|
|
+ func.group(0)
|
|
.replace("export ", "")
|
|
.replace(": string", "") # 형 이름 뗌 — Node 가 그대로 돌게
|
|
+ """
|
|
const f = attachUnitToFormat;
|
|
console.log(JSON.stringify([
|
|
f("", "Φ"), // 처음 = 「Φ」 + 0
|
|
f("0.00", "Φ"), // 코드 앞
|
|
f('"Φ"0', "Φ"), // 두 번 눌러도 한 번
|
|
f('0"m"', "Φ"), // 뒤 단위는 그대로
|
|
f('"Φ"0', "m"), // 뒤 단위를 붙여도 앞 단위 살아 있음
|
|
f('0"m"', "㎜"), // 옛 동작 — 뒤 단위 바꿈
|
|
f("", "m"),
|
|
]));
|
|
"""
|
|
)
|
|
out = subprocess.run(
|
|
["node", "-e", script], capture_output=True, text=True, encoding="utf-8", check=True
|
|
)
|
|
assert json.loads(out.stdout) == [
|
|
'"Φ"0',
|
|
'"Φ"0.00',
|
|
'"Φ"0',
|
|
'"Φ"0"m"',
|
|
'"Φ"0"m"',
|
|
'0"㎜"',
|
|
'0"m"',
|
|
]
|
|
|
|
|
|
def test_Φ_길이_묶음_끝_칸_글_편집기():
|
|
src = _text()
|
|
assert '["UnitGroup_area", ["㎡", "㎥", "m", "㎝", "㎜", "㎞", "Φ"]]' in src
|
|
body = src.split("function insertUnit")[1].split("function renderRecent")[0]
|
|
assert "UNIT_PREFIX.includes(unit)" in body
|
|
assert "prefixUnit(now, unit)" in body # 칸 글 — 「300」 → 「Φ300」 · 두 번 안 붙음
|
|
assert "prefixUnit(active.value, unit)" in body # 편집 중에도 같은 규칙
|
|
|
|
|
|
@pytest.mark.skipif(shutil.which("node") is None, reason="node 가 없음")
|
|
def test_앞_단위_글_낫표_뒤에_붙음():
|
|
"""강제 글 낫표(`'300`)는 맨 앞에 두고 그 뒤에 붙임 — 「Φ'300」 처럼 낫표가 가운데 남지 않음."""
|
|
func = re.search(r"^export function prefixUnit[\s\S]*?^}", _text(), re.M)
|
|
assert func
|
|
script = (
|
|
func.group(0).replace("export ", "").replace(": string", "")
|
|
+ """
|
|
const f = prefixUnit;
|
|
console.log(JSON.stringify([f("300", "Φ"), f("'300", "Φ"), f("Φ300", "Φ"), f("'Φ300", "Φ"), f("=A1", "Φ"), f("", "Φ")]));
|
|
"""
|
|
)
|
|
out = subprocess.run(
|
|
["node", "-e", script], capture_output=True, text=True, encoding="utf-8", check=True
|
|
)
|
|
assert json.loads(out.stdout) == ["Φ300", "'Φ300", "Φ300", "'Φ300", "=A1", "Φ"]
|