blob: eb8fb873b70bcced0df09fed51fa390ccb7d4c04 [file] [log] [blame]
Bram Moolenaar53f16732016-09-07 20:46:39 +02001" Test for v:hlsearch
2
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02003source check.vim
K.Takatac4b7dec2023-02-10 21:38:44 +00004source screendump.vim
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02005
Bram Moolenaar1e115362019-01-09 23:01:02 +01006func Test_hlsearch()
Bram Moolenaar53f16732016-09-07 20:46:39 +02007 new
8 call setline(1, repeat(['aaa'], 10))
9 set hlsearch nolazyredraw
Bram Moolenaar53f16732016-09-07 20:46:39 +020010 " redraw is needed to make hlsearch highlight the matches
11 exe "normal! /aaa\<CR>" | redraw
12 let r1 = screenattr(1, 1)
13 nohlsearch | redraw
14 call assert_notequal(r1, screenattr(1,1))
15 let v:hlsearch=1 | redraw
16 call assert_equal(r1, screenattr(1,1))
17 let v:hlsearch=0 | redraw
18 call assert_notequal(r1, screenattr(1,1))
19 set hlsearch | redraw
20 call assert_equal(r1, screenattr(1,1))
21 let v:hlsearch=0 | redraw
22 call assert_notequal(r1, screenattr(1,1))
23 exe "normal! n" | redraw
24 call assert_equal(r1, screenattr(1,1))
25 let v:hlsearch=0 | redraw
26 call assert_notequal(r1, screenattr(1,1))
27 exe "normal! /\<CR>" | redraw
28 call assert_equal(r1, screenattr(1,1))
29 set nohls
30 exe "normal! /\<CR>" | redraw
31 call assert_notequal(r1, screenattr(1,1))
Bram Moolenaare2e40752020-09-04 21:18:46 +020032 call assert_fails('let v:hlsearch=[]', 'E745:')
Bram Moolenaar53f16732016-09-07 20:46:39 +020033 call garbagecollect(1)
34 call getchar(1)
35 enew!
Bram Moolenaar1e115362019-01-09 23:01:02 +010036endfunc
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020037
38func Test_hlsearch_hangs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020039 CheckFunction reltimefloat
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020040
Bram Moolenaare5303952022-06-19 17:05:47 +010041 " So, it turns out that Windows 7 implements TimerQueue timers differently
Paul Ollis65745772022-06-05 16:55:54 +010042 " and they can expire *before* the requested time has elapsed. So allow for
43 " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
44 if has("win32")
45 let min_timeout = 0.08
46 else
47 let min_timeout = 0.1
48 endif
49
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +020050 " This pattern takes a long time to match, it should timeout.
Bram Moolenaar09463262017-06-17 20:55:06 +020051 new
52 call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020053 let start = reltime()
54 set hlsearch nolazyredraw redrawtime=101
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +020055 let @/ = '\%#=1a*.*X\@<=b*'
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020056 redraw
57 let elapsed = reltimefloat(reltime(start))
zeertzjqcdc6a432022-06-19 11:45:46 +010058 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020059 set nohlsearch redrawtime&
Bram Moolenaar09463262017-06-17 20:55:06 +020060 bwipe!
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020061endfunc
Bram Moolenaar7ee3f152018-09-02 15:07:28 +020062
63func 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!
74endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020075
K.Takatac4b7dec2023-02-10 21:38:44 +000076func Test_hlsearch_Ctrl_R()
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)
92endfunc
93
K.Takata9cf6ab12023-05-29 16:08:08 +010094func Test_hlsearch_clipboard()
95 CheckRunVimInTerminal
96 CheckFeature clipboard_working
97
98 let lines =<< trim END
99 set incsearch hlsearch
100 let @* = "text"
101 put *
102 END
103 call writefile(lines, 'XhlsearchClipboard', 'D')
104 let buf = RunVimInTerminal('-S XhlsearchClipboard', #{rows: 6, cols: 60})
105
106 call term_sendkeys(buf, "/\<C-R>*")
107 call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
108
109 call term_sendkeys(buf, "\<Esc>")
110 call StopVimInTerminal(buf)
111endfunc
112
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200113" vim: shiftwidth=2 sts=2 expandtab