text tests

This commit is contained in:
Will McGugan 2019-12-25 22:34:43 +00:00
parent 0f5c49c8a6
commit 1fb31ad97c
2 changed files with 28 additions and 2 deletions

View File

@ -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

View File

@ -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()