Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 1 | " Test for v:hlsearch |
| 2 | |
Christian Brabandt | eb380b9 | 2025-07-07 20:53:55 +0200 | [diff] [blame] | 3 | source util/screendump.vim |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 4 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 5 | func Test_hlsearch() |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 6 | new |
| 7 | call setline(1, repeat(['aaa'], 10)) |
| 8 | set hlsearch nolazyredraw |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 9 | " redraw is needed to make hlsearch highlight the matches |
| 10 | exe "normal! /aaa\<CR>" | redraw |
| 11 | let r1 = screenattr(1, 1) |
| 12 | nohlsearch | redraw |
| 13 | call assert_notequal(r1, screenattr(1,1)) |
| 14 | let v:hlsearch=1 | redraw |
| 15 | call assert_equal(r1, screenattr(1,1)) |
| 16 | let v:hlsearch=0 | redraw |
| 17 | call assert_notequal(r1, screenattr(1,1)) |
| 18 | set hlsearch | redraw |
| 19 | call assert_equal(r1, screenattr(1,1)) |
| 20 | let v:hlsearch=0 | redraw |
| 21 | call assert_notequal(r1, screenattr(1,1)) |
| 22 | exe "normal! n" | redraw |
| 23 | call assert_equal(r1, screenattr(1,1)) |
| 24 | let v:hlsearch=0 | redraw |
| 25 | call assert_notequal(r1, screenattr(1,1)) |
| 26 | exe "normal! /\<CR>" | redraw |
| 27 | call assert_equal(r1, screenattr(1,1)) |
| 28 | set nohls |
| 29 | exe "normal! /\<CR>" | redraw |
| 30 | call assert_notequal(r1, screenattr(1,1)) |
Bram Moolenaar | e2e4075 | 2020-09-04 21:18:46 +0200 | [diff] [blame] | 31 | call assert_fails('let v:hlsearch=[]', 'E745:') |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 32 | call garbagecollect(1) |
| 33 | call getchar(1) |
| 34 | enew! |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 35 | endfunc |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 36 | |
| 37 | func Test_hlsearch_hangs() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 38 | CheckFunction reltimefloat |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 39 | |
Bram Moolenaar | e530395 | 2022-06-19 17:05:47 +0100 | [diff] [blame] | 40 | " So, it turns out that Windows 7 implements TimerQueue timers differently |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 41 | " and they can expire *before* the requested time has elapsed. So allow for |
| 42 | " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)). |
| 43 | if has("win32") |
| 44 | let min_timeout = 0.08 |
| 45 | else |
| 46 | let min_timeout = 0.1 |
| 47 | endif |
| 48 | |
Bram Moolenaar | 1ef9bbe | 2017-06-17 20:08:20 +0200 | [diff] [blame] | 49 | " This pattern takes a long time to match, it should timeout. |
Bram Moolenaar | 0946326 | 2017-06-17 20:55:06 +0200 | [diff] [blame] | 50 | new |
| 51 | call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 52 | let start = reltime() |
| 53 | set hlsearch nolazyredraw redrawtime=101 |
Bram Moolenaar | 1ef9bbe | 2017-06-17 20:08:20 +0200 | [diff] [blame] | 54 | let @/ = '\%#=1a*.*X\@<=b*' |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 55 | redraw |
| 56 | let elapsed = reltimefloat(reltime(start)) |
zeertzjq | cdc6a43 | 2022-06-19 11:45:46 +0100 | [diff] [blame] | 57 | call assert_inrange(min_timeout, 1.0, elapsed) |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 58 | set nohlsearch redrawtime& |
Bram Moolenaar | 0946326 | 2017-06-17 20:55:06 +0200 | [diff] [blame] | 59 | bwipe! |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 60 | endfunc |
Bram Moolenaar | 7ee3f15 | 2018-09-02 15:07:28 +0200 | [diff] [blame] | 61 | |
| 62 | func Test_hlsearch_eol_highlight() |
| 63 | new |
| 64 | call append(1, repeat([''], 9)) |
| 65 | set hlsearch nolazyredraw |
| 66 | exe "normal! /$\<CR>" | redraw |
| 67 | let attr = screenattr(1, 1) |
| 68 | for row in range(2, 10) |
| 69 | call assert_equal(attr, screenattr(row, 1), 'in line ' . row) |
| 70 | endfor |
| 71 | set nohlsearch |
| 72 | bwipe! |
| 73 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 74 | |
K.Takata | c4b7dec | 2023-02-10 21:38:44 +0000 | [diff] [blame] | 75 | func Test_hlsearch_Ctrl_R() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 76 | CheckScreendump |
K.Takata | c4b7dec | 2023-02-10 21:38:44 +0000 | [diff] [blame] | 77 | CheckRunVimInTerminal |
| 78 | |
| 79 | let lines =<< trim END |
| 80 | set incsearch hlsearch |
| 81 | let @" = "text" |
| 82 | put |
| 83 | END |
| 84 | call writefile(lines, 'XhlsearchCtrlR', 'D') |
| 85 | let buf = RunVimInTerminal('-S XhlsearchCtrlR', #{rows: 6, cols: 60}) |
| 86 | |
| 87 | call term_sendkeys(buf, "/\<C-R>\<C-R>\"") |
| 88 | call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {}) |
| 89 | |
| 90 | call term_sendkeys(buf, "\<Esc>") |
| 91 | call StopVimInTerminal(buf) |
| 92 | endfunc |
| 93 | |
K.Takata | 9cf6ab1 | 2023-05-29 16:08:08 +0100 | [diff] [blame] | 94 | func Test_hlsearch_clipboard() |
Drew Vogel | ea67ba7 | 2025-05-07 22:05:17 +0200 | [diff] [blame] | 95 | CheckScreendump |
K.Takata | 9cf6ab1 | 2023-05-29 16:08:08 +0100 | [diff] [blame] | 96 | CheckRunVimInTerminal |
| 97 | CheckFeature clipboard_working |
| 98 | |
| 99 | let lines =<< trim END |
| 100 | set incsearch hlsearch |
| 101 | let @* = "text" |
| 102 | put * |
| 103 | END |
| 104 | call writefile(lines, 'XhlsearchClipboard', 'D') |
| 105 | let buf = RunVimInTerminal('-S XhlsearchClipboard', #{rows: 6, cols: 60}) |
| 106 | |
| 107 | call term_sendkeys(buf, "/\<C-R>*") |
| 108 | call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {}) |
| 109 | |
| 110 | call term_sendkeys(buf, "\<Esc>") |
| 111 | call StopVimInTerminal(buf) |
| 112 | endfunc |
| 113 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 114 | " vim: shiftwidth=2 sts=2 expandtab |