Skip to content

Commit 6cda21d

Browse files
committed
port pagination tests
1 parent 28001f7 commit 6cda21d

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from unittest import TestCase
2+
3+
from pydis_core.utils import pagination
4+
5+
6+
class LinePaginatorTests(TestCase):
7+
"""Tests functionality of the `LinePaginator`."""
8+
9+
def setUp(self):
10+
"""Create a paginator for the test method."""
11+
self.paginator = pagination.LinePaginator(prefix="", suffix="", max_size=30,
12+
scale_to_size=50)
13+
14+
def test_add_line_works_on_small_lines(self):
15+
"""`add_line` should allow small lines to be added."""
16+
self.paginator.add_line("x" * (self.paginator.max_size - 3))
17+
# Note that the page isn't added to _pages until it's full.
18+
self.assertEqual(len(self.paginator._pages), 0)
19+
20+
def test_add_line_works_on_long_lines(self):
21+
"""After additional lines after `max_size` is exceeded should go on the next page."""
22+
self.paginator.add_line("x" * self.paginator.max_size)
23+
self.assertEqual(len(self.paginator._pages), 0)
24+
25+
# Any additional lines should start a new page after `max_size` is exceeded.
26+
self.paginator.add_line("x")
27+
self.assertEqual(len(self.paginator._pages), 1)
28+
29+
def test_add_line_continuation(self):
30+
"""When `scale_to_size` is exceeded, remaining words should be split onto the next page."""
31+
self.paginator.add_line("zyz " * (self.paginator.scale_to_size // 4 + 1))
32+
self.assertEqual(len(self.paginator._pages), 1)
33+
34+
def test_add_line_no_continuation(self):
35+
"""If adding a new line to an existing page would exceed `max_size`, it should start a new
36+
page rather than using continuation.
37+
"""
38+
self.paginator.add_line("z" * (self.paginator.max_size - 3))
39+
self.paginator.add_line("z")
40+
self.assertEqual(len(self.paginator._pages), 1)
41+
42+
def test_add_line_truncates_very_long_words(self):
43+
"""`add_line` should truncate if a single long word exceeds `scale_to_size`."""
44+
self.paginator.add_line("x" * (self.paginator.scale_to_size + 1))
45+
# Note: item at index 1 is the truncated line, index 0 is prefix
46+
self.assertEqual(self.paginator._current_page[1], "x" * self.paginator.scale_to_size)

0 commit comments

Comments
 (0)