aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_tui.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests/test_tui.py')
-rw-r--r--app/tests/test_tui.py25
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."""