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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
|
import pytest
from urwid_readline import ReadlineEdit
@pytest.mark.parametrize("set_pos, end_pos", [(100, 3), (-1, 0)])
def test_edit_pos_clamp(set_pos, end_pos):
edit = ReadlineEdit(edit_text="asd", edit_pos=0)
assert edit.edit_pos == 0
edit.edit_pos = set_pos
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[("ab", 2, 1), ("ab", 1, 0), ("ab", 0, 0)],
)
def test_backward_char(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.backward_char()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[("ab", 0, 1), ("ab", 1, 2), ("ab", 2, 2)],
)
def test_forward_char(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.forward_char()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("ab", 2, 0),
("ab", 1, 0),
("line 1\nline 2", 13, 7),
("line 1\nline 2", 8, 7),
("line 1\nline 2", 7, 0),
("line 1\nline 2", 6, 0),
("line 1\nline 2", 1, 0),
("line 1\nline 2", 0, 0),
],
)
def test_beginnining_of_line(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.beginning_of_line()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("ab", 0, 2),
("ab", 1, 2),
("ab", 2, 2),
("line 1\nline 2", 0, 6),
("line 1\nline 2", 1, 6),
("line 1\nline 2", 5, 6),
("line 1\nline 2", 6, 13),
("line 1\nline 2", 7, 13),
("line 1\nline 2", 8, 13),
("line 1\nline 2", 13, 13),
],
)
def test_end_of_line(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.end_of_line()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("'x'", 3, 1),
("'x'", 2, 1),
("'x'", 1, 0),
("'x'", 0, 0),
("'x' x", 4, 1),
("'x' x", 3, 1),
("'x' x", 2, 1),
("'x' x", 1, 0),
("'x'' x", 5, 1),
("'x'' x", 4, 1),
("'x'' x", 3, 1),
("'x'' x", 2, 1),
("'x'' x", 1, 0),
("'x'' x'", 6, 5),
("'x'' x'", 5, 1),
("'x'' x'", 4, 1),
("'x'' x'", 3, 1),
("'x'' x'", 2, 1),
("'x'' x'", 1, 0),
("xx'xx x", 7, 6),
("xx'xx x", 6, 3),
("xx'xx x", 3, 0),
],
)
def test_backward_word(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.backward_word()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("'x'", 0, 1),
("'x'", 1, 3),
("'x'", 2, 3),
("'x'", 3, 3),
("'x' x", 1, 4),
("'x' x", 2, 4),
("'x' x", 3, 4),
("'x' x", 4, 5),
("'x'' x", 1, 5),
("'x'' x", 2, 5),
("'x'' x", 3, 5),
("'x'' x", 4, 5),
("'x'' x", 5, 6),
("'x'' x'", 1, 5),
("'x'' x'", 2, 5),
("'x'' x'", 3, 5),
("'x'' x'", 4, 5),
("'x'' x'", 5, 7),
("'x'' x'", 6, 7),
("xx'xx x", 0, 3),
("xx'xx x", 3, 6),
],
)
def test_forward_word(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.forward_word()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("abc", 0, "bc", 0),
("abc", 1, "ac", 1),
("abc", 2, "ab", 2),
("abc", 3, "abc", 3),
],
)
def test_delete_char(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.delete_char()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("abc", 3, "ab", 2),
("abc", 2, "ac", 1),
("abc", 1, "bc", 0),
("abc", 0, "abc", 0),
],
)
def test_backward_delete_char(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.backward_delete_char()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("ab", 0, 0),
("ab", 1, 1),
("ab", 2, 2),
("line 1\nline 2", 13, 6),
("line 1\nline 2", 8, 1),
("line 1\nline 2", 7, 0),
("line 1\nline 2", 6, 6),
("line 1\nline 2", 1, 1),
("line 1\nline 2", 0, 0),
],
)
def test_previous_line(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.previous_line()
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_pos",
[
("ab", 0, 0),
("ab", 1, 1),
("ab", 2, 2),
("line 1\nline 2", 0, 7),
("line 1\nline 2", 1, 8),
("line 1\nline 2", 6, 13),
("line 1\nline 2", 7, 7),
("line 1\nline 2", 8, 8),
("line 1\nline 2", 13, 13),
],
)
def test_next_line(start_text, start_pos, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.next_line()
assert edit.edit_pos == end_pos
def test_clear_screen():
edit = ReadlineEdit(edit_text="line 1\nline 2", edit_pos=4)
edit.clear_screen()
assert edit.edit_pos == 0
assert edit.edit_text == ""
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("", 0, "", 0),
("ab", 1, "b", 0),
("line 1\nline 2", 0, "line 1\nline 2", 0),
("line 1\nline 2", 1, "ine 1\nline 2", 0),
("line 1\nline 2", 6, "\nline 2", 0),
("line 1\nline 2", 7, "line 1\nline 2", 7),
("line 1\nline 2", 8, "line 1\nine 2", 7),
("line 1\nline 2", 13, "line 1\n", 7),
("line 1\nline 2\nline 3", 7, "line 1\nline 2\nline 3", 7),
("line 1\nline 2\nline 3", 8, "line 1\nine 2\nline 3", 7),
("line 1\nline 2\nline 3", 13, "line 1\n\nline 3", 7),
],
)
def test_backward_kill_line(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.backward_kill_line()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("", 0, "", 0),
("ab", 1, "a", 1),
("line 1\nline 2", 0, "\nline 2", 0),
("line 1\nline 2", 1, "l\nline 2", 1),
("line 1\nline 2", 6, "line 1\nline 2", 6),
("line 1\nline 2", 7, "line 1\n", 7),
("line 1\nline 2", 8, "line 1\nl", 8),
("line 1\nline 2", 13, "line 1\nline 2", 13),
("line 1\nline 2\nline 3", 7, "line 1\n\nline 3", 7),
("line 1\nline 2\nline 3", 8, "line 1\nl\nline 3", 8),
("line 1\nline 2\nline 3", 13, "line 1\nline 2\nline 3", 13),
],
)
def test_forward_kill_line(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.forward_kill_line()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("", 0, "", 0),
("ab", 1, "", 0),
("line 1\nline 2", 0, "\nline 2", 0),
("line 1\nline 2", 6, "\nline 2", 0),
("line 1\nline 2", 7, "line 1\n", 7),
("line 1\nline 2", 13, "line 1\n", 7),
("line 1\nline 2\nline 3", 7, "line 1\n\nline 3", 7),
("line 1\nline 2\nline 3", 8, "line 1\n\nline 3", 7),
("line 1\nline 2\nline 3", 13, "line 1\n\nline 3", 7),
],
)
def test_kill_whole_line(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.kill_whole_line()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("'x'", 3, "'", 1),
("'x'", 2, "''", 1),
("'x'", 1, "x'", 0),
("'x'", 0, "'x'", 0),
("'x' x", 4, "'x", 1),
("'x' x", 3, "' x", 1),
("'x' x", 2, "'' x", 1),
("'x' x", 1, "x' x", 0),
("'x'' x", 5, "'x", 1),
("'x'' x", 4, "' x", 1),
("'x'' x", 3, "'' x", 1),
("'x'' x", 2, "''' x", 1),
("'x'' x", 1, "x'' x", 0),
("'x'' x'", 6, "'x'' '", 5),
("'x'' x'", 5, "'x'", 1),
("'x'' x'", 4, "' x'", 1),
("'x'' x'", 3, "'' x'", 1),
("'x'' x'", 2, "''' x'", 1),
("'x'' x'", 1, "x'' x'", 0),
("xx'xx x", 7, "xx'xx ", 6),
("xx'xx x", 6, "xx'x", 3),
("xx'xx x", 3, "xx x", 0),
],
)
def test_backward_kill_word(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.backward_kill_word()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("'x'", 1, "'", 1),
("'x'", 2, "'x", 2),
("'x'", 3, "'x'", 3),
("'x' x", 1, "'x", 1),
("'x' x", 2, "'xx", 2),
("'x' x", 3, "'x'x", 3),
("'x' x", 4, "'x' ", 4),
("'x'' x", 1, "'x", 1),
("'x'' x", 2, "'xx", 2),
("'x'' x", 3, "'x'x", 3),
("'x'' x", 4, "'x''x", 4),
("'x'' x", 5, "'x'' ", 5),
("'x'' x'", 1, "'x'", 1),
("'x'' x'", 2, "'xx'", 2),
("'x'' x'", 3, "'x'x'", 3),
("'x'' x'", 4, "'x''x'", 4),
("'x'' x'", 5, "'x'' ", 5),
("'x'' x'", 6, "'x'' x", 6),
("xx'xx x", 0, "xx x", 0),
("xx'xx x", 3, "xx'x", 3),
],
)
def test_kill_word(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.kill_word()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.mark.parametrize(
"start_text, start_pos, end_text, end_pos",
[
("a", 0, "a", 1),
("a", 1, "a", 1),
("abc", 0, "bac", 2),
("abc", 1, "bac", 2),
("abc", 2, "acb", 3),
("abc", 3, "acb", 3),
("line 1\nline 2", 6, "line1 \nline 2", 6),
("line 1\nline 2", 7, "line 1\nilne 2", 9),
("line 1\nline 2", 8, "line 1\nilne 2", 9),
("line 1\nline 2", 9, "line 1\nlnie 2", 10),
("line 1\nline 2", 10, "line 1\nlien 2", 11),
("line 1\nline 2", 13, "line 1\nline2 ", 13),
],
)
def test_transpose(start_text, start_pos, end_text, end_pos):
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
edit.transpose_chars()
assert edit.text == end_text
assert edit.edit_pos == end_pos
@pytest.fixture
def completion_func_for_source():
def _factory(source):
def compl(text, state):
tmp = (
[c for c in source if c and c.startswith(text)]
if text
else source
)
try:
return tmp[state]
except (IndexError, TypeError):
return None
return compl
return _factory
@pytest.mark.parametrize(
"start_text, start_pos, source, positions",
[
(
"",
0,
["start", "stop", "next"],
[("start", 5), ("stop", 4), ("next", 4), ("", 0), ("start", 5)],
),
(
"non-matching",
12,
["start", "stop", "next"],
[("non-matching", 12), ("non-matching", 12)],
),
(
"s",
1,
["start", "stop", "next"],
[("start", 5), ("stop", 4), ("s", 1)],
),
(
"trailing",
0,
["start", "stop", "next"],
[
("starttrailing", 5),
("stoptrailing", 4),
("nexttrailing", 4),
("trailing", 0),
],
),
(
"trailing trailing",
0,
["start", "stop", "next"],
[
("starttrailing trailing", 5),
("stoptrailing trailing", 4),
("nexttrailing trailing", 4),
("trailing trailing", 0),
],
),
(
"strailing trailing",
1,
["start", "stop", "next"],
[
("starttrailing trailing", 5),
("stoptrailing trailing", 4),
("strailing trailing", 1),
],
),
(
"preceding s",
11,
["start", "stop", "next"],
[
("preceding start", 15),
("preceding stop", 14),
("preceding s", 11),
],
),
(
"multiline\npreceding s\ntrailing",
21,
["start", "stop", "next"],
[
("multiline\npreceding start\ntrailing", 25),
("multiline\npreceding stop\ntrailing", 24),
("multiline\npreceding s\ntrailing", 21),
],
),
],
)
@pytest.mark.parametrize("autocomplete_key", [None, "tab", "ctrl q"])
def test_enable_autocomplete(
completion_func_for_source,
start_text,
start_pos,
source,
positions,
autocomplete_key,
):
keypress = autocomplete_key if autocomplete_key else "tab"
compl = completion_func_for_source(source)
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
kwargs = {}
if autocomplete_key:
kwargs["key"] = autocomplete_key
edit.enable_autocomplete(compl, **kwargs)
for position in positions:
expected_text, expected_pos = position
edit.keypress(None, keypress)
assert edit.edit_text == expected_text
assert edit.edit_pos == expected_pos
@pytest.mark.parametrize(
"start_text, start_pos, edits",
[
("", 0, [("forward", "start", 5), ("reverse", "", 0)]),
(
"",
0,
[
("reverse", "next", 4),
("reverse", "stop", 4),
("reverse", "start", 5),
("reverse", "", 0),
],
),
(
"",
0,
[
("forward", "start", 5),
("forward", "stop", 4),
("forward", "next", 4),
("reverse", "stop", 4),
],
),
(
"",
0,
[
("forward", "start", 5),
("forward", "stop", 4),
("forward", "next", 4),
("forward", "", 0),
("forward", "start", 5),
],
),
(
"",
0,
[("reverse", "next", 4), ("forward", "", 0)],
),
(
"st",
2,
[
("forward", "start", 5),
("reverse", "st", 2),
("reverse", "stop", 4),
],
),
],
)
@pytest.mark.parametrize(
"autocomplete_key, autocomplete_key_reverse",
[
(None, None),
("tab", "shift tab"),
("ctrl q", "ctrl m"),
],
)
def test_enable_autocomplete_reverse(
completion_func_for_source,
start_text,
start_pos,
edits,
autocomplete_key,
autocomplete_key_reverse,
):
source = ["start", "stop", "next"]
keypress = autocomplete_key if autocomplete_key else "tab"
keypress_reverse = (
autocomplete_key_reverse if autocomplete_key_reverse else "shift tab"
)
compl = completion_func_for_source(source)
edit = ReadlineEdit(edit_text=start_text, edit_pos=start_pos)
kwargs = {}
if autocomplete_key:
kwargs["key"] = autocomplete_key
if autocomplete_key_reverse:
kwargs["key_reverse"] = autocomplete_key_reverse
edit.enable_autocomplete(compl, **kwargs)
for direction, expected_text, expected_pos in edits:
if direction == "forward":
edit.keypress(None, keypress)
else:
edit.keypress(None, keypress_reverse)
assert edit.edit_text == expected_text
assert edit.edit_pos == expected_pos
def test_enable_autocomplete_clear_state(completion_func_for_source):
source = ["start", "stop", "next"]
compl = completion_func_for_source(source)
edit = ReadlineEdit(edit_text="s", edit_pos=1)
edit.enable_autocomplete(compl)
edit.keypress(edit.size, "tab")
assert edit.edit_text == "start"
assert edit.edit_pos == 5
edit.keypress(edit.size, "home")
edit.keypress(edit.size, "right")
assert edit.edit_pos == 1
edit.keypress(edit.size, "tab")
assert edit.edit_text == "starttart"
assert edit.edit_pos == 5
@pytest.mark.parametrize(
"autocomplete_delimiters, word_separator, final_phrase",
[
(None, " ", "firstw firstw secondw"),
(None, ";", "firstw;firstw;secondw"),
(";", " ", "firstw secondw"),
(";", ";", "firstw;firstw;secondw"),
("#", " ", "firstw secondw"),
("", " ", "firstw secondw"),
("", "-", "firstw-secondw"),
],
ids=[
"default:space/tab/newline/semicolon-space",
"default:space/tab/newline/semicolon-semicolon",
"custom:semicolon-space",
"custom:semicolon-semicolon",
"custom:hash-space",
"no delimiters-space", # matches from start of text box
"no delimiters-hyphen", # matches from start of text box
],
)
def test_autocomplete_delimiters(
completion_func_for_source,
autocomplete_delimiters,
word_separator,
final_phrase,
word1="firstw",
word2="secondw",
):
phrase = word_separator.join([word1, word2])
phrase_length = len(phrase)
source = [phrase]
compl = completion_func_for_source(source)
edit = ReadlineEdit(edit_text=word1, edit_pos=len(word1))
edit.enable_autocomplete(compl)
if autocomplete_delimiters is not None:
edit.set_completer_delims(autocomplete_delimiters)
# Completion from word1 to phrase
edit.keypress(edit.size, "tab")
assert edit.edit_text == phrase
assert edit.edit_pos == phrase_length
# Backspace to after word1 + space
for _ in range(len(word2)):
edit.keypress(edit.size, "backspace")
assert edit.edit_text == word1 + word_separator
assert edit.edit_pos == len(word1) + 1
# Completion from word1 + word_separator
edit.keypress(edit.size, "tab")
assert edit.edit_text == final_phrase
assert edit.edit_pos == len(final_phrase)
@pytest.mark.parametrize(
"keys, expected_edit_pos, expected_text",
[
([], 0, ""),
(["F"], 0, ""),
(["F", "O"], 1, "F"),
(["F", "O", "O"], 2, "FO"),
(["F", "O", "O", "ctrl w"], 3, "FOO"),
(["F", "O", "O", "ctrl w", "ctrl _"], 2, "FO"),
(["a", "s", "d", "ctrl u", "ctrl u"], 3, "asd"),
],
)
def test_undo(keys, expected_edit_pos, expected_text):
edit = ReadlineEdit()
for key in keys:
edit.keypress(edit.size, key)
edit.undo()
assert edit.edit_pos == expected_edit_pos
assert edit.text == expected_text
@pytest.mark.parametrize(
"paste_buffer, text, max_char, pos, expected_pos, expected_text",
[
(["OO"], "F", None, 1, 3, "FOO"),
(["BOO", "FOO"], "", None, 0, 3, "FOO"),
(["BCDE"], "A", 3, 1, 3, "ABC"),
(["FOO", "BOO", "FOOBAR"], "", 3, 0, 3, "FOO"),
(["FOOBAR"], "BAR", 3, 0, 0, "BAR"),
],
)
def test_paste(paste_buffer, text, max_char, pos, expected_pos, expected_text):
edit = ReadlineEdit(edit_text=text, max_char=max_char, edit_pos=pos)
edit._paste_buffer[:] = paste_buffer
edit.paste()
assert edit.edit_pos == expected_pos
assert edit.edit_text == expected_text
@pytest.mark.parametrize(
"text, key, max_char, pos, expected_pos, expected_text",
[
("FOAA", "S", None, 4, 5, "FOAAS"),
("FOOBAR", "A", 3, 3, 3, "FOO"),
("OO", "F", 3, 0, 1, "FOO"),
("ABCDE", "F", 4, 3, 3, "ABCD"),
],
)
def test_insert_char_at_cursor(
text, key, max_char, pos, expected_pos, expected_text
):
edit = ReadlineEdit(edit_text=text, max_char=max_char, edit_pos=pos)
edit._insert_char_at_cursor(key)
assert edit.edit_pos == expected_pos
assert edit.edit_text == expected_text
|