|
1 | 1 | " Test for the search command |
2 | 2 |
|
| 3 | +source shared.vim |
| 4 | + |
3 | 5 | func Test_search_cmdline() |
4 | 6 | if !exists('+incsearch') |
5 | 7 | return |
@@ -431,3 +433,118 @@ func Test_search_regexp() |
431 | 433 | set undolevels& |
432 | 434 | enew! |
433 | 435 | endfunc |
| 436 | + |
| 437 | +func Test_search_cmdline_incsearch_highlight() |
| 438 | + if !exists('+incsearch') |
| 439 | + return |
| 440 | + endif |
| 441 | + set incsearch hlsearch |
| 442 | + " need to disable char_avail, |
| 443 | + " so that expansion of commandline works |
| 444 | + call test_override("char_avail", 1) |
| 445 | + new |
| 446 | + call setline(1, ['aaa 1 the first', ' 2 the second', ' 3 the third']) |
| 447 | + |
| 448 | + 1 |
| 449 | + call feedkeys("/second\<cr>", 'tx') |
| 450 | + call assert_equal('second', @/) |
| 451 | + call assert_equal(' 2 the second', getline('.')) |
| 452 | + |
| 453 | + " Canceling search won't change @/ |
| 454 | + 1 |
| 455 | + let @/ = 'last pattern' |
| 456 | + call feedkeys("/third\<C-c>", 'tx') |
| 457 | + call assert_equal('last pattern', @/) |
| 458 | + call feedkeys("/third\<Esc>", 'tx') |
| 459 | + call assert_equal('last pattern', @/) |
| 460 | + call feedkeys("/3\<bs>\<bs>", 'tx') |
| 461 | + call assert_equal('last pattern', @/) |
| 462 | + call feedkeys("/third\<c-g>\<c-t>\<Esc>", 'tx') |
| 463 | + call assert_equal('last pattern', @/) |
| 464 | + |
| 465 | + " clean up |
| 466 | + set noincsearch nohlsearch |
| 467 | + bw! |
| 468 | +endfunc |
| 469 | + |
| 470 | +func Test_search_cmdline_incsearch_highlight_attr() |
| 471 | + if !exists('+incsearch') || !has('terminal') || has('gui_running') |
| 472 | + return |
| 473 | + endif |
| 474 | + let h = winheight(0) |
| 475 | + if h < 3 |
| 476 | + return |
| 477 | + endif |
| 478 | + let g:buf = term_start([GetVimProg(), '--clean', '-c', 'set noswapfile'], {'term_rows': 3}) |
| 479 | + |
| 480 | + " Prepare buffer text |
| 481 | + let lines = ['abb vim vim vi', 'vimvivim'] |
| 482 | + call term_sendkeys(g:buf, 'i' . join(lines, "\n") . "\<esc>gg0") |
| 483 | + call term_wait(g:buf, 200) |
| 484 | + call assert_equal(lines[0], term_getline(g:buf, 1)) |
| 485 | + |
| 486 | + " Get attr of normal(a0), incsearch(a1), hlsearch(a2) highlight |
| 487 | + call term_sendkeys(g:buf, ":set incsearch hlsearch\<cr>") |
| 488 | + call term_sendkeys(g:buf, '/b') |
| 489 | + call term_wait(g:buf, 200) |
| 490 | + let screen_line1 = term_scrape(g:buf, 1) |
| 491 | + call assert_true(len(screen_line1) > 2) |
| 492 | + " a0: attr_normal |
| 493 | + let a0 = screen_line1[0].attr |
| 494 | + " a1: attr_incsearch |
| 495 | + let a1 = screen_line1[1].attr |
| 496 | + " a2: attr_hlsearch |
| 497 | + let a2 = screen_line1[2].attr |
| 498 | + call assert_notequal(a0, a1) |
| 499 | + call assert_notequal(a0, a2) |
| 500 | + call assert_notequal(a1, a2) |
| 501 | + call term_sendkeys(g:buf, "\<cr>gg0") |
| 502 | + |
| 503 | + " Test incremental highlight search |
| 504 | + call term_sendkeys(g:buf, "/vim") |
| 505 | + call term_wait(g:buf, 200) |
| 506 | + " Buffer: |
| 507 | + " abb vim vim vi |
| 508 | + " vimvivim |
| 509 | + " Search: /vim |
| 510 | + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a2,a2,a2,a0,a0,a0] |
| 511 | + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
| 512 | + call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 513 | + call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
| 514 | + |
| 515 | + " Test <C-g> |
| 516 | + call term_sendkeys(g:buf, "\<C-g>\<C-g>") |
| 517 | + call term_wait(g:buf, 200) |
| 518 | + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 519 | + let attr_line2 = [a1,a1,a1,a0,a0,a2,a2,a2] |
| 520 | + call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 521 | + call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
| 522 | + |
| 523 | + " Test <C-t> |
| 524 | + call term_sendkeys(g:buf, "\<C-t>") |
| 525 | + call term_wait(g:buf, 200) |
| 526 | + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a1,a1,a1,a0,a0,a0] |
| 527 | + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
| 528 | + call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 529 | + call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
| 530 | + |
| 531 | + " Type Enter and a1(incsearch highlight) should become a2(hlsearch highlight) |
| 532 | + call term_sendkeys(g:buf, "\<cr>") |
| 533 | + call term_wait(g:buf, 200) |
| 534 | + let attr_line1 = [a0,a0,a0,a0,a2,a2,a2,a0,a2,a2,a2,a0,a0,a0] |
| 535 | + let attr_line2 = [a2,a2,a2,a0,a0,a2,a2,a2] |
| 536 | + call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 537 | + call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
| 538 | + |
| 539 | + " Test nohlsearch. a2(hlsearch highlight) should become a0(normal highlight) |
| 540 | + call term_sendkeys(g:buf, ":1\<cr>") |
| 541 | + call term_sendkeys(g:buf, ":set nohlsearch\<cr>") |
| 542 | + call term_sendkeys(g:buf, "/vim") |
| 543 | + call term_wait(g:buf, 200) |
| 544 | + let attr_line1 = [a0,a0,a0,a0,a1,a1,a1,a0,a0,a0,a0,a0,a0,a0] |
| 545 | + let attr_line2 = [a0,a0,a0,a0,a0,a0,a0,a0] |
| 546 | + call assert_equal(attr_line1, map(term_scrape(g:buf, 1)[:len(attr_line1)-1], 'v:val.attr')) |
| 547 | + call assert_equal(attr_line2, map(term_scrape(g:buf, 2)[:len(attr_line2)-1], 'v:val.attr')) |
| 548 | + |
| 549 | + bwipe! |
| 550 | +endfunc |
0 commit comments