Skip to content

Commit 9b22e47

Browse files
authored
Merge pull request #11 from python-tableformatter/unit_tests
Added more unit tests related to text wrapping
2 parents fdce34d + e83867a commit 9b22e47

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

tests/test_utils.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
22
"""
3-
Unit testing of tableformatter utility functtions.
3+
Unit testing of tableformatter utility functions.
44
"""
55
import pytest
66

@@ -11,15 +11,26 @@
1111
def empty_text():
1212
return ''
1313

14-
1514
@pytest.fixture
1615
def sample_text():
1716
return 'FooBar'
1817

18+
@pytest.fixture
19+
def long_text():
20+
return 'FooBarBaz'
21+
1922
@pytest.fixture
2023
def tabbed_text():
2124
return 'Foo\tBar'
2225

26+
@pytest.fixture
27+
def multiline_text():
28+
return 'FooBar\nBaz'
29+
30+
@pytest.fixture
31+
def whitespace_text():
32+
return 'FooBar \n '
33+
2334

2435
# Test text wrapping
2536
def test_empty_wrap(empty_text):
@@ -37,6 +48,26 @@ def test_simple_wrap(sample_text):
3748
wrapped = tf._text_wrap(sample_text, width=3)
3849
assert expected == wrapped
3950

51+
def test_double_wrap(long_text):
52+
expected = ['Foo', 'Bar', 'Baz']
53+
wrapped = tf._text_wrap(long_text, width=3)
54+
assert expected == wrapped
55+
56+
def test_multiline_no_wrap(multiline_text):
57+
expected = ['FooBar Baz']
58+
wrapped = tf._text_wrap(multiline_text)
59+
assert expected == wrapped
60+
61+
def test_multiline_with_wrap(multiline_text):
62+
expected = ['Foo', 'Bar', 'Baz']
63+
wrapped = tf._text_wrap(multiline_text, width=3)
64+
assert expected == wrapped
65+
66+
def test_trailing_whitespace_wrap(whitespace_text):
67+
expected = ['FooBar']
68+
wrapped = tf._text_wrap(whitespace_text)
69+
assert expected == wrapped
70+
4071

4172
# Test tab translation and printable width calculation
4273
def test_empty_translation(empty_text):

0 commit comments

Comments
 (0)