From 1fb31ad97c1e1cad4a34c2fdf34b4621d7164291 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Wed, 25 Dec 2019 22:34:43 +0000 Subject: [PATCH] text tests --- rich/text.py | 4 ++-- tests/test_text.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/rich/text.py b/rich/text.py index 2127361b..24f2ef99 100644 --- a/rich/text.py +++ b/rich/text.py @@ -463,8 +463,8 @@ class Text: break span = new_span line_index += 1 - if line_index >= len(line_ranges): - break + # if line_index >= len(line_ranges): + # break line_start, line_end = line_ranges[line_index] return new_lines diff --git a/tests/test_text.py b/tests/test_text.py index 9882383f..c4413845 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -197,6 +197,32 @@ def test_divide(): assert lines[1]._spans == [Span(0, 1, "bold")] assert lines[2]._spans == [Span(0, 1, "bold")] + text = Text() + text.append("foo", "red") + text.append("bar", "green") + text.append("baz", "blue") + lines = text.divide([8]) + assert len(lines) == 2 + assert str(lines[0]) == "foobarba" + assert str(lines[1]) == "z" + assert lines[0]._spans == [ + Span(0, 3, "red"), + Span(3, 6, "green"), + Span(6, 8, "blue"), + ] + assert lines[1]._spans == [Span(0, 1, "blue")] + + lines = text.divide([1]) + assert len(lines) == 2 + assert str(lines[0]) == "f" + assert str(lines[1]) == "oobarbaz" + assert lines[0]._spans == [Span(0, 1, "red")] + assert lines[1]._spans == [ + Span(0, 2, "red"), + Span(2, 5, "green"), + Span(5, 8, "blue"), + ] + def test_right_crop(): test = Text()