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 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
|
unit TestNavigation;
(* TODO:
Word Left/Right: Need tests with fold, trim, selection
*)
{$mode objfpc}{$H+}
interface
uses
SysUtils, testregistry, LCLProc, Forms, TestBase,
SynEdit, SynEditKeyCmds;
type
{ TTestSynNavigation }
TTestSynNavigation = class(TTestBase)
published
procedure TestCaretHomeEnd;
procedure TestCaretLeftRight;
procedure TestCaretMoveLeftRightWord;
//procedure TestCaretMoveLeftRightPartWord;
end;
implementation
{ TTestSynNavigation }
procedure TTestSynNavigation.TestCaretHomeEnd;
procedure DoInit1;
begin
ReCreateEdit;
SynEdit.TabWidth := 6;
SyneDit.Options := [];
SyneDit.Options2 := [];
SetLines(['', //1
'',
'test', // 3
'',
'',
' ',
'test', // 3
#9#9#9#9#9,
' spaced', // 9
'',
'',
' ',
' spaced',
#9#9#9#9#9,
#9'tabbed', // 15
'',
'',
' ',
#9'tabbed',
#9#9#9#9#9,
#9' tabbed spaced', // 21
'',
'',
' ',
#9' tabbed spaced',
#9#9#9#9#9,
' ', // 27 (space only)
'',
'',
' ',
#9' ',
#9#9#9#9#9,
' spaced 9 for tab', // 33
#9#9#9#9#9,
' X ', // 35
' X'#9, // 36
''
]);
end;
procedure TestHome(Name:String; X, Y, ExpX1, ExpX2, ExpX3: Integer; ExpLTxTStartX: Integer = -1);
begin
SetCaretPhys(X, Y);
synedit.CommandProcessor(ecLineStart, '', nil);
TestIsCaretPhys(Name + '(1st home)', ExpX1,Y);
synedit.CommandProcessor(ecLineStart, '', nil);
TestIsCaretPhys(Name + '(2nd home)', ExpX2,Y);
synedit.CommandProcessor(ecLineStart, '', nil);
TestIsCaretPhys(Name + '(3rd home)', ExpX3,Y);
if ExpLTxTStartX > 0 then begin
SetCaretPhys(X, Y);
synedit.CommandProcessor(ecLineTextStart, '', nil);
TestIsCaretPhys(Name + '(1st line-text-start)', ExpLTxTStartX,Y);
synedit.CommandProcessor(ecLineTextStart, '', nil);
TestIsCaretPhys(Name + '(2nd line-text-start)', ExpLTxTStartX,Y);
synedit.CommandProcessor(ecLineTextStart, '', nil);
TestIsCaretPhys(Name + '(3rd line-text-start)', ExpLTxTStartX,Y);
end;
end;
procedure TestEnd(Name:String; X, Y, ExpX1, ExpX2, ExpX3: Integer);
begin
SetCaretPhys(X, Y);
synedit.CommandProcessor(ecLineEnd, '', nil);
TestIsCaretPhys(Name + '(1st end)', ExpX1,Y);
synedit.CommandProcessor(ecLineEnd, '', nil);
TestIsCaretPhys(Name + '(2nd end)', ExpX2,Y);
synedit.CommandProcessor(ecLineEnd, '', nil);
TestIsCaretPhys(Name + '(3rd end)', ExpX3,Y);
end;
begin
// None Smart-Home:
// Caret goes x=1, then x=indend
// Smart-Home:
// Caret goes x=indent, then 1, IF AFTER indent, or at x=1
// Caret goes x=1, then x=indend, IF at x=indent, or inside indent
// Both
// Caret does not go past eol, unless explicitly enabled
// if spaces/tab exist at start of otherwise empty line, caret will go to prev-line indent
{%region}
DoInit1;
PushBaseName('no smart / no past-eol');
TestHome('empty 1st line', 1, 1, 1,1,1, 1);
TestHome('empty 2nd line', 1, 2, 1,1,1, 1);
TestHome('unindented line', 1, 3, 1,1,1, 1);
TestHome('unindented line x-in-line', 4, 3, 1,1,1, 1);
TestHome('1st line after unindendet', 1, 4, 1,1,1, 1);
TestHome('2nd line after unindendet', 1, 5, 1,1,1, 1);
TestHome('3rd #32 line after unindendet', 2, 6, 1,1,1, 1);
TestHome('4th #9 line after unindendet', 2, 8, 1,1,1, 1);
TestHome('space indented line', 1, 9, 4,1,4, 4);
TestHome('space indented line x-after-indent', 4, 9, 1,4,1, 4); // go to indent, after absolute home
TestHome('space indented line x-in-indent', 3, 9, 1,4,1, 4);
TestHome('space indented line x-in-line', 6, 9, 1,4,1, 4);
TestHome('1st after space indented line', 1,10, 1,1,1, 1);
TestHome('2nd after space indented line', 1,11, 1,1,1, 1);
TestHome('3rd #32 after space indented line', 2,12, 1,4,1, 1);
TestHome('4th #9 after space indented line', 2,14, 1,4,1, 1);
TestHome('#9 after long space indented line', 2,34, 1,9,1, 1);
SyneDit.Options2 := SyneDit.Options2 + [eoCaretSkipTab];
TestHome('4th #9 after space indented line [skipT]', 7,14, 1,1,1, 1);
TestHome('#9 after long space indented line [skipT]', 1,34, 7,1,7, 1);
TestHome('#9 after long space indented line [skipT]', 7,34, 1,7,1, 1);
TestHome('#9 after long space indented line [skipT]', 13,34, 1,7,1, 1);
SyneDit.Options2 := SyneDit.Options2 - [eoCaretSkipTab];
TestHome('tab indented line', 1,15, 7,1,7, 7);
TestHome('tab indented line x-after-indent', 7,15, 1,7,1, 7);
TestHome('tab indented line x-in-indent', 5,15, 1,7,1, 7);
TestHome('tab indented line x-in-line', 9,15, 1,7,1, 7);
TestHome('1st after tab indented line', 1,16, 1,1,1, 1);
TestHome('2nd after tab indented line', 1,17, 1,1,1, 1);
TestHome('3rd #32 after tab indented line', 2,18, 1,7,1, 1);
TestHome('4th #9 after tab indented line', 2,20, 1,7,1, 1);
{%endregion}
{%region}
DoInit1;
SyneDit.Options := [eoScrollPastEol];
PopPushBaseName('no smart / past-eol');
TestHome('empty 1st line', 1, 1, 1,1,1, 1);
TestHome('empty 2nd line', 1, 2, 1,1,1, 1);
TestHome('unindented line', 1, 3, 1,1,1, 1);
TestHome('unindented line x-in-line', 4, 3, 1,1,1, 1);
TestHome('1st line after unindendet', 1, 4, 1,1,1, 1);
TestHome('2nd line after unindendet', 1, 5, 1,1,1, 1);
TestHome('3rd #32 line after unindendet', 2, 6, 1,1,1, 1);
TestHome('4th #9 line after unindendet', 2, 8, 1,1,1, 1);
TestHome('space indented line', 1, 9, 4,1,4, 4);
TestHome('space indented line x-after-indent', 4, 9, 1,4,1, 4); // go to indent, after absolute home
TestHome('space indented line x-in-indent', 3, 9, 1,4,1, 4);
TestHome('space indented line x-in-line', 6, 9, 1,4,1, 4);
TestHome('1st after space indented line', 1,10, 4,1,4, 1);
TestHome('1st after space indented line (x)', 2,10, 1,4,1, 1);
TestHome('2nd after space indented line', 1,11, 4,1,4, 1);
TestHome('3rd #32 after space indented line', 2,12, 1,4,1, 1);
TestHome('4th #9 after space indented line', 2,14, 1,4,1, 1);
TestHome('#9 after long space indented line', 2,34, 1,9,1, 1);
SyneDit.Options2 := SyneDit.Options2 + [eoCaretSkipTab];
TestHome('4th #9 after space indented line [skipT]', 7,14, 1,1,1, 1);
TestHome('#9 after long space indented line [skipT]', 1,34, 7,1,7, 1);
TestHome('#9 after long space indented line [skipT]', 7,34, 1,7,1, 1);
TestHome('#9 after long space indented line [skipT]', 13,34, 1,7,1, 1);
SyneDit.Options2 := SyneDit.Options2 - [eoCaretSkipTab];
TestHome('tab indented line', 1,15, 7,1,7, 7);
TestHome('tab indented line x-after-indent', 7,15, 1,7,1, 7);
TestHome('tab indented line x-in-indent', 5,15, 1,7,1, 7);
TestHome('tab indented line x-in-line', 9,15, 1,7,1, 7);
TestHome('1st after tab indented line', 1,16, 7,1,7, 1);
TestHome('1st after tab indented line(x)', 2,16, 1,7,1, 1);
TestHome('2nd after tab indented line', 1,17, 7,1,7, 1);
TestHome('3rd #32 after tab indented line', 2,18, 1,7,1, 1);
TestHome('4th #9 after tab indented line', 2,20, 1,7,1, 1);
{%endregion}
{%region}
DoInit1;
SyneDit.Options := [eoEnhanceHomeKey];
PopPushBaseName('smart home / no past-eol');
TestHome('empty 1st line', 1, 1, 1,1,1, 1);
TestHome('empty 2nd line', 1, 2, 1,1,1, 1);
TestHome('unindented line', 1, 3, 1,1,1, 1);
TestHome('unindented line x-in-line', 4, 3, 1,1,1, 1);
TestHome('1st line after unindendet', 1, 4, 1,1,1, 1);
TestHome('2nd line after unindendet', 1, 5, 1,1,1, 1);
TestHome('3rd #32 line after unindendet', 2, 6, 1,1,1, 1);
TestHome('4th #9 line after unindendet', 2, 8, 1,1,1, 1);
TestHome('space indented line', 1, 9, 4,1,4, 4); // go to absolut home (x-=1), after indent
TestHome('space indented line x-after-indent', 4, 9, 1,4,1, 4);
TestHome('space indented line x-in-indent', 3, 9, 1,4,1, 4);
TestHome('space indented line x-in-line', 6, 9, 4,1,4, 4);
TestHome('1st after space indented line', 1,10, 1,1,1, 1);
TestHome('2nd after space indented line', 1,11, 1,1,1, 1);
TestHome('3rd #32 after space indented line', 2,12, 1,4,1, 1);
TestHome('4th #9 after space indented line', 2,14, 1,4,1, 1);
TestHome('#9 after long space indented line', 2,34, 1,9,1, 1);
SyneDit.Options2 := SyneDit.Options2 + [eoCaretSkipTab];
TestHome('4th #9 after space indented line [skipT]', 7,14, 1,1,1, 1);
TestHome('#9 after long space indented line [skipT]', 1,34, 7,1,7, 1);
TestHome('#9 after long space indented line [skipT]', 7,34, 1,7,1, 1);
TestHome('#9 after long space indented line [skipT]', 13,34, 7,1,7, 1);
SyneDit.Options2 := SyneDit.Options2 - [eoCaretSkipTab];
TestHome('tab indented line', 1,15, 7,1,7, 7);
TestHome('tab indented line x-after-indent', 7,15, 1,7,1, 7);
TestHome('tab indented line x-in-indent', 5,15, 1,7,1, 7);
TestHome('tab indented line x-in-line', 9,15, 7,1,7, 7);
TestHome('1st after tab indented line', 1,16, 1,1,1, 1);
TestHome('2nd after tab indented line', 1,17, 1,1,1, 1);
TestHome('3rd #32 after tab indented line', 2,18, 1,7,1, 1);
TestHome('3rd #32 after tab indented line', 11,18, 7,1,7, 1);
TestHome('4th #9 after tab indented line', 2,20, 1,7,1, 1);
{%endregion}
{%region}
DoInit1;
SyneDit.Options := [eoEnhanceHomeKey, eoScrollPastEol];
PopPushBaseName('smart home / past-eol');
TestHome('empty 1st line', 1, 1, 1,1,1, 1);
TestHome('empty 2nd line', 1, 2, 1,1,1, 1);
TestHome('unindented line', 1, 3, 1,1,1, 1);
TestHome('unindented line x-in-line', 4, 3, 1,1,1, 1);
TestHome('1st line after unindendet', 1, 4, 1,1,1, 1);
TestHome('2nd line after unindendet', 1, 5, 1,1,1, 1);
TestHome('3rd #32 line after unindendet', 2, 6, 1,1,1, 1);
TestHome('4th #9 line after unindendet', 2, 8, 1,1,1, 1);
TestHome('space indented line', 1, 9, 4,1,4, 4); // go to absolut home (x-=1), after indent
TestHome('space indented line x-after-indent', 4, 9, 1,4,1, 4);
TestHome('space indented line x-in-indent', 3, 9, 1,4,1, 4);
TestHome('space indented line x-in-line', 6, 9, 4,1,4, 4);
TestHome('1st after space indented line', 1,10, 4,1,4, 1);
TestHome('2nd after space indented line', 1,11, 4,1,4, 1);
TestHome('3rd #32 after space indented line', 2,12, 1,4,1, 1);
TestHome('4th #9 after space indented line', 2,14, 1,4,1, 1);
TestHome('#9 after long space indented line', 2,34, 1,9,1, 1);
SyneDit.Options2 := SyneDit.Options2 + [eoCaretSkipTab];
TestHome('4th #9 after space indented line [skipT]', 7,14, 1,1,1, 1);
TestHome('#9 after long space indented line [skipT]', 7,34, 1,7,1, 1);
SyneDit.Options2 := SyneDit.Options2 - [eoCaretSkipTab];
TestHome('tab indented line', 1,15, 7,1,7, 7);
TestHome('tab indented line x-after-indent', 7,15, 1,7,1, 7);
TestHome('tab indented line x-in-indent', 5,15, 1,7,1, 7);
TestHome('tab indented line x-in-line', 9,15, 7,1,7, 7);
TestHome('1st after tab indented line', 1,16, 7,1,7, 1);
TestHome('1st after tab indented line (x)', 2,16, 1,7,1, 1);
TestHome('2nd after tab indented line', 1,17, 7,1,7, 1);
TestHome('3rd #32 after tab indented line', 2,18, 1,7,1, 1);
TestHome('3rd #32 after tab indented line', 11,18, 7,1,7, 1);
TestHome('4th #9 after tab indented line', 2,20, 1,7,1, 1);
{%endregion}
PopPushBaseName('NO smart end/ NO past-eol');
DoInit1;
TestEnd ('empty 1st line', 1,1, 1,1,1);
TestEnd ('end', 1,35, 6,3,6);
TestEnd ('end tab', 1,36, 7,3,7);
PopPushBaseName('smart end/ NO past-eol');
DoInit1;
SyneDit.Options2 := [eoEnhanceEndKey];
TestEnd ('end', 1,35, 3,6,3);
TestEnd ('end tab', 1,36, 3,7,3);
//SyneDit.Options := [eoScrollPastEol, eoEnhanceHomeKey];
//SyneDit.Options2 := [eoEnhanceEndKey];
end;
procedure TTestSynNavigation.TestCaretLeftRight;
procedure SetTextLeftRight;
begin
ReCreateEdit;
SetLines([ 'ああああああああああああああああああああああ', // 1: Double width at odd pos (start at 1, then every 2)
' ああああああああああああああああああああああ', // 2: Double width at even pos
'', // 3: empty
#9#9#9#9#9#9#9#9, // 4: tabs
'abc'#9'def', // 5: text+tabs
'abc def üüü xyz', // 6: utf8 multibyte
'abc def ü'#9'üü xyz', // 7: utf8 multibyte + tabs
'abc あdefあ123', // 8: Double withs
'abc あdef'#9'あ'#9'123', // 9: Double withs + tabs
'Aa'#$CC#$81'B', // 10: a-accent, in 2 (combining) codepoints)
''
]);
end;
procedure TestLeftRight(AName: String; ALine: Integer; AStartPhysX: Integer; ACommand:TSynEditorCommand;
ExpPhysX, ExpLogX: Integer; ExpRepeatPhysX: Integer = -1; ExpRepeatLogX: Integer = -1;
DoReverse: Boolean = True; DoKeepXDWidth: Boolean = True;
ASelectXEnd: Integer = -1; ExpCaretY: integer = -1);
var
Name2: String;
TestLogFirst: Boolean;
procedure DoCmd;
begin
if ASelectXEnd < 0
then SetCaretPhys(AStartPhysX, ALine)
else SetCaretAndSelPhys(ASelectXEnd, ALine, AStartPhysX, ALine);
SynEdit.ExecuteCommand(ACommand, '', nil);
end;
procedure TestCmd;
begin
DoCmd;
if not TestLogFirst then
TestIsCaretPhys(Name2+'[1]', ExpPhysX, ExpCaretY);
TestIsCaret(Name2+'[1]', ExpLogX, ExpCaretY);
TestIsCaretPhys(Name2+'[1]', ExpPhysX, ExpCaretY);
end;
procedure DoCmdRepeat;
begin
if ExpRepeatPhysX < 0 then exit;
SynEdit.ExecuteCommand(ACommand, '', nil);
end;
procedure TestCmdRepeat;
begin
if ExpRepeatPhysX < 0 then exit;
DoCmdRepeat;
if not TestLogFirst then
TestIsCaretPhys(Name2+'[2]', ExpRepeatPhysX, ExpCaretY);
if ExpRepeatLogX > 0 then
TestIsCaret(Name2+'[2]', ExpRepeatLogX, ExpCaretY);
TestIsCaretPhys(Name2+'[2]', ExpRepeatPhysX, ExpCaretY);
end;
procedure DoCmdReverse(AfterRepeat: Boolean = false);
begin
if not DoReverse then exit;
if AfterRepeat and (ExpRepeatPhysX < 0) then exit; // was never repeated
if ACommand = ecLeft
then SynEdit.ExecuteCommand(ecRight, '', nil)
else SynEdit.ExecuteCommand(ecLeft, '', nil);
end;
procedure TestCmdReverse(AfterRepeat: Boolean = false);
begin
if not DoReverse then exit;
if AfterRepeat and (ExpRepeatPhysX < 0) then exit; // was never repeated
DoCmdReverse(AfterRepeat);
if AfterRepeat then begin
if not TestLogFirst then
TestIsCaretPhys(Name2+'[R,'+dbgs(AfterRepeat)+']', ExpPhysX, ExpCaretY);
TestIsCaret(Name2, ExpLogX, ExpCaretY);
TestIsCaretPhys(Name2+'[R,'+dbgs(AfterRepeat)+']', ExpPhysX, ExpCaretY);
end else begin
TestIsCaretPhys(Name2+'[R,'+dbgs(AfterRepeat)+']', AStartPhysX, ALine);
end;
end;
procedure DoKeepXOnEmpty;
begin
if (ExpPhysX > 1) and not(eoScrollPastEol in SynEdit.Options) then begin
SynEdit.CaretObj.LinePos := 3; // empty line
SynEdit.CaretObj.LinePos := ExpCaretY;
end;
end;
procedure TestKeepXOnEmpty(TestBetween: Boolean = False);
begin
if (ExpPhysX > 1) and not(eoScrollPastEol in SynEdit.Options) then begin
SynEdit.CaretObj.LinePos := 3; // empty line
if TestBetween then
AssertEquals(Name2+'empty line at pos 1', 1, SynEdit.CaretObj.CharPos);
SynEdit.CaretObj.LinePos := ExpCaretY;
if eoKeepCaretX in SynEdit.Options
then AssertEquals(Name2+'after empty line at pos 1', ExpPhysX, SynEdit.CaretObj.CharPos)
else AssertEquals(Name2+'after empty line at pos 1', 1, SynEdit.CaretObj.CharPos);
end;
end;
procedure DoKeepXOnDWidth;
begin
if (ExpPhysX > 1) and DoKeepXDWidth then begin
if (ExpPhysX and 1) = 0
then SynEdit.CaretObj.LinePos := 1 // double width odd
else SynEdit.CaretObj.LinePos := 2; // double width even
SynEdit.CaretObj.LinePos := ExpCaretY;
end;
end;
procedure TestKeepXOnDWidth(TestBetween: Boolean = False);
begin
if (ExpPhysX > 1) and DoKeepXDWidth then begin
if (ExpPhysX and 1) = 0
then SynEdit.CaretObj.LinePos := 1 // double width odd
else SynEdit.CaretObj.LinePos := 2; // double width even
if TestBetween then
AssertFalse(Name2+'after dwidth line at pos 1', ExpPhysX = SynEdit.CaretObj.CharPos);
SynEdit.CaretObj.LinePos := ExpCaretY;
AssertTrue(Name2+'after dwidth line at pos 1',
(ExpPhysX = SynEdit.CaretObj.CharPos) = (eoKeepCaretX in SynEdit.Options));
end;
end;
var
s: string;
begin
if ExpCaretY < 0 then ExpCaretY := ALine;
EditorCommandToIdent(ACommand, s{%H-});
AName := Format('%s (%s Y=%d, X=%d) ', [AName, s, ALine, AStartPhysX]);
{%region NO eoKeepCaretX}
SynEdit.Options := SynEdit.Options - [eoKeepCaretX];
Name2 := AName + 'NO eoKeepCaretX: ';
TestLogFirst := False;
TestCmd;
TestCmdReverse;
TestCmd;
TestCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
DoCmd;
TestCmdReverse;
DoCmd;
DoCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
TestLogFirst := True;
TestCmd;
TestCmdReverse;
TestCmd;
TestCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
TestCmd;
TestKeepXOnEmpty(False);
TestCmd;
TestKeepXOnEmpty(True);
TestCmd;
TestKeepXOnDWidth(False);
TestCmd;
TestKeepXOnDWidth(True);
{%endregion NO eoKeepCaretX}
{%region WITH eoKeepCaretX}
SynEdit.Options := SynEdit.Options + [eoKeepCaretX];
Name2 := Name2 + 'WITH eoKeepCaretX: ';
TestLogFirst := False;
TestCmd;
TestCmdReverse;
TestCmd;
TestCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
DoCmd;
TestCmdReverse;
DoCmd;
DoCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
TestLogFirst := True;
TestCmd;
TestCmdReverse;
TestCmd;
TestCmdRepeat;
TestCmdReverse(True);
TestCmdReverse;
TestCmd;
TestKeepXOnEmpty(False);
if ASelectXEnd < 0 then
TestCmdReverse;
TestCmd;
TestKeepXOnEmpty(True);
if ASelectXEnd < 0 then
TestCmdReverse;
TestCmd;
TestKeepXOnEmpty(False);
TestCmdRepeat;
TestCmd;
TestKeepXOnDWidth(False);
if ASelectXEnd < 0 then
TestCmdReverse;
TestCmd;
TestKeepXOnDWidth(True);
if ASelectXEnd < 0 then
TestCmdReverse;
TestCmd;
TestKeepXOnDWidth(False);
TestCmdRepeat;
{%endregion WITH eoKeepCaretX}
end;
begin
// TODO:
// EOL/BOL at first/last (visible) line (with folding)
// Multybyte char at EOL
SetTextLeftRight;
{%region ecRight}
PushBaseName('No opts');
SynEdit.TabWidth := 6;
SynEdit.MaxLeftChar := 200;
SynEdit.Options := [];
SynEdit.Options2 := [];
TestLeftRight('Simple right', 5, 2, ecRight, 3, 3, 4, 4);
TestLeftRight('After tab right', 5, 7, ecRight, 8, 6, 9, 7);
TestLeftRight('Before tab right', 5, 4, ecRight, 5, 4, 6, 4);
TestLeftRight('Mid tab right', 5, 5, ecRight, 6, 4, 7, 5);
TestLeftRight('tab to tab right', 4, 6, ecRight, 7, 2, 8, 2);
TestLeftRight('Umlaut right', 6, 9, ecRight, 10,11, 11,13);
TestLeftRight('Double W right', 8, 5, ecRight, 7, 8, 8, 9);
TestLeftRight('combining right', 10, 2, ecRight, 3, 5, 4, 6);
TestLeftRight('at EOL right', 5, 10, ecRight, 1, 1, 2, 2, True, True, -1 , 6);
PopPushBaseName('eoScrollPastEol');
SynEdit.Options := [eoScrollPastEol];
TestLeftRight('at EOL right', 5, 10, ecRight, 11, 9, 12,10);
TestLeftRight('at Max-left right', 5,199, ecRight, 200,198, 200,198, False, False);
PopPushBaseName('eoCaretSkipTab');
SynEdit.Options := [];
SynEdit.Options2 := [eoCaretSkipTab];
TestLeftRight('Simple right', 5, 2, ecRight, 3, 3, 4, 4);
TestLeftRight('After tab right', 5, 7, ecRight, 8, 6, 9, 7);
TestLeftRight('Before tab right', 5, 4, ecRight, 7, 5, 8, 6);
TestLeftRight('tab to tab right', 4, 7, ecRight, 13, 3, 19, 4);
PopPushBaseName('eoCaretSkipsSelection');
SynEdit.Options2 := [eoCaretSkipsSelection];
TestLeftRight('Selected right', 5, 2, ecRight, 8, 6, -1, -1, True, False, 8);
{%region ecRight}
{%region ecLeft}
SynEdit.Options := [];
SynEdit.Options2 := [];
TestLeftRight('Simple left', 5, 3, ecLeft, 2, 2, 1, 1);
TestLeftRight('After tab left', 5, 7, ecLeft, 6, 4, 5, 4);
TestLeftRight('Before tab left', 5, 4, ecLeft, 3, 3, 2, 2);
TestLeftRight('Mid tab left', 5, 5, ecLeft, 4, 4, 3, 3);
TestLeftRight('tab to tab left', 4, 8, ecLeft, 7, 2, 6, 1);
TestLeftRight('Umlaut left', 6, 10, ecLeft, 9, 9, 8, 8);
TestLeftRight('Double W left', 8, 7, ecLeft, 5, 5, 4, 4);
TestLeftRight('combining left', 10, 3, ecLeft, 2, 2, 1, 1);
TestLeftRight('at BOL left', 6, 1, ecLeft, 10, 8, 9, 7, True, True, -1 , 5);
PopPushBaseName('eoScrollPastEol');
SynEdit.Options := [eoScrollPastEol];
TestLeftRight('at BOL left', 6, 1, ecLeft, 1, 1, 1, 1, False, False);
PopPushBaseName('eoCaretSkipTab');
SynEdit.Options := [];
SynEdit.Options2 := [eoCaretSkipTab];
TestLeftRight('Simple left', 5, 3, ecLeft, 2, 2, 1, 1);
TestLeftRight('After tab left', 5, 7, ecLeft, 4, 4, 3, 3);
TestLeftRight('tab to tab left', 4, 13, ecLeft, 7, 2, 1, 1);
PopPushBaseName('eoCaretSkipsSelection');
SynEdit.Options2 := [eoCaretSkipsSelection];
TestLeftRight('Selected left', 5, 8, ecLeft, 3, 3, -1, -1, True, False, 3);
{%endregion ecLeft}
PopBaseName;
end;
procedure TTestSynNavigation.TestCaretMoveLeftRightWord;
procedure DoInit;
begin
ReCreateEdit;
SynEdit.TabWidth := 7;
// 1 6 11 14
SetLines(['Some text to test', //1
// 1 5 9
'Foo bar abc', // 2
// 8 14 19 24
#9'Other line with tab', // 3
// 1 8 11 15
'tab'#9'in the middle', // 4
// 1 9 12 16 23 28
'tab'#9' in the middle with space', // 5
// 1 9 13 16
'umlaute äää in text', // 6
'normal line',
// 4 14 21 28 32
' untrimmed spaces around line ', // 8
'normal line',
// 8 15 22 26
#9'tab'#9'only'#9'line'#9, // 10
// 1 8
'normal line',
'', // 12 (empty)
'normal line',
' ', // space only empty line // 14
'normal line',
'',
'A B', // 17
'normal line', // 18
''
]);
end;
procedure TestWordLeft(Name:String; X, Y, ExpX1, ExpY1: Integer;
ExpX2: Integer = -1; ExpY2: Integer = -1);
begin
SetCaretPhys(X,Y);
SynEdit.CommandProcessor(ecWordLeft, '', nil);
TestIsCaretPhys(Name + '(1st WordLeft)', ExpX1, ExpY1);
if ExpY2 > 0 then begin
SynEdit.CommandProcessor(ecWordLeft, '', nil);
TestIsCaretPhys(Name + '(2nd WordLeft)', ExpX2, ExpY2);
end;
end;
procedure TestWordRight(Name:String; X, Y, ExpX1, ExpY1: Integer;
ExpX2: Integer = -1; ExpY2: Integer = -1);
begin
SetCaretPhys(X,Y);
SynEdit.CommandProcessor(ecWordRight, '', nil);
TestIsCaretPhys(Name + '(1st WordRight)', ExpX1, ExpY1);
if ExpY2 > 0 then begin
SynEdit.CommandProcessor(ecWordRight, '', nil);
TestIsCaretPhys(Name + '(2nd WordRight)', ExpX2, ExpY2);
end;
end;
begin
DoInit;
{%region word left}
TestWordLeft('simple "te|st"', 16, 1, 14, 1, 11, 1);
TestWordLeft('simple EOW "test|"', 18, 1, 14, 1, 11, 1);
TestWordLeft('simple BOW "|test"', 14, 1, 11, 1, 6, 1);
TestWordLeft('simple > BOT "So|me"', 3, 1, 1, 1, 1, 1);
TestWordLeft('simple > prev-line "F|oo"', 2, 2, 1, 2, 18, 1);
TestWordLeft('simple > prev-line "|Foo"', 1, 2, 18, 1, 14, 1);
TestWordLeft('tab "wi|th"', 21, 3, 19, 3, 14, 3);
TestWordLeft('tab EOW "with|"', 23, 3, 19, 3, 14, 3);
TestWordLeft('tab BOW "|with"', 19, 3, 14, 3, 8, 3);
TestWordLeft('tab > prev-line "O|ther"', 9, 3, 8, 3, 12, 2);
TestWordLeft('M-tab "i|n"', 9, 4, 8, 4, 1, 4);
TestWordLeft('M-tab > prev-line-tab "ta|b"', 3, 4, 1, 4, 27, 3);
TestWordLeft('M-S-tab "i|n"', 10, 5, 9, 5, 1, 5);
TestWordLeft('M-S-EOW tab "in|"', 11, 5, 9, 5, 1, 5);
TestWordLeft('M-S-BOW tab "|in"', 9, 5, 1, 5, 21, 4);
TestWordLeft('M-S-tab "#9| in"', 8, 5, 1, 5);
TestWordLeft('Umlaut "ää|ä"', 11, 6, 9, 6, 1, 6);
TestWordLeft('Umlaut EOW "äää|"', 12, 6, 9, 6, 1, 6);
TestWordLeft('Umlaut BOW "|äää"', 9, 6, 1, 6, 33, 5);
TestWordLeft('Umlaut "i|n"', 14, 6, 13, 6, 9, 6);
TestWordLeft('After Umlaut > prev line', 1, 7, 20, 6, 16, 6);
TestWordLeft('untrimmed "un|trimmed"', 6, 8, 4, 8, 12, 7);
TestWordLeft('After untrimmed > prev', 1, 9, 35, 8, 28, 8);
TestWordLeft('untrimmed tab "t|ab"', 9,10, 8,10, 12, 9);
TestWordLeft('After untrimmed tab > prev', 1,11, 29,10, 22,10);
TestWordLeft('After empty > prev', 1,13, 1,12);
TestWordLeft('After space empty > prev', 1,15, 6,14);
TestWordLeft('single char at eol "A B|"', 4,17, 3,17, 1,17);
{%endregion}
{%region word right}
TestWordRight('simple "te|xt"', 8, 1, 11, 1, 14, 1);
TestWordRight('simple EOW "text|"', 10, 1, 11, 1, 14, 1);
TestWordRight('simple BOW "|text"', 6, 1, 11, 1, 14, 1);
TestWordRight('simple EOT "li|ne"', 10,18, 12,18, 12,18);
TestWordRight('simple > EOL, next line "te|st"', 16, 1, 18, 1, 1, 2);
TestWordRight('tab "li|ne"', 16, 3, 19, 3, 24, 3);
TestWordRight('tab EOW "line|"', 18, 3, 19, 3, 24, 3);
TestWordRight('tab BOW "|line"', 14, 3, 19, 3, 24, 3);
TestWordRight('tab > EOL, next-line', 25, 3, 27, 3, 1, 4);
TestWordRight('M-tab "t|ab"', 2, 4, 8, 4, 11, 4);
TestWordRight('M-tab "tab|"', 4, 4, 8, 4, 11, 4);
TestWordRight('M-tab > EOL, next-line-tab', 17, 4, 21, 4, 1, 5);
TestWordRight('M-S-tab BOW "t|ab"', 2, 5, 9, 5, 12, 5);
TestWordRight('M-S-tab EOW "tab|"', 4, 5, 9, 5, 12, 5);
TestWordRight('M-S-tab BOW "|tab"', 1, 5, 9, 5, 12, 5);
TestWordRight('M-S-tab "tab#9| "', 5, 5, 9, 5, 12, 5);
TestWordRight('Umlaut "ää|ä"', 11, 6, 13, 6, 16, 6);
TestWordRight('Umlaut EOW "äää|"', 12, 6, 13, 6, 16, 6);
TestWordRight('Umlaut BOW "|äää"', 9, 6, 13, 6, 16, 6);
TestWordRight('Umlaut "um|laute"', 2, 6, 9, 6, 13, 6);
TestWordRight('After Umlaut > EOL, next line', 18, 6, 20, 6, 1, 7);
TestWordRight('Before untrimmed > next', 12, 7, 4, 8, 14, 8);
TestWordRight('untrimmed > EOL, next', 30, 8, 35, 8, 1, 9);
TestWordRight('Before untrimmed tab > next', 12, 9, 8,10, 15,10);
TestWordRight('untrimmed tab > EOL, next', 24,10, 29,10, 1,11);
TestWordRight('Before empty > next', 12,11, 1,12);
TestWordRight('Before space empty > next', 12,13, 1,14, 6, 14);
{%endregion}
end;
initialization
RegisterTest(TTestSynNavigation);
end.
|