Files
neovim/test/functional/legacy/101_hlsearch_spec.lua
Justin M. Keyes 6d8c8b18d5 test(harness): migrate away from magic globals
Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
2026-07-21 13:22:39 +02:00

70 lines
2.0 KiB
Lua

-- Test for v:hlsearch
local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local describe, it, setup = t.describe, t.it, t.setup
local clear, feed = n.clear, n.feed
local feed_command, expect = n.feed_command, n.expect
describe('v:hlsearch', function()
setup(clear)
it('is working', function()
-- Last abc: Q
feed_command('new')
feed_command([[call setline(1, repeat(['aaa'], 10))]])
feed_command('set hlsearch nolazyredraw')
feed_command('let r=[]')
feed_command('command -nargs=0 -bar AddR :call add(r, [screenattr(1, 1), v:hlsearch])')
feed_command('/aaa')
feed_command('AddR')
feed_command('nohlsearch')
feed_command('AddR')
feed_command('let v:hlsearch=1')
feed_command('AddR')
feed_command('let v:hlsearch=0')
feed_command('AddR')
feed_command('set hlsearch')
feed_command('AddR')
feed_command('let v:hlsearch=0')
feed_command('AddR')
feed('n:AddR<cr>')
feed_command('let v:hlsearch=0')
feed_command('AddR')
feed_command('/')
feed_command('AddR')
feed_command('set nohls')
feed_command('/')
feed_command('AddR')
feed_command('let r1=r[0][0]')
-- I guess it is not guaranteed that screenattr outputs always the same character
feed_command([[call map(r, 'v:val[1].":".(v:val[0]==r1?"highlighted":"not highlighted")')]])
feed_command('try')
feed_command(' let v:hlsearch=[]')
feed_command('catch')
feed_command([[ call add(r, matchstr(v:exception,'^Vim(let):E\d\+:'))]])
feed_command('endtry')
feed_command('bwipeout!')
feed_command('$put=r')
feed_command('call garbagecollect(1)')
feed_command('call getchar()')
feed_command('1d', '1d')
-- Assert buffer contents.
expect([[
1:highlighted
0:not highlighted
1:highlighted
0:not highlighted
1:highlighted
0:not highlighted
1:highlighted
0:not highlighted
1:highlighted
0:not highlighted
Vim(let):E745:]])
end)
end)