Files
Aislo/resources/tester/test_spreadsheet_unit_prefix.py
T

71 lines
2.2 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"^const UNIT_PREFIX = .*;$", src, re.M)
func = re.search(r"^function attachUnitToFormat[\s\S]*?^}", src, re.M)
assert prefix and func
script = (
prefix.group(0)
+ "\n"
+ func.group(0).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 (
"now.startsWith(unit)" in body and "unit + now" in body
) # 「300」 → 「Φ300」 · 두 번 안 붙음
assert "const s = front ? 0" in body # 편집 중에도 글 맨 앞