Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import unittest
|
|
|
|
from textkit import wrap_text
|
|
|
|
|
|
class WrapTextTests(unittest.TestCase):
|
|
def test_short_text_is_one_line(self):
|
|
self.assertEqual(wrap_text("hello world", 20), ["hello world"])
|
|
|
|
def test_exact_width_fits(self):
|
|
self.assertEqual(wrap_text("abc def", 7), ["abc def"])
|
|
|
|
def test_breaks_between_words(self):
|
|
self.assertEqual(wrap_text("the quick brown fox", 10), ["the quick", "brown fox"])
|
|
|
|
def test_collapses_whitespace(self):
|
|
self.assertEqual(wrap_text("a b\n c", 10), ["a b c"])
|
|
|
|
def test_empty_text(self):
|
|
self.assertEqual(wrap_text("", 5), [])
|
|
|
|
def test_long_word_is_split(self):
|
|
self.assertEqual(wrap_text("abcdefghij", 4), ["abcd", "efgh", "ij"])
|
|
|
|
def test_long_word_between_words(self):
|
|
self.assertEqual(wrap_text("go extraordinary now", 6), ["go", "extrao", "rdinar", "y now"])
|
|
|
|
def test_invalid_width(self):
|
|
with self.assertRaises(ValueError):
|
|
wrap_text("x", 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|