blob: 8bf7f0aaeb59f5873082127bc60d398a35e211bc [file] [log] [blame]
Bram Moolenaar53f16732016-09-07 20:46:39 +02001" Test for v:hlsearch
2
Christian Brabandteb380b92025-07-07 20:53:55 +02003source util/screendump.vim
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02004
Bram Moolenaar1e115362019-01-09 23:01:02 +01005func Test_hlsearch()
Bram Moolenaar53f16732016-09-07 20:46:39 +02006 new
7 call setline(1, repeat(['aaa'], 10))
8 set hlsearch nolazyredraw
Bram Moolenaar53f16732016-09-07 20:46:39 +02009 " 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 Moolenaare2e40752020-09-04 21:18:46 +020031 call assert_fails('let v:hlsearch=[]', 'E745:')
Bram Moolenaar53f16732016-09-07 20:46:39 +020032 call garbagecollect(1)
33 call getchar(1)
34 enew!
Bram Moolenaar1e115362019-01-09 23:01:02 +010035endfunc
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020036
37func Test_hlsearch_hangs()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020038 CheckFunction reltimefloat
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020039
Bram Moolenaare5303952022-06-19 17:05:47 +010040 " So, it turns out that Windows 7 implements TimerQueue timers differently
Paul Ollis65745772022-06-05 16:55:54 +010041 " 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 Moolenaar1ef9bbe2017-06-17 20:08:20 +020049 " This pattern takes a long time to match, it should timeout.
Bram Moolenaar09463262017-06-17 20:55:06 +020050 new
51 call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020052 let start = reltime()
53 set hlsearch nolazyredraw redrawtime=101
Bram Moolenaar1ef9bbe2017-06-17 20:08:20 +020054 let @/ = '\%#=1a*.*X\@<=b*'
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020055 redraw
56 let elapsed = reltimefloat(reltime(start))
zeertzjqcdc6a432022-06-19 11:45:46 +010057 call assert_inrange(min_timeout, 1.0, elapsed)
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020058 set nohlsearch redrawtime&
Bram Moolenaar09463262017-06-17 20:55:06 +020059 bwipe!
Bram Moolenaar5b1affe2017-06-17 19:13:49 +020060endfunc
Bram Moolenaar7ee3f152018-09-02 15:07:28 +020061
62func 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!
73endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020074
K.Takatac4b7dec2023-02-10 21:38:44 +000075func Test_hlsearch_Ctrl_R()
Drew Vogelea67ba72025-05-07 22:05:17 +020076 CheckScreendump
K.Takatac4b7dec2023-02-10 21:38:44 +000077 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()
Drew Vogelea67ba72025-05-07 22:05:17 +020095 CheckScreendump
K.Takata9cf6ab12023-05-29 16:08:08 +010096 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)
112endfunc
113
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200114" vim: shiftwidth=2 sts=2 expandtab