Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 1 | " Test for v:hlsearch |
| 2 | |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 3 | source check.vim |
| 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 | |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 40 | " So, it turns out the Windows 7 implements TimerQueue timers differently |
| 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)) |
Paul Ollis | 6574577 | 2022-06-05 16:55:54 +0100 | [diff] [blame] | 57 | call assert_true(elapsed > min_timeout) |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 58 | call assert_true(elapsed < 1.0) |
| 59 | set nohlsearch redrawtime& |
Bram Moolenaar | 0946326 | 2017-06-17 20:55:06 +0200 | [diff] [blame] | 60 | bwipe! |
Bram Moolenaar | 5b1affe | 2017-06-17 19:13:49 +0200 | [diff] [blame] | 61 | endfunc |
Bram Moolenaar | 7ee3f15 | 2018-09-02 15:07:28 +0200 | [diff] [blame] | 62 | |
| 63 | func Test_hlsearch_eol_highlight() |
| 64 | new |
| 65 | call append(1, repeat([''], 9)) |
| 66 | set hlsearch nolazyredraw |
| 67 | exe "normal! /$\<CR>" | redraw |
| 68 | let attr = screenattr(1, 1) |
| 69 | for row in range(2, 10) |
| 70 | call assert_equal(attr, screenattr(row, 1), 'in line ' . row) |
| 71 | endfor |
| 72 | set nohlsearch |
| 73 | bwipe! |
| 74 | endfunc |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 75 | |
| 76 | " vim: shiftwidth=2 sts=2 expandtab |