"""Formatting must never reach the speakers. Regression test for hearing "asterisk asterisk aloud asterisk asterisk". """ import asyncio, sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from spoken_text import SpokenTextFilter CASES = [ ("It is annoying to hear **aloud** asterisks.", "It is annoying to hear aloud asterisks."), ("Use *italics* and `code` and ~~strike~~.", "Use italics and code and strike."), ("- first\n- second", "first\nsecond"), ("Check `bot.py`, the **sample_rate** is 16000.", "Check bot.py, the sample rate is 16000."), ("See [the docs](https://example.com) for more.", "See the docs for more."), ("Multiply 3 * 4.", "Multiply 3 times 4."), ("A plain sentence.", "A plain sentence."), ("The well-known trade-off is fine.", "The well-known trade-off is fine."), ] async def main(): f = SpokenTextFilter() bad = 0 for text, want in CASES: got = await f.filter(text) if got.strip() != want.strip(): bad += 1 print(f" FAIL {text!r}\n got {got!r}\n want {want!r}") print(f" {'PASS' if not bad else 'FAIL'} {len(CASES) - bad}/{len(CASES)} spoken-text cases") # Nothing that reads as punctuation noise should survive. joined = "".join([await f.filter(t) for t, _ in CASES]) for ch in "*`~#": print(f" {'PASS' if ch not in joined else 'FAIL'} no {ch!r} reaches the speakers") asyncio.run(main())