diff options
| author | historia <historiavg@proton.me> | 2026-08-28 04:45:29 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-28 04:45:29 -0400 |
| commit | 5ed31309b6d0db94ccd566914653d367f4577c64 (patch) | |
| tree | b909445125629181eb8aa38e4805f672bdaf9c20 /app/tests/test_tui.py | |
| parent | 0dda9a5921eafd03853d233e077138ff72d64e4d (diff) | |
| download | tts-audiobook-generator-5ed31309b6d0db94ccd566914653d367f4577c64.tar.gz | |
fix: japanese characters not truncated correctly in tui terminal output
Diffstat (limited to 'app/tests/test_tui.py')
| -rw-r--r-- | app/tests/test_tui.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/tests/test_tui.py b/app/tests/test_tui.py index 6fc3fd5..4c8b431 100644 --- a/app/tests/test_tui.py +++ b/app/tests/test_tui.py @@ -1501,6 +1501,31 @@ class TextViewerTests(TuiTestCase): self.assertTrue(drawn[0].endswith("~")) +class FitTests(TuiTestCase): + """Column-aware fitting: East Asian Wide characters occupy 2 cells.""" + + def test_disp_width_counts_wide_characters_twice(self): + self.assertEqual(tui._disp_width(""), 0) + self.assertEqual(tui._disp_width("hello"), 5) + self.assertEqual(tui._disp_width("一号"), 4) + self.assertEqual(tui._disp_width("mix語end"), 8) + + def test_fit_truncates_by_display_columns(self): + self.assertEqual(tui._fit("hello", 3), "he~") + self.assertEqual(tui._fit("hi", 10), "hi") + # Exact fit keeps the wide pair; one column more would overflow. + self.assertEqual(tui._fit("你好", 4), "你好") + self.assertEqual(tui._fit("你好你好", 5), "你好~") + self.assertEqual(tui._fit("こんにちは", 3), "こ~") + + def test_wrap_segments_counts_wide_characters_twice(self): + # "語 語 語" is 8 cells, so at width 5 only two words fit per + # line even though 5 characters would fit by count. + lines = tui._wrap_segments([("語 語 語", None)], 5) + self.assertEqual(["".join(t for t, _ in line) for line in lines], + ["語 語", "語"]) + + class WizardTests(unittest.TestCase): """The tui.Wizard screen-stack driver: Esc steps back one screen.""" |
