aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2024-04-08 11:03:20 +0200
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2024-04-08 22:51:00 +0200
commit7035125b2b26aa68fcfb7cda39377ac79926a0f9 (patch)
treed194a3556a367b42505f9e7d26637e7cb3674928 /test/functional/lua
parent978962f9a00ce75216d2c36b79397ef3d2b54096 (diff)
downloadrneovim-7035125b2b26aa68fcfb7cda39377ac79926a0f9.tar.gz
rneovim-7035125b2b26aa68fcfb7cda39377ac79926a0f9.tar.bz2
rneovim-7035125b2b26aa68fcfb7cda39377ac79926a0f9.zip
test: improve test conventions
Work on https://github.com/neovim/neovim/issues/27004.
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/api_spec.lua18
-rw-r--r--test/functional/lua/base64_spec.lua12
-rw-r--r--test/functional/lua/buffer_updates_spec.lua30
-rw-r--r--test/functional/lua/command_line_completion_spec.lua8
-rw-r--r--test/functional/lua/commands_spec.lua34
-rw-r--r--test/functional/lua/comment_spec.lua16
-rw-r--r--test/functional/lua/diagnostic_spec.lua36
-rw-r--r--test/functional/lua/ffi_spec.lua8
-rw-r--r--test/functional/lua/filetype_spec.lua20
-rw-r--r--test/functional/lua/fs_spec.lua26
-rw-r--r--test/functional/lua/glob_spec.lua10
-rw-r--r--test/functional/lua/highlight_spec.lua18
-rw-r--r--test/functional/lua/inspector_spec.lua10
-rw-r--r--test/functional/lua/iter_spec.lua182
-rw-r--r--test/functional/lua/json_spec.lua10
-rw-r--r--test/functional/lua/loader_spec.lua28
-rw-r--r--test/functional/lua/loop_spec.lua20
-rw-r--r--test/functional/lua/luaeval_spec.lua28
-rw-r--r--test/functional/lua/mpack_spec.lua8
-rw-r--r--test/functional/lua/overrides_spec.lua24
-rw-r--r--test/functional/lua/runtime_spec.lua20
-rw-r--r--test/functional/lua/secure_spec.lua40
-rw-r--r--test/functional/lua/snippet_spec.lua26
-rw-r--r--test/functional/lua/spell_spec.lua10
-rw-r--r--test/functional/lua/system_spec.lua8
-rw-r--r--test/functional/lua/text_spec.lua6
-rw-r--r--test/functional/lua/thread_spec.lua16
-rw-r--r--test/functional/lua/ui_event_spec.lua20
-rw-r--r--test/functional/lua/ui_spec.lua20
-rw-r--r--test/functional/lua/uri_spec.lua16
-rw-r--r--test/functional/lua/version_spec.lua16
-rw-r--r--test/functional/lua/vim_spec.lua70
-rw-r--r--test/functional/lua/watch_spec.lua23
-rw-r--r--test/functional/lua/xdiff_spec.lua10
34 files changed, 418 insertions, 429 deletions
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index acd56a0ddb..0aa63327ad 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -1,15 +1,15 @@
-- Test suite for testing interactions with API bindings
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.functional.testutil')(after_each)
-local exc_exec = helpers.exc_exec
-local remove_trace = helpers.remove_trace
-local fn = helpers.fn
-local clear = helpers.clear
-local eval = helpers.eval
+local exc_exec = t.exc_exec
+local remove_trace = t.remove_trace
+local fn = t.fn
+local clear = t.clear
+local eval = t.eval
local NIL = vim.NIL
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local pcall_err = helpers.pcall_err
+local eq = t.eq
+local exec_lua = t.exec_lua
+local pcall_err = t.pcall_err
before_each(clear)
diff --git a/test/functional/lua/base64_spec.lua b/test/functional/lua/base64_spec.lua
index 21fd536a98..9410a6fd6f 100644
--- a/test/functional/lua/base64_spec.lua
+++ b/test/functional/lua/base64_spec.lua
@@ -1,9 +1,9 @@
-local helpers = require('test.functional.helpers')(after_each)
-local clear = helpers.clear
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local pcall_err = helpers.pcall_err
-local matches = helpers.matches
+local t = require('test.functional.testutil')(after_each)
+local clear = t.clear
+local exec_lua = t.exec_lua
+local eq = t.eq
+local pcall_err = t.pcall_err
+local matches = t.matches
describe('vim.base64', function()
before_each(clear)
diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua
index 01dc8c2f02..490177b96b 100644
--- a/test/functional/lua/buffer_updates_spec.lua
+++ b/test/functional/lua/buffer_updates_spec.lua
@@ -1,18 +1,18 @@
-- Test suite for testing interactions with API bindings
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.functional.testutil')(after_each)
local Screen = require('test.functional.ui.screen')
-local command = helpers.command
-local api = helpers.api
-local fn = helpers.fn
-local clear = helpers.clear
-local eq = helpers.eq
-local fail = helpers.fail
-local exec_lua = helpers.exec_lua
-local feed = helpers.feed
-local expect_events = helpers.expect_events
-local write_file = helpers.write_file
-local dedent = helpers.dedent
+local command = t.command
+local api = t.api
+local fn = t.fn
+local clear = t.clear
+local eq = t.eq
+local fail = t.fail
+local exec_lua = t.exec_lua
+local feed = t.feed
+local expect_events = t.expect_events
+local write_file = t.write_file
+local dedent = t.dedent
local origlines = {
'original line 1',
@@ -292,11 +292,11 @@ describe('lua buffer event callbacks: on_lines', function()
exec_lua(code)
command('q!')
- helpers.assert_alive()
+ t.assert_alive()
exec_lua(code)
command('bd!')
- helpers.assert_alive()
+ t.assert_alive()
end)
it('#12718 lnume', function()
@@ -965,7 +965,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
command('e! Xtest-undofile')
command('set undodir=. | set undofile')
- local ns = helpers.request('nvim_create_namespace', 'ns1')
+ local ns = t.request('nvim_create_namespace', 'ns1')
api.nvim_buf_set_extmark(0, ns, 0, 0, {})
eq({ '12345', 'hello world' }, api.nvim_buf_get_lines(0, 0, -1, true))
diff --git a/test/functional/lua/command_line_completion_spec.lua b/test/functional/lua/command_line_completion_spec.lua
index b88a38082f..41e807f086 100644
--- a/test/functional/lua/command_line_completion_spec.lua
+++ b/test/functional/lua/command_line_completion_spec.lua
@@ -1,8 +1,8 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.functional.testutil')(after_each)
-local clear = helpers.clear
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
+local clear = t.clear
+local eq = t.eq
+local exec_lua = t.exec_lua
local get_completions = function(input, env)
return exec_lua('return {vim._expand_pat(...)}', input, env)
diff --git a/test/functional/lua/commands_spec.lua b/test/functional/lua/commands_spec.lua
index b8d0638ce5..04188281bc 100644
--- a/test/functional/lua/commands_spec.lua
+++ b/test/functional/lua/commands_spec.lua
@@ -1,24 +1,24 @@
-- Test suite for checking :lua* commands
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.functional.testutil')(after_each)
local Screen = require('test.functional.ui.screen')
-local eq = helpers.eq
+local eq = t.eq
local NIL = vim.NIL
-local eval = helpers.eval
-local feed = helpers.feed
-local clear = helpers.clear
-local matches = helpers.matches
-local api = helpers.api
-local exec_lua = helpers.exec_lua
-local exec_capture = helpers.exec_capture
-local fn = helpers.fn
-local source = helpers.source
-local dedent = helpers.dedent
-local command = helpers.command
-local exc_exec = helpers.exc_exec
-local pcall_err = helpers.pcall_err
-local write_file = helpers.write_file
-local remove_trace = helpers.remove_trace
+local eval = t.eval
+local feed = t.feed
+local clear = t.clear
+local matches = t.matches
+local api = t.api
+local exec_lua = t.exec_lua
+local exec_capture = t.exec_capture
+local fn = t.fn
+local source = t.source
+local dedent = t.dedent
+local command = t.command
+local exc_exec = t.exc_exec
+local pcall_err = t.pcall_err
+local write_file = t.write_file
+local remove_trace = t.remove_trace
before_each(clear)
diff --git a/test/functional/lua/comment_spec.lua b/test/functional/lua/comment_spec.lua
index 72935c47d5..3b230780ad 100644
--- a/test/functional/lua/comment_spec.lua
+++ b/test/functional/lua/comment_spec.lua
@@ -1,11 +1,11 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local api = helpers.api
-local clear = helpers.clear
-local eq = helpers.eq
-local exec_capture = helpers.exec_capture
-local exec_lua = helpers.exec_lua
-local feed = helpers.feed
+local t = require('test.functional.testutil')(after_each)
+
+local api = t.api
+local clear = t.clear
+local eq = t.eq
+local exec_capture = t.exec_capture
+local exec_lua = t.exec_lua
+local feed = t.feed
-- Reference text
-- aa
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index f648c0b215..152258dd8c 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -1,14 +1,14 @@
-local helpers = require('test.functional.helpers')(after_each)
+local t = require('test.functional.testutil')(after_each)
local NIL = vim.NIL
-local command = helpers.command
-local clear = helpers.clear
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local matches = helpers.matches
-local api = helpers.api
-local pcall_err = helpers.pcall_err
-local fn = helpers.fn
+local command = t.command
+local clear = t.clear
+local exec_lua = t.exec_lua
+local eq = t.eq
+local matches = t.matches
+local api = t.api
+local pcall_err = t.pcall_err
+local fn = t.fn
describe('vim.diagnostic', function()
before_each(function()
@@ -1826,20 +1826,12 @@ describe('vim.diagnostic', function()
it('respects legacy signs placed with :sign define or sign_define #26618', function()
-- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12
- eq(0, helpers.fn.has('nvim-0.12'))
+ eq(0, t.fn.has('nvim-0.12'))
- helpers.command(
- 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg'
- )
- helpers.command(
- 'sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg'
- )
- helpers.command(
- 'sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined'
- )
- helpers.command(
- 'sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined'
- )
+ t.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg')
+ t.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg')
+ t.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined')
+ t.command('sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined')
local result = exec_lua [[
vim.diagnostic.config({
diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua
index 4229e4af9b..2cde9f4f2a 100644
--- a/test/functional/lua/ffi_spec.lua
+++ b/test/functional/lua/ffi_spec.lua
@@ -1,7 +1,7 @@
-local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
-local clear = helpers.clear
+local t = require('test.functional.testutil')(after_each)
+local eq = t.eq
+local exec_lua = t.exec_lua
+local clear = t.clear
before_each(clear)
diff --git a/test/functional/lua/filetype_spec.lua b/test/functional/lua/filetype_spec.lua
index 3ef650a1d2..677d039b81 100644
--- a/test/functional/lua/filetype_spec.lua
+++ b/test/functional/lua/filetype_spec.lua
@@ -1,13 +1,13 @@
-local helpers = require('test.functional.helpers')(after_each)
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local api = helpers.api
-local clear = helpers.clear
-local pathroot = helpers.pathroot
-local command = helpers.command
-local mkdir = helpers.mkdir
-local rmdir = helpers.rmdir
-local write_file = helpers.write_file
+local t = require('test.functional.testutil')(after_each)
+local exec_lua = t.exec_lua
+local eq = t.eq
+local api = t.api
+local clear = t.clear
+local pathroot = t.pathroot
+local command = t.command
+local mkdir = t.mkdir
+local rmdir = t.rmdir
+local write_file = t.write_file
local uv = vim.uv
local root = pathroot()
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index 6e7811908b..a0df71b20a 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -1,16 +1,16 @@
-local helpers = require('test.functional.helpers')(after_each)
-
-local clear = helpers.clear
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local mkdir_p = helpers.mkdir_p
-local rmdir = helpers.rmdir
-local nvim_dir = helpers.nvim_dir
-local test_build_dir = helpers.paths.test_build_dir
-local test_source_path = helpers.paths.test_source_path
-local nvim_prog = helpers.nvim_prog
-local is_os = helpers.is_os
-local mkdir = helpers.mkdir
+local t = require('test.functional.testutil')(after_each)
+
+local clear = t.clear
+local exec_lua = t.exec_lua
+local eq = t.eq
+local mkdir_p = t.mkdir_p
+local rmdir = t.rmdir
+local nvim_dir = t.nvim_dir
+local test_build_dir = t.paths.test_build_dir
+local test_source_path = t.paths.test_source_path
+local nvim_prog = t.nvim_prog
+local is_os = t.is_os
+local mkdir = t.mkdir
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua
index 1eac037575..dbe1079092 100644
--- a/test/functional/lua/glob_spec.lua
+++ b/test/functional/lua/glob_spec.lua
@@ -1,10 +1,10 @@
-local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
-local exec_lua = helpers.exec_lua
+local t = require('test.functional.testutil')(after_each)
+local eq = t.eq
+local exec_lua = t.exec_lua
describe('glob', function()
- before_each(helpers.clear)
- after_each(helpers.clear)
+ before_each(t.clear)
+ after_each(t.clear)
local match = function(...)
return exec_lua(
diff --git a/test/functional/lua/highlight_spec.lua b/test/functional/lua/highlight_spec.lua
index 197f3139f3..dc80a1672a 100644
--- a/test/functional/lua/highlight_spec.lua
+++ b/test/functional/lua/highlight_spec.lua
@@ -1,11 +1,11 @@
-local helpers = require('test.functional.helpers')(after_each)
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local neq = helpers.neq
-local eval = helpers.eval
-local command = helpers.command
-local clear = helpers.clear
-local api = helpers.api
+local t = require('test.functional.testutil')(after_each)
+local exec_lua = t.exec_lua
+local eq = t.eq
+local neq = t.neq
+local eval = t.eval
+local command = t.command
+local clear = t.clear
+local api = t.api
describe('vim.highlight.on_yank', function()
before_each(function()
@@ -19,7 +19,7 @@ describe('vim.highlight.on_yank', function()
vim.cmd('bwipeout!')
]])
vim.uv.sleep(10)
- helpers.feed('<cr>') -- avoid hang if error message exists
+ t.feed('<cr>') -- avoid hang if error message exists
eq('', eval('v:errmsg'))
end)
diff --git a/test/functional/lua/inspector_spec.lua b/test/functional/lua/inspector_spec.lua
index ad8b5a45a8..efc710d0d7 100644
--- a/test/functional/lua/inspector_spec.lua
+++ b/test/functional/lua/inspector_spec.lua
@@ -1,8 +1,8 @@
-local helpers = require('test.functional.helpers')(after_each)
-local exec_lua = helpers.exec_lua
-local eq = helpers.eq
-local eval = helpers.eval
-local clear = helpers.clear
+local t = require('test.functional.testutil')(after_each)
+local exec_lua = t.exec_lua
+local eq = t.eq
+local eval = t.eval
+local clear = t.clear
describe('vim.inspect_pos', function()
before_each(function()
diff --git a/test/functional/lua/iter_spec.lua b/test/functional/lua/iter_spec.lua
index 6d8a37f022..237710242d 100644
--- a/test/functional/lua/iter_spec.lua
+++ b/test/functional/lua/iter_spec.lua
@@ -1,7 +1,7 @@
-local helpers = require('test.functional.helpers')(after_each)
-local eq = helpers.eq
-local matches = helpers.matches
-local pcall_err = helpers.pcall_err
+local t = require('test.functional.testutil')(after_each)
+local eq = t.eq
+local matches = t.matches
+local pcall_err = t.pcall_err
describe('vim.iter', function()
it('new() on iterable class instance', function()
@@ -18,12 +18,12 @@ describe('vim.iter', function()
return v % 2 ~= 0
end
- local t = { 1, 2, 3, 4, 5 }
- eq({ 1, 3, 5 }, vim.iter(t):filter(odd):totable())
+ local q = { 1, 2, 3, 4, 5 }
+ eq({ 1, 3, 5 }, vim.iter(q):filter(odd):totable())
eq(
{ 2, 4 },
vim
- .iter(t)
+ .iter(q)
:filter(function(v)
return not odd(v)
end)
@@ -32,7 +32,7 @@ describe('vim.iter', function()
eq(
{},
vim
- .iter(t)
+ .iter(q)
:filter(function(v)
return v > 5
end)
@@ -40,7 +40,7 @@ describe('vim.iter', function()
)
do
- local it = vim.iter(ipairs(t))
+ local it = vim.iter(ipairs(q))
it:filter(function(i, v)
return i > 1 and v < 5
end)
@@ -60,11 +60,11 @@ describe('vim.iter', function()
end)
it('map()', function()
- local t = { 1, 2, 3, 4, 5 }
+ local q = { 1, 2, 3, 4, 5 }
eq(
{ 2, 4, 6, 8, 10 },
vim
- .iter(t)
+ .iter(q)
:map(function(v)
return 2 * v
end)
@@ -96,10 +96,10 @@ describe('vim.iter', function()
end)
it('for loops', function()
- local t = { 1, 2, 3, 4, 5 }
+ local q = { 1, 2, 3, 4, 5 }
local acc = 0
for v in
- vim.iter(t):map(function(v)
+ vim.iter(q):map(function(v)
return v * 3
end)
do
@@ -146,13 +146,13 @@ describe('vim.iter', function()
it('skip()', function()
do
- local t = { 4, 3, 2, 1 }
- eq(t, vim.iter(t):skip(0):totable())
- eq({ 3, 2, 1 }, vim.iter(t):skip(1):totable())
- eq({ 2, 1 }, vim.iter(t):skip(2):totable())
- eq({ 1 }, vim.iter(t):skip(#t - 1):totable())
- eq({}, vim.iter(t):skip(#t):totable())
- eq({}, vim.iter(t):skip(#t + 1):totable())
+ local q = { 4, 3, 2, 1 }
+ eq(q, vim.iter(q):skip(0):totable())
+ eq({ 3, 2, 1 }, vim.iter(q):skip(1):totable())
+ eq({ 2, 1 }, vim.iter(q):skip(2):totable())
+ eq({ 1 }, vim.iter(q):skip(#q - 1):totable())
+ eq({}, vim.iter(q):skip(#q):totable())
+ eq({}, vim.iter(q):skip(#q + 1):totable())
end
do
@@ -170,13 +170,13 @@ describe('vim.iter', function()
it('skipback()', function()
do
- local t = { 4, 3, 2, 1 }
- eq(t, vim.iter(t):skipback(0):totable())
- eq({ 4, 3, 2 }, vim.iter(t):skipback(1):totable())
- eq({ 4, 3 }, vim.iter(t):skipback(2):totable())
- eq({ 4 }, vim.iter(t):skipback(#t - 1):totable())
- eq({}, vim.iter(t):skipback(#t):totable())
- eq({}, vim.iter(t):skipback(#t + 1):totable())
+ local q = { 4, 3, 2, 1 }
+ eq(q, vim.iter(q):skipback(0):totable())
+ eq({ 4, 3, 2 }, vim.iter(q):skipback(1):totable())
+ eq({ 4, 3 }, vim.iter(q):skipback(2):totable())
+ eq({ 4 }, vim.iter(q):skipback(#q - 1):totable())
+ eq({}, vim.iter(q):skipback(#q):totable())
+ eq({}, vim.iter(q):skipback(#q + 1):totable())
end
local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
@@ -184,14 +184,14 @@ describe('vim.iter', function()
end)
it('slice()', function()
- local t = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
- eq({ 3, 4, 5, 6, 7 }, vim.iter(t):slice(3, 7):totable())
- eq({}, vim.iter(t):slice(6, 5):totable())
- eq({}, vim.iter(t):slice(0, 0):totable())
- eq({ 1 }, vim.iter(t):slice(1, 1):totable())
- eq({ 1, 2 }, vim.iter(t):slice(1, 2):totable())
- eq({ 10 }, vim.iter(t):slice(10, 10):totable())
- eq({ 8, 9, 10 }, vim.iter(t):slice(8, 11):totable())
+ local q = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
+ eq({ 3, 4, 5, 6, 7 }, vim.iter(q):slice(3, 7):totable())
+ eq({}, vim.iter(q):slice(6, 5):totable())
+ eq({}, vim.iter(q):slice(0, 0):totable())
+ eq({ 1 }, vim.iter(q):slice(1, 1):totable())
+ eq({ 1, 2 }, vim.iter(q):slice(1, 2):totable())
+ eq({ 10 }, vim.iter(q):slice(10, 10):totable())
+ eq({ 8, 9, 10 }, vim.iter(q):slice(8, 11):totable())
local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
matches('slice%(%) requires a list%-like table', pcall_err(it.slice, it, 1, 3))
@@ -199,13 +199,13 @@ describe('vim.iter', function()
it('nth()', function()
do
- local t = { 4, 3, 2, 1 }
- eq(nil, vim.iter(t):nth(0))
- eq(4, vim.iter(t):nth(1))
- eq(3, vim.iter(t):nth(2))
- eq(2, vim.iter(t):nth(3))
- eq(1, vim.iter(t):nth(4))
- eq(nil, vim.iter(t):nth(5))
+ local q = { 4, 3, 2, 1 }
+ eq(nil, vim.iter(q):nth(0))
+ eq(4, vim.iter(q):nth(1))
+ eq(3, vim.iter(q):nth(2))
+ eq(2, vim.iter(q):nth(3))
+ eq(1, vim.iter(q):nth(4))
+ eq(nil, vim.iter(q):nth(5))
end
do
@@ -223,13 +223,13 @@ describe('vim.iter', function()
it('nthback()', function()
do
- local t = { 4, 3, 2, 1 }
- eq(nil, vim.iter(t):nthback(0))
- eq(1, vim.iter(t):nthback(1))
- eq(2, vim.iter(t):nthback(2))
- eq(3, vim.iter(t):nthback(3))
- eq(4, vim.iter(t):nthback(4))
- eq(nil, vim.iter(t):nthback(5))
+ local q = { 4, 3, 2, 1 }
+ eq(nil, vim.iter(q):nthback(0))
+ eq(1, vim.iter(q):nthback(1))
+ eq(2, vim.iter(q):nthback(2))
+ eq(3, vim.iter(q):nthback(3))
+ eq(4, vim.iter(q):nthback(4))
+ eq(nil, vim.iter(q):nthback(5))
end
local it = vim.iter(vim.gsplit('a|b|c|d', '|'))
@@ -238,24 +238,24 @@ describe('vim.iter', function()
it('take()', function()
do
- local t = { 4, 3, 2, 1 }
- eq({}, vim.iter(t):take(0):totable())
- eq({ 4 }, vim.iter(t):take(1):totable())
- eq({ 4, 3 }, vim.iter(t):take(2):totable())
- eq({ 4, 3, 2 }, vim.iter(t):take(3):totable())
- eq({ 4, 3, 2, 1 }, vim.iter(t):take(4):totable())
- eq({ 4, 3, 2, 1 }, vim.iter(t):take(5):totable())
+ local q = { 4, 3, 2, 1 }
+ eq({}, vim.iter(q):take(0):totable())
+ eq({ 4 }, vim.iter(q):take(1):totable())
+ eq({ 4, 3 }, vim.iter(q):take(2):totable())
+ eq({ 4, 3, 2 }, vim.iter(q):take(3):totable())
+ eq({ 4, 3, 2, 1 }, vim.iter(q):take(4):totable())
+ eq({ 4, 3, 2, 1 }, vim.iter(q):take(5):totable())
end
do
- local t = { 4, 3, 2, 1 }
- eq({ 1, 2, 3 }, vim.iter(t):rev():take(3):totable())
- eq({ 2, 3, 4 }, vim.iter(t):take(3):rev():totable())
+ local q = { 4, 3, 2, 1 }
+ eq({ 1, 2, 3 }, vim.iter(q):rev():take(3):totable())
+ eq({ 2, 3, 4 }, vim.iter(q):take(3):rev():totable())
end
do
- local t = { 4, 3, 2, 1 }
- local it = vim.iter(t)
+ local q = { 4, 3, 2, 1 }
+ local it = vim.iter(q)
eq({ 4, 3 }, it:take(2):totable())
-- tail is already set from the previous take()
eq({ 4, 3 }, it:take(3):totable())
@@ -275,13 +275,13 @@ describe('vim.iter', function()
end
do
- local t = { 4, 8, 9, 10 }
- eq(true, vim.iter(t):any(odd))
+ local q = { 4, 8, 9, 10 }
+ eq(true, vim.iter(q):any(odd))
end
do
- local t = { 4, 8, 10 }
- eq(false, vim.iter(t):any(odd))
+ local q = { 4, 8, 10 }
+ eq(false, vim.iter(q):any(odd))
end
do
@@ -306,13 +306,13 @@ describe('vim.iter', function()
end
do
- local t = { 3, 5, 7, 9 }
- eq(true, vim.iter(t):all(odd))
+ local q = { 3, 5, 7, 9 }
+ eq(true, vim.iter(q):all(odd))
end
do
- local t = { 3, 5, 7, 10 }
- eq(false, vim.iter(t):all(odd))
+ local q = { 3, 5, 7, 10 }
+ eq(false, vim.iter(q):all(odd))
end
do
@@ -360,18 +360,18 @@ describe('vim.iter', function()
end)
it('find()', function()
- local t = { 3, 6, 9, 12 }
- eq(12, vim.iter(t):find(12))
- eq(nil, vim.iter(t):find(15))
+ local q = { 3, 6, 9, 12 }
+ eq(12, vim.iter(q):find(12))
+ eq(nil, vim.iter(q):find(15))
eq(
12,
- vim.iter(t):find(function(v)
+ vim.iter(q):find(function(v)
return v % 4 == 0
end)
)
do
- local it = vim.iter(t)
+ local it = vim.iter(q)
local pred = function(v)
return v % 3 == 0
end
@@ -395,16 +395,16 @@ describe('vim.iter', function()
end)
it('rfind()', function()
- local t = { 1, 2, 3, 2, 1 }
+ local q = { 1, 2, 3, 2, 1 }
do
- local it = vim.iter(t)
+ local it = vim.iter(q)
eq(1, it:rfind(1))
eq(1, it:rfind(1))
eq(nil, it:rfind(1))
end
do
- local it = vim.iter(t):enumerate()
+ local it = vim.iter(q):enumerate()
local pred = function(i)
return i % 2 ~= 0
end
@@ -452,16 +452,16 @@ describe('vim.iter', function()
end)
it('fold()', function()
- local t = { 1, 2, 3, 4, 5 }
+ local q = { 1, 2, 3, 4, 5 }
eq(
115,
- vim.iter(t):fold(100, function(acc, v)
+ vim.iter(q):fold(100, function(acc, v)
return acc + v
end)
)
eq(
{ 5, 4, 3, 2, 1 },
- vim.iter(t):fold({}, function(acc, v)
+ vim.iter(q):fold({}, function(acc, v)
table.insert(acc, 1, v)
return acc
end)
@@ -469,14 +469,14 @@ describe('vim.iter', function()
end)
it('flatten()', function()
- local t = { { 1, { 2 } }, { { { { 3 } } }, { 4 } }, { 5 } }
+ local q = { { 1, { 2 } }, { { { { 3 } } }, { 4 } }, { 5 } }
- eq(t, vim.iter(t):flatten(-1):totable())
- eq(t, vim.iter(t):flatten(0):totable())
- eq({ 1, { 2 }, { { { 3 } } }, { 4 }, 5 }, vim.iter(t):flatten():totable())
- eq({ 1, 2, { { 3 } }, 4, 5 }, vim.iter(t):flatten(2):totable())
- eq({ 1, 2, { 3 }, 4, 5 }, vim.iter(t):flatten(3):totable())
- eq({ 1, 2, 3, 4, 5 }, vim.iter(t):flatten(4):totable())
+ eq(q, vim.iter(q):flatten(-1):totable())
+ eq(q, vim.iter(q):flatten(0):totable())
+ eq({ 1, { 2 }, { { { 3 } } }, { 4 }, 5 }, vim.iter(q):flatten():totable())
+ eq({ 1, 2, { { 3 } }, 4, 5 }, vim.iter(q):flatten(2):totable())
+ eq({ 1, 2, { 3 }, 4, 5 }, vim.iter(q):flatten(3):totable())
+ eq({ 1, 2, 3, 4, 5 }, vim.iter(q):flatten(4):totable())
local m = { a = 1, b = { 2, 3 }, d = { 4 } }
local it = vim.iter(m)
@@ -507,11 +507,11 @@ describe('vim.iter', function()
end
end)
- local t = it:fold({}, function(t, k, v)
- t[k] = v
- return t
+ local q =