robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local command =n . command 8local eq =t . eq 9local eval =n . eval 10local feed =n . feed 11local fn =n . fn 12local poke_eventloop =n . poke_eventloop 13local exec =n . exec 14 15describe ( 'search cmdline' , function () 16local screen 17 18before_each ( function () 19clear () 20command ( 'set nohlsearch inccommand=' ) 21screen =Screen . new ( 20 , 3 ) 22end ) 23 24local function tenlines () 25fn . setline ( 1 , { 26' 1' , 27' 2 these' , 28' 3 the' , 29' 4 their' , 30' 5 there' , 31' 6 their' , 32' 7 the' , 33' 8 them' , 34' 9 these' , 35' 10 foobar' , 36} ) 37command ( '1' ) 38end 39 40it ( 'history can be navigated with <C-N>/<C-P>' , function () 41tenlines () 42command ( 'set noincsearch' ) 43feed ( '/foobar<CR>' ) 44feed ( '/the<CR>' ) 45eq ( 'the' , eval ( '@/' )) 46feed ( '/thes<C-P><C-P><CR>' ) 47eq ( 'foobar' , eval ( '@/' )) 48end ) 49 50describe ( 'can traverse matches' , function () 51before_each ( tenlines ) 52local function forwarditer ( wrapscan ) 53command ( 'set incsearch ' .. wrapscan ) 54feed ( '/the' ) 55screen : expect ( [[ 561 | 572 {2:the}se | 58/the^ | 59]] ) 60feed ( '<C-G>' ) 61screen : expect ( [[ 622 these | 633 {2:the} | 64/the^ | 65]] ) 66eq ( { 0 , 0 , 0 , 0 } , fn . getpos ( '"' )) 67feed ( '<C-G>' ) 68screen : expect ( [[ 693 the | 704 {2:the}ir | 71/the^ | 72]] ) 73feed ( '<C-G>' ) 74screen : expect ( [[ 754 their | 765 {2:the}re | 77/the^ | 78]] ) 79feed ( '<C-G>' ) 80screen : expect ( [[ 815 there | 826 {2:the}ir | 83/the^ | 84]] ) 85feed ( '<C-G>' ) 86screen : expect ( [[ 876 their | 887 {2:the} | 89/the^ | 90]] ) 91feed ( '<C-G>' ) 92screen : expect ( [[ 937 the | 948 {2:the}m | 95/the^ | 96]] ) 97feed ( '<C-G>' ) 98screen : expect ( [[ 998 them | 1009 {2:the}se | 101/the^ | 102]] ) 103screen . bell =false 104feed ( '<C-G>' ) 105if wrapscan == 'wrapscan' then 106screen : expect ( [[ 1072 {2:the}se | 1083 the | 109/the^ | 110]] ) 111else 112screen : expect { 113grid =[[ 1148 them | 1159 {2:the}se | 116/the^ | 117]] , 118condition =function () 119eq ( true , screen . bell ) 120end , 121} 122feed ( '<CR>' ) 123eq ( { 0 , 0 , 0 , 0 } , fn . getpos ( '"' )) 124end 125end 126 127local function backiter ( wrapscan ) 128command ( 'set incsearch ' .. wrapscan ) 129command ( '$' ) 130 131feed ( '?the' ) 132screen : expect ( [[ 1339 {2:the}se | 13410 foobar | 135?the^ | 136]] ) 137screen . bell =false 138if wrapscan == 'wrapscan' then 139feed ( '<C-G>' ) 140screen : expect ( [[ 1412 {2:the}se | 1423 the | 143?the^ | 144]] ) 145feed ( '<CR>' ) 146screen : expect ( [[ 1472 ^these | 1483 the | 149?the | 150]] ) 151else 152feed ( '<C-G>' ) 153screen : expect { 154grid =[[ 1559 {2:the}se | 15610 foobar | 157?the^ | 158]] , 159condition =function () 160eq ( true , screen . bell ) 161end , 162} 163feed ( '<CR>' ) 164screen : expect ( [[ 1659 ^these | 16610 foobar | 167?the | 168]] ) 169end 170command ( '$' ) 171feed ( '?the' ) 172screen : expect ( [[ 1739 {2:the}se | 17410 foobar | 175?the^ | 176]] ) 177feed ( '<C-T>' ) 178screen : expect ( [[ 1798 {2:the}m | 1809 these | 181?the^ | 182]] ) 183for i =1 , 6 do 184feed ( '<C-T>' ) 185-- Avoid sleep just before expect, otherwise expect will take the full 186-- timeout 187if i ~= 6 then 188screen : sleep ( 1 ) 189end 190end 191screen : expect ( [[ 1922 {2:the}se | 1933 the | 194?the^ | 195]] ) 196screen . bell =false 197feed ( '<C-T>' ) 198if wrapscan == 'wrapscan' then 199screen : expect ( [[ 2009 {2:the}se | 20110 foobar | 202?the^ | 203]] ) 204else 205screen : expect { 206grid =[[ 2072 {2:the}se | 2083 the | 209?the^ | 210]] , 211condition =function () 212eq ( true , screen . bell ) 213end , 214} 215end 216end 217 218it ( "using <C-G> and 'nowrapscan'" , function () 219forwarditer ( 'nowrapscan' ) 220end ) 221 222it ( "using <C-G> and 'wrapscan'" , function () 223forwarditer ( 'wrapscan' ) 224end ) 225 226it ( "using <C-T> and 'nowrapscan'" , function () 227backiter ( 'nowrapscan' ) 228end ) 229 230it ( "using <C-T> and 'wrapscan'" , function () 231backiter ( 'wrapscan' ) 232end ) 233end ) 234 235it ( 'expands pattern with <C-L>' , function () 236tenlines () 237command ( 'set incsearch wrapscan' ) 238 239feed ( '/the' ) 240screen : expect ( [[ 2411 | 2422 {2:the}se | 243/the^ | 244]] ) 245feed ( '<C-L>' ) 246screen : expect ( [[ 2471 | 2482 {2:thes}e | 249/thes^ | 250]] ) 251feed ( '<C-G>' ) 252screen : expect ( [[ 2539 {2:thes}e | 25410 foobar | 255/thes^ | 256]] ) 257feed ( '<C-G>' ) 258screen : expect ( [[ 2592 {2:thes}e | 2603 the | 261/thes^ | 262]] ) 263feed ( '<CR>' ) 264screen : expect ( [[ 2652 ^these | 2663 the | 267/thes | 268]] ) 269 270command ( '1' ) 271command ( 'set nowrapscan' ) 272feed ( '/the' ) 273screen : expect ( [[ 2741 | 2752 {2:the}se | 276/the^ | 277]] ) 278feed ( '<C-L>' ) 279screen : expect ( [[ 2801 | 2812 {2:thes}e | 282/thes^ | 283]] ) 284feed ( '<C-G>' ) 285screen : expect ( [[ 2869 {2:thes}e | 28710 foobar | 288/thes^ | 289]] ) 290feed ( '<C-G><CR>' ) 291screen : expect ( [[ 2929 ^these | 29310 foobar | 294/thes | 295]] ) 296end ) 297 298it ( 'reduces pattern with <BS> and keeps cursor position' , function () 299tenlines () 300command ( 'set incsearch wrapscan' ) 301 302-- First match 303feed ( '/thei' ) 304screen : expect ( [[ 3053 the | 3064 {2:thei}r | 307/thei^ | 308]] ) 309-- Match from initial cursor position when modifying search 310feed ( '<BS>' ) 311screen : expect ( [[ 3121 | 3132 {2:the}se | 314/the^ | 315]] ) 316-- New text advances to next match 317feed ( 's' ) 318screen : expect ( [[ 3191 | 3202 {2:thes}e | 321/thes^ | 322]] ) 323-- Stay on this match when deleting a character 324feed ( '<BS>' ) 325screen : expect ( [[ 3261 | 3272 {2:the}se | 328/the^ | 329]] ) 330-- Advance to previous match 331feed ( '<C-T>' ) 332screen : expect ( [[ 3339 {2:the}se | 33410 foobar | 335/the^ | 336]] ) 337-- Extend search to include next character 338feed ( '<C-L>' ) 339screen : expect ( [[ 3409 {2:thes}e | 34110 foobar | 342/thes^ | 343]] ) 344-- Deleting all characters resets the cursor position 345feed ( '<BS><BS><BS><BS>' ) 346screen : expect ( [[ 3471 | 3482 these | 349/^ | 350]] ) 351feed ( 'the' ) 352screen : expect ( [[ 3531 | 3542 {2:the}se | 355/the^ | 356]] ) 357feed ( '\\>' ) 358screen : expect ( [[ 3592 these | 3603 {2:the} | 361/the\>^ | 362]] ) 363end ) 364 365it ( 'can traverse matches in the same line with <C-G>/<C-T>' , function () 366fn . setline ( 1 , { ' 1' , ' 2 these' , ' 3 the theother' } ) 367command ( '1' ) 368command ( 'set incsearch' ) 369 370-- First match 371feed ( '/the' ) 372screen : expect ( [[ 3731 | 3742 {2:the}se | 375/the^ | 376]] ) 377 378-- Next match, different line 379feed ( '<C-G>' ) 380screen : expect ( [[ 3812 these | 3823 {2:the} theother | 383/the^ | 384]] ) 385 386-- Next match, same line 387feed ( '<C-G>' ) 388screen : expect ( [[ 3892 these | 3903 the {2:the}other | 391/the^ | 392]] ) 393feed ( '<C-G>' ) 394screen : expect ( [[ 3952 these | 3963 the theo{2:the}r | 397/the^ | 398]] ) 399 400-- Previous match, same line 401feed ( '<C-T>' ) 402screen : expect ( [[ 4032 these | 4043 the {2:the}other | 405/the^ | 406]] ) 407feed ( '<C-T>' ) 408screen : expect ( [[ 4092 these | 4103 {2:the} theother | 411/the^ | 412]] ) 413 414-- Previous match, different line 415feed ( '<C-T>' ) 416screen : expect ( [[ 4172 {2:the}se | 4183 the theother | 419/the^ | 420]] ) 421end ) 422 423it ( 'keeps the view after deleting a char from the search' , function () 424screen : try_resize ( 20 , 6 ) 425tenlines () 426 427feed ( '/foo' ) 428screen : expect ( [[ 4296 their | 4307 the | 4318 them | 4329 these | 43310 {2:foo}bar | 434/foo^ | 435]] ) 436feed ( '<BS>' ) 437screen : expect ( [[ 4386 their | 4397 the | 4408 them | 4419 these | 44210 {2:fo}obar | 443/fo^ | 444]] ) 445feed ( '<CR>' ) 446screen : expect ( [[ 4476 their | 4487 the | 4498 them | 4509 these | 45110 ^foobar | 452/fo | 453]] ) 454eq ( { 455lnum =10 , 456leftcol =0 , 457col =4 , 458topfill =0 , 459topline =6 , 460coladd =0 , 461skipcol =0 , 462curswant =4 , 463} , fn . winsaveview ()) 464end ) 465 466it ( 'restores original view after failed search' , function () 467screen : try_resize ( 40 , 3 ) 468tenlines () 469feed ( '0' ) 470feed ( '/foo' ) 471screen : expect ( [[ 4729 these | 47310 {2:foo}bar | 474/foo^ | 475]] ) 476feed ( '<C-W>' ) 477screen : expect ( [[ 4781 | 4792 these | 480/^ | 481]] ) 482feed ( '<CR>' ) 483screen : expect ( [[ 484/ | 485{9:E35: No previous regular expression} | 486{6:Press ENTER or type command to continue}^ | 487]] ) 488feed ( '<CR>' ) 489eq ( { 490lnum =1 , 491leftcol =0 , 492col =0 , 493topfill =0 , 494topline =1 , 495coladd =0 , 496skipcol =0 , 497curswant =0 , 498} , fn . winsaveview ()) 499end ) 500 501-- oldtest: Test_search_cmdline4(). 502it ( "CTRL-G with 'incsearch' and ? goes in the right direction" , function () 503screen : try_resize ( 40 , 4 ) 504command ( 'enew!' ) 505fn . setline ( 1 , { ' 1 the first' , ' 2 the second' , ' 3 the third' } ) 506command ( 'set laststatus=0 shortmess+=s' ) 507command ( 'set incsearch' ) 508command ( '$' ) 509-- Send the input in chunks, so the cmdline logic regards it as 510-- "interactive". This mimics Vim's test_override("char_avail"). 511-- (See legacy test: test_search.vim) 512feed ( '?the' ) 513poke_eventloop () 514feed ( '<c-g>' ) 515poke_eventloop () 516feed ( '<cr>' ) 517screen : expect ( [[ 5181 the first | 5192 the second | 5203 ^the third | 521?the | 522]] ) 523 524command ( '$' ) 525feed ( '?the' ) 526poke_eventloop () 527feed ( '<c-g>' ) 528poke_eventloop () 529feed ( '<c-g>' ) 530poke_eventloop () 531feed ( '<cr>' ) 532screen : expect ( [[ 5331 ^the first | 5342 the second | 5353 the third | 536?the | 537]] ) 538 539command ( '$' ) 540feed ( '?the' ) 541poke_eventloop () 542feed ( '<c-g>' ) 543poke_eventloop () 544feed ( '<c-g>' ) 545poke_eventloop () 546feed ( '<c-g>' ) 547poke_eventloop () 548feed ( '<cr>' ) 549screen : expect ( [[ 5501 the first | 5512 ^the second | 5523 the third | 553?the | 554]] ) 555 556command ( '$' ) 557feed ( '?the' ) 558poke_eventloop () 559feed ( '<c-t>' ) 560poke_eventloop () 561feed ( '<cr>' ) 562screen : expect ( [[ 5631 ^the first | 5642 the second | 5653 the third | 566?the | 567]] ) 568 569command ( '$' ) 570feed ( '?the' ) 571poke_eventloop () 572feed ( '<c-t>' ) 573poke_eventloop () 574feed ( '<c-t>' ) 575poke_eventloop () 576feed ( '<cr>' ) 577screen : expect ( [[ 5781 the first | 5792 the second | 5803 ^the third | 581?the | 582]] ) 583 584command ( '$' ) 585feed ( '?the' ) 586poke_eventloop () 587feed ( '<c-t>' ) 588poke_eventloop () 589feed ( '<c-t>' ) 590poke_eventloop () 591feed ( '<c-t>' ) 592poke_eventloop () 593feed ( '<cr>' ) 594screen : expect ( [[ 5951 the first | 5962 ^the second | 5973 the third | 598?the | 599]] ) 600end ) 601 602-- oldtest: Test_incsearch_sort_dump(). 603it ( 'incsearch works with :sort' , function () 604screen : try_resize ( 20 , 4 ) 605command ( 'set incsearch hlsearch scrolloff=0' ) 606fn . setline ( 1 , { 'another one 2' , 'that one 3' , 'the one 1' } ) 607 608feed ( ':sort ni u /on' ) 609screen : expect ( [[ 610another {2:on}e 2 | 611that {10:on}e 3 | 612the {10:on}e 1 | 613:sort ni u /on^ | 614]] ) 615feed ( '<Esc>' ) 616 617feed ( ':sort! /on' ) 618screen : expect ( [[ 619another {2:on}e 2 | 620that {10:on}e 3 | 621the {10:on}e 1 | 622:sort! /on^ | 623]] ) 624feed ( '<Esc>' ) 625end ) 626 627-- oldtest: Test_incsearch_uniq_dump(). 628it ( 'incsearch works with :uniq' , function () 629screen : try_resize ( 20 , 4 ) 630command ( 'set incsearch hlsearch scrolloff=0' ) 631fn . setline ( 1 , { 'another one 2' , 'that one 3' , 'the one 1' } ) 632 633feed ( ':uniq /on' ) 634screen : expect ( [[ 635another {2:on}e 2 | 636that {10:on}e 3 | 637the {10:on}e 1 | 638:uniq /on^ | 639]] ) 640feed ( '<Esc>' ) 641 642feed ( ':uniq! /on' ) 643screen : expect ( [[ 644another {2:on}e 2 | 645that {10:on}e 3 | 646the {10:on}e 1 | 647:uniq! /on^ | 648]] ) 649feed ( '<Esc>' ) 650end ) 651 652-- oldtest: Test_incsearch_vimgrep_dump(). 653it ( 'incsearch works with :vimgrep family' , function () 654screen : try_resize ( 30 , 4 ) 655command ( 'set incsearch hlsearch scrolloff=0' ) 656fn . setline ( 1 , { 'another one 2' , 'that one 3' , 'the one 1' } ) 657 658feed ( ':vimgrep on' ) 659screen : expect ( [[ 660another {2:on}e 2 | 661that {10:on}e 3 | 662the {10:on}e 1 | 663:vimgrep on^ | 664]] ) 665feed ( '<esc>' ) 666 667feed ( ':vimg /on/ *.txt' ) 668screen : expect ( [[ 669another {2:on}e 2 | 670that {10:on}e 3 | 671the {10:on}e 1 | 672:vimg /on/ *.txt^ | 673]] ) 674feed ( '<esc>' ) 675 676feed ( ':vimgrepadd "\\<LT>on' ) 677screen : expect ( [[ 678another {2:on}e 2 | 679that {10:on}e 3 | 680the {10:on}e 1 | 681:vimgrepadd "\<on^ | 682]] ) 683feed ( '<esc>' ) 684 685feed ( ':lv "tha' ) 686screen : expect ( [[ 687another one 2 | 688{2:tha}t one 3 | 689the one 1 | 690:lv "tha^ | 691]] ) 692feed ( '<esc>' ) 693 694feed ( ':lvimgrepa "the" **/*.txt' ) 695screen : expect ( [[ 696ano{2:the}r one 2 | 697that one 3 | 698{10:the} one 1 | 699:lvimgrepa "the" **/*.txt^ | 700]] ) 701feed ( '<esc>' ) 702end ) 703 704-- oldtest: Test_incsearch_substitute_dump2() 705it ( 'incsearch detects empty pattern properly vim-patch:8.2.2295' , function () 706screen : try_resize ( 70 , 6 ) 707exec ( [[ 708set incsearch hlsearch scrolloff=0 709for n in range(1, 4) 710call setline(n, "foo " . n) 711endfor 712call setline(5, "abc|def") 7133 714]] ) 715 716feed ( [[:%s/\vabc|]] ) 717screen : expect ( [[ 718foo 1 | 719foo 2 | 720foo 3 | 721foo 4 | 722abc|def | 723:%s/\vabc|^ | 724]] ) 725feed ( '<Esc>' ) 726 727-- The following should not be highlighted 728feed ( [[:1,5s/\v|]] ) 729screen : expect ( [[ 730foo 1 | 731foo 2 | 732foo 3 | 733foo 4 | 734abc|def | 735:1,5s/\v|^ | 736]] ) 737end ) 738 739-- oldtest: Test_incsearch_restore_view() 740it ( 'incsearch restores viewport' , function () 741screen : try_resize ( 20 , 6 ) 742exec ( [[ 743set incsearch nohlsearch 744setlocal scrolloff=0 smoothscroll 745call setline(1, [join(range(25), ' '), '', '', '', '', 'xxx']) 746call feedkeys("2\<C-E>", 't') 747]] ) 748local s =[[ 749{1:<<<} 18 19 20 21 22 2| 750^3 24 | 751|*4 752]] 753screen : expect ( s ) 754feed ( '/xx' ) 755screen : expect ( [[ 756|*4 757{2:xx}x | 758/xx^ | 759]] ) 760feed ( 'x' ) 761screen : expect ( [[ 762|*4 763{2:xxx} | 764/xxx^ | 765]] ) 766feed ( '<Esc>' ) 767screen : expect ( s ) 768end ) 769 770-- oldtest: Test_incsearch_delimiter_ctrlg() 771it ( 'incsearch does not include trailing delimiter' , function () 772screen : try_resize ( 20 , 6 ) 773exec ( [[ 774set incsearch hls 775call setline(1, ["1 vim inc", "2 vim /", "3 vim /", "4 vim ?", "5 vim ?"]) 776normal gg 777redraw 778]] ) 779 780feed ( '/' ) 781poke_eventloop () 782feed ( 'v' ) 783poke_eventloop () 784feed ( 'i' ) 785poke_eventloop () 786feed ( 'm' ) 787poke_eventloop () 788feed ( ' ' ) 789poke_eventloop () 790feed ( '/' ) 791poke_eventloop () 792feed ( '<C-G>' ) 793screen : expect ( [[ 7941 {10:vim }inc | 7952 {2:vim }/ | 7963 {10:vim }/ | 7974 {10:vim }? | 7985 {10:vim }? | 799/vim /^ | 800]] ) 801feed ( '<Esc>' ) 802 803command ( '5' ) 804feed ( '?' ) 805poke_eventloop () 806feed ( 'v' ) 807poke_eventloop () 808feed ( 'i' ) 809poke_eventloop () 810feed ( 'm' ) 811poke_eventloop () 812feed ( ' ' ) 813poke_eventloop () 814feed ( '?' ) 815poke_eventloop () 816feed ( '<C-T>' ) 817screen : expect ( [[ 8181 {10:vim }inc | 8192 {10:vim }/ | 8203 {2:vim }/ | 8214 {10:vim }? | 8225 {10:vim }? | 823?vim ?^ | 824]] ) 825feed ( '<Esc>' ) 826 827feed ( '/' ) 828poke_eventloop () 829feed ( 'v' ) 830poke_eventloop () 831feed ( 'i' ) 832poke_eventloop () 833feed ( 'm' ) 834poke_eventloop () 835feed ( ' ' ) 836poke_eventloop () 837feed ( '\\/' ) 838poke_eventloop () 839feed ( '<C-G>' ) 840screen : expect ( [[ 8411 vim inc | 8422 {10:vim /} | 8433 {2:vim /} | 8444 vim ? | 8455 vim ? | 846/vim \/^ | 847]] ) 848feed ( '<Esc>' ) 849 850command ( '5' ) 851feed ( '?' ) 852poke_eventloop () 853feed ( 'v' ) 854poke_eventloop () 855feed ( 'i' ) 856poke_eventloop () 857feed ( 'm' ) 858poke_eventloop () 859feed ( ' ' ) 860poke_eventloop () 861feed ( '\\?' ) 862poke_eventloop () 863feed ( '<C-T>' ) 864screen : expect ( [[ 8651 vim inc | 8662 vim / | 8673 vim / | 8684 {10:vim ?} | 8695 {2:vim ?} | 870?vim \?^ | 871]] ) 872feed ( '<Esc>' ) 873end ) 874end ) 875 876describe ( 'Search highlight' , function () 877before_each ( clear ) 878 879-- oldtest: Test_hlsearch_dump() 880it ( 'beyond line end vim-patch:8.2.2542' , function () 881local screen =Screen . new ( 50 , 6 ) 882exec ( [[ 883set hlsearch noincsearch cursorline 884call setline(1, ["xxx", "xxx", "xxx"]) 885/.* 8862 887]] ) 888feed ( [[/\_.*<CR>]] ) 889screen : expect ( [[ 890{10:xxx } |*2 891{10:^xxx }{21: }| 892{1:~ }|*2 893/\_.* | 894]] ) 895end ) 896 897-- oldtest: Test_hlsearch_and_visual() 898it ( 'is combined with Visual highlight vim-patch:8.2.2797' , function () 899local screen =Screen . new ( 40 , 6 ) 900screen : add_extra_attr_ids { 901[ 100 ] ={ 902foreground =Screen . colors . Black , 903bold =true , 904background =Screen . colors . LightGrey , 905} , 906[ 101 ] ={ bold =true , background =Screen . colors . Yellow } , 907} 908exec ( [[ 909set hlsearch noincsearch 910call setline(1, repeat(["xxx yyy zzz"], 3)) 911hi Search gui=bold 912/yyy 913call cursor(1, 6) 914]] ) 915feed ( 'vjj' ) 916screen : expect ( [[ 917xxx {101:y}{100:yy}{17: zzz} | 918{17:xxx }{100:yyy}{17: zzz} | 919{17:xxx }{100:y^y}{101:y} zzz | 920{1:~ }|*2 921{5:-- VISUAL --} | 922]] ) 923end ) 924end )