"""원화 꼴 한 벌 거울 시험 — `common_util_money.py`(파이썬) ↔ `common_util_money.ts`(TS · Node) 가 같은 글. CLAUDE.md 5장 ① 짝. 값은 숫자 글(`num`) · 숫자 아닌 글(`text`) · 빈 값(None). """ import json import os import subprocess import sys from decimal import Decimal HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "..", "..")) from common_util import common_util_money as mf # noqa: E402 NUMS = [ "0", "1", "2.5", "-1234.5", "1.00005", "0.12345", "0.00167", "22.9", "1846.39", "124419.853", "275790", "69643.9394", "0.2525", "4", "199.99", "200", "1234567.891", "-0.00001", "0.05", "870.2455", "59020", "1414.9", "-22.96", ] # fmt: skip CASES = [{"num": n} for n in NUMS] + [{"text": "가나다"}, {"text": ""}, None] PAIRS = { "formatNumber": mf.fmt, "formatMoney": mf.fmt_money, "formatLineMoney": mf.fmt_line_money, "formatPrice": mf.fmt_price, } def _ts() -> dict: proc = subprocess.run( ["node", os.path.join(HERE, "helper_588_2_money_fmt.cjs")], input=json.dumps(CASES, ensure_ascii=False), capture_output=True, text=True, encoding="utf-8", check=True, ) return json.loads(proc.stdout) def _py_value(case): if case is None: return None return Decimal(case["num"]) if "num" in case else case["text"] def test_python_ts_same_text(): ts_out = _ts() for name, py_fn in PAIRS.items(): for case, ts_text in zip(CASES, ts_out[name]): assert py_fn(_py_value(case)) == ts_text, (name, case) def test_known_shapes(): assert mf.fmt(Decimal("1.00005")) == "1.0001" assert mf.fmt(Decimal("0.00167")) == "0.00167" assert mf.fmt(Decimal("4")) == "4" # 율 — 「4 %」 (「4.0」 아님) assert mf.fmt_money(Decimal("124419.853")) == "124,420" assert mf.fmt_line_money(Decimal("69643.9394")) == "69,643.9" assert mf.fmt_line_money(Decimal("18064")) == "18,064" # 「.0」 꼬리 없음 assert mf.fmt_price(Decimal("1846.39")) == "1,846.39" # 정수로 숨기지 않음 assert mf.fmt_price(Decimal("22.9")) == "22.9" assert mf.fmt_money(Decimal("-0.4")) == "0" assert mf.fmt(None) == "" and mf.fmt("가") == "가"