annotate src/testdir/test_hlsearch.vim @ 29071:b90bca860b5a v8.2.5057

patch 8.2.5057: using gettimeofday() for timeout is very inefficient Commit: https://github.com/vim/vim/commit/6574577cacd393ab7591fc776ea060eebc939e55 Author: Paul Ollis <paul@cleversheep.org> Date: Sun Jun 5 16:55:54 2022 +0100 patch 8.2.5057: using gettimeofday() for timeout is very inefficient Problem: Using gettimeofday() for timeout is very inefficient. Solution: Set a platform dependent timer. (Paul Ollis, closes https://github.com/vim/vim/issues/10505)
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jun 2022 18:00:08 +0200
parents ff21e2962490
children 32f3b86352e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for v:hlsearch
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
3 source check.vim
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
4
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14662
diff changeset
5 func Test_hlsearch()
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 new
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call setline(1, repeat(['aaa'], 10))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 set hlsearch nolazyredraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 " redraw is needed to make hlsearch highlight the matches
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 exe "normal! /aaa\<CR>" | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let r1 = screenattr(1, 1)
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 nohlsearch | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_notequal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 let v:hlsearch=1 | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call assert_equal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let v:hlsearch=0 | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 call assert_notequal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 set hlsearch | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 call assert_equal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 let v:hlsearch=0 | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 call assert_notequal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 exe "normal! n" | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 call assert_equal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 let v:hlsearch=0 | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call assert_notequal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 exe "normal! /\<CR>" | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 call assert_equal(r1, screenattr(1,1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 set nohls
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 exe "normal! /\<CR>" | redraw
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call assert_notequal(r1, screenattr(1,1))
22087
ff21e2962490 patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
31 call assert_fails('let v:hlsearch=[]', 'E745:')
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 call garbagecollect(1)
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 call getchar(1)
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 enew!
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 14662
diff changeset
35 endfunc
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
36
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
37 func Test_hlsearch_hangs()
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
38 CheckFunction reltimefloat
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
39
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
40 " So, it turns out the Windows 7 implements TimerQueue timers differently
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
41 " and they can expire *before* the requested time has elapsed. So allow for
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
42 " the timeout occurring after 80 ms (5 * 16 (the typical clock tick)).
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
43 if has("win32")
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
44 let min_timeout = 0.08
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
45 else
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
46 let min_timeout = 0.1
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
47 endif
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
48
11525
14b6b79d685b patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents: 11523
diff changeset
49 " This pattern takes a long time to match, it should timeout.
11527
ac20f71e8aa4 patch 8.0.0646: the hlsearch test fails on fast systems
Christian Brabandt <cb@256bit.org>
parents: 11525
diff changeset
50 new
ac20f71e8aa4 patch 8.0.0646: the hlsearch test fails on fast systems
Christian Brabandt <cb@256bit.org>
parents: 11525
diff changeset
51 call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
52 let start = reltime()
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
53 set hlsearch nolazyredraw redrawtime=101
11525
14b6b79d685b patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents: 11523
diff changeset
54 let @/ = '\%#=1a*.*X\@<=b*'
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
55 redraw
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
56 let elapsed = reltimefloat(reltime(start))
29071
b90bca860b5a patch 8.2.5057: using gettimeofday() for timeout is very inefficient
Bram Moolenaar <Bram@vim.org>
parents: 22087
diff changeset
57 call assert_true(elapsed > min_timeout)
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
58 call assert_true(elapsed < 1.0)
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
59 set nohlsearch redrawtime&
11527
ac20f71e8aa4 patch 8.0.0646: the hlsearch test fails on fast systems
Christian Brabandt <cb@256bit.org>
parents: 11525
diff changeset
60 bwipe!
11523
aad2c2ca0774 patch 8.0.0644: the timeout for 'hlsearch' is not tested
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
61 endfunc
14662
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
62
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
63 func Test_hlsearch_eol_highlight()
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
64 new
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
65 call append(1, repeat([''], 9))
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
66 set hlsearch nolazyredraw
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
67 exe "normal! /$\<CR>" | redraw
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
68 let attr = screenattr(1, 1)
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
69 for row in range(2, 10)
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
70 call assert_equal(attr, screenattr(row, 1), 'in line ' . row)
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
71 endfor
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
72 set nohlsearch
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
73 bwipe!
04c168a6d998 patch 8.1.0344: 'hlsearch' highlighting has a gap after /$
Christian Brabandt <cb@256bit.org>
parents: 11527
diff changeset
74 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
75
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
76 " vim: shiftwidth=2 sts=2 expandtab