robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
3.0 KiB117 linesraw
1" Test for v:hlsearch
2
3source check.vim
4source screendump.vim
5
6func Test_hlsearch()
7  new
8  call setline(1, repeat(['aaa'], 10))
9  set hlsearch nolazyredraw
10  " 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))
32  call assert_fails('let v:hlsearch=[]', 'E745')
33  call garbagecollect(1)
34  call getchar(1)
35  enew!
36endfunc
37
38func Test_hlsearch_hangs()
39  if !has('reltime') || !has('float')
40    return
41  endif
42
43  " So, it turns out the Windows 7 implements TimerQueue timers differently
44  " and they can expire *before* the requested time has elapsed. So allow for
45  " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
46  if has("win32")
47    let min_timeout = 0.08
48  else
49    let min_timeout = 0.1
50  endif
51
52  " This pattern takes a long time to match, it should timeout.
53  new
54  call setline(1, ['aaa', repeat('abc ', 100000), 'ccc'])
55  let start = reltime()
56  set hlsearch nolazyredraw redrawtime=101
57  let @/ = '\%#=1a*.*X\@<=b*'
58  redraw
59  let elapsed = reltimefloat(reltime(start))
60  call assert_inrange(min_timeout, 1.0, elapsed)
61  set nohlsearch redrawtime&
62  bwipe!
63endfunc
64
65func Test_hlsearch_eol_highlight()
66  new
67  call append(1, repeat([''], 9))
68  set hlsearch nolazyredraw
69  exe "normal! /$\<CR>" | redraw
70  let attr = screenattr(1, 1)
71  for row in range(2, 10)
72    call assert_equal(attr, screenattr(row, 1), 'in line ' . row)
73  endfor
74  set nohlsearch
75  bwipe!
76endfunc
77
78func Test_hlsearch_Ctrl_R()
79  CheckScreendump
80  CheckRunVimInTerminal
81
82  let lines =<< trim END
83      set incsearch hlsearch
84      let @" = "text"
85      put
86  END
87  call writefile(lines, 'XhlsearchCtrlR', 'D')
88  let buf = RunVimInTerminal('-S XhlsearchCtrlR', #{rows: 6, cols: 60})
89
90  call term_sendkeys(buf, "/\<C-R>\<C-R>\"")
91  call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
92
93  call term_sendkeys(buf, "\<Esc>")
94  call StopVimInTerminal(buf)
95endfunc
96
97func Test_hlsearch_clipboard()
98  CheckScreendump
99  CheckRunVimInTerminal
100  CheckFeature clipboard_working
101
102  let lines =<< trim END
103      set incsearch hlsearch
104      let @* = "text"
105      put *
106  END
107  call writefile(lines, 'XhlsearchClipboard', 'D')
108  let buf = RunVimInTerminal('-S XhlsearchClipboard', #{rows: 6, cols: 60})
109
110  call term_sendkeys(buf, "/\<C-R>*")
111  call VerifyScreenDump(buf, 'Test_hlsearch_ctrlr_1', {})
112
113  call term_sendkeys(buf, "\<Esc>")
114  call StopVimInTerminal(buf)
115endfunc
116
117" vim: shiftwidth=2 sts=2 expandtab