1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
from textual.widgets.text_area import Document
TEXT = """I must not fear.
Fear is the mind-killer."""
def test_insert_no_newlines():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), " really")
assert document.lines == [
"I really must not fear.",
"Fear is the mind-killer.",
]
def test_insert_empty_string():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), "")
assert document.lines == ["I must not fear.", "Fear is the mind-killer."]
def test_insert_invalid_column():
document = Document(TEXT)
document.replace_range((0, 999), (0, 999), " really")
assert document.lines == ["I must not fear. really", "Fear is the mind-killer."]
def test_insert_invalid_row_and_column():
document = Document(TEXT)
document.replace_range((999, 0), (999, 0), " really")
assert document.lines == ["I must not fear.", "Fear is the mind-killer.", " really"]
def test_insert_range_newline_file_start():
document = Document(TEXT)
document.replace_range((0, 0), (0, 0), "\n")
assert document.lines == ["", "I must not fear.", "Fear is the mind-killer."]
def test_insert_newline_splits_line():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), "\n")
assert document.lines == ["I", " must not fear.", "Fear is the mind-killer."]
def test_insert_newline_splits_line_selection():
document = Document(TEXT)
document.replace_range((0, 1), (0, 6), "\n")
assert document.lines == ["I", " not fear.", "Fear is the mind-killer."]
def test_insert_multiple_lines_ends_with_newline():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), "Hello,\nworld!\n")
assert document.lines == [
"IHello,",
"world!",
" must not fear.",
"Fear is the mind-killer.",
]
def test_insert_multiple_lines_ends_with_no_newline():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), "Hello,\nworld!")
assert document.lines == [
"IHello,",
"world! must not fear.",
"Fear is the mind-killer.",
]
def test_insert_multiple_lines_starts_with_newline():
document = Document(TEXT)
document.replace_range((0, 1), (0, 1), "\nHello,\nworld!\n")
assert document.lines == [
"I",
"Hello,",
"world!",
" must not fear.",
"Fear is the mind-killer.",
]
def test_insert_range_text_no_newlines():
"""Ensuring we can do a simple replacement of text."""
document = Document(TEXT)
document.replace_range((0, 2), (0, 6), "MUST")
assert document.lines == [
"I MUST not fear.",
"Fear is the mind-killer.",
]
TEXT_NEWLINE_EOF = """\
I must not fear.
Fear is the mind-killer.
"""
def test_newline_eof():
document = Document(TEXT_NEWLINE_EOF)
assert document.lines == [
"I must not fear.",
"Fear is the mind-killer.",
"",
]
|