aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/clipboard/clipboard_provider_spec.lua4
-rw-r--r--test/functional/helpers.lua2
-rw-r--r--test/functional/normal/undo_spec.lua61
-rw-r--r--test/functional/terminal/ex_terminal_spec.lua36
-rw-r--r--test/functional/ui/inccommand_spec.lua12
-rw-r--r--test/functional/ui/output_spec.lua5
-rw-r--r--test/functional/ui/screen.lua2
-rw-r--r--test/unit/memory_spec.lua51
8 files changed, 166 insertions, 7 deletions
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua
index 6424b39e13..2b26697b97 100644
--- a/test/functional/clipboard/clipboard_provider_spec.lua
+++ b/test/functional/clipboard/clipboard_provider_spec.lua
@@ -5,8 +5,6 @@ local Screen = require('test.functional.ui.screen')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect, eq, eval = helpers.execute, helpers.expect, helpers.eq, helpers.eval
-if helpers.pending_win32(pending) then return end
-
local function basic_register_test(noblock)
insert("some words")
@@ -440,6 +438,8 @@ describe('clipboard usage', function()
end)
it('handles middleclick correctly', function()
+ execute('set mouse=a')
+
local screen = Screen.new(30, 5)
screen:attach()
insert([[
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index 7de1d0f2c6..880cb6546c 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -195,7 +195,7 @@ local function dedent(str)
indent = line_indent
end
end
- if #indent == 0 then
+ if indent == nil or #indent == 0 then
-- no minimum common indent
return str
end
diff --git a/test/functional/normal/undo_spec.lua b/test/functional/normal/undo_spec.lua
new file mode 100644
index 0000000000..55429f2e1e
--- /dev/null
+++ b/test/functional/normal/undo_spec.lua
@@ -0,0 +1,61 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local execute = helpers.execute
+local expect = helpers.expect
+local feed = helpers.feed
+local insert = helpers.insert
+
+describe('u CTRL-R g- g+', function()
+ before_each(clear)
+
+ local function create_history(num_steps)
+ if num_steps == 0 then return end
+ insert('1')
+ if num_steps == 1 then return end
+ feed('o2<esc>')
+ feed('o3<esc>')
+ feed('u')
+ if num_steps == 2 then return end
+ feed('o4<esc>')
+ if num_steps == 3 then return end
+ feed('u')
+ end
+
+ local function undo_and_redo(hist_pos, undo, redo, expect_str)
+ execute('enew!')
+ create_history(hist_pos)
+ local cur_contents = helpers.curbuf_contents()
+ feed(undo)
+ expect(expect_str)
+ feed(redo)
+ expect(cur_contents)
+ end
+
+ -- TODO Look for message saying 'Already at oldest change'
+ it('does nothing when no changes have happened', function()
+ undo_and_redo(0, 'u', '<C-r>', '')
+ undo_and_redo(0, 'g-', 'g+', '')
+ end)
+ it('undoes a change when at a leaf', function()
+ undo_and_redo(1, 'u', '<C-r>', '')
+ undo_and_redo(1, 'g-', 'g+', '')
+ end)
+ it('undoes a change when in a non-leaf', function()
+ undo_and_redo(2, 'u', '<C-r>', '1')
+ undo_and_redo(2, 'g-', 'g+', '1')
+ end)
+ it('undoes properly around a branch point', function()
+ undo_and_redo(3, 'u', '<C-r>', [[
+ 1
+ 2]])
+ undo_and_redo(3, 'g-', 'g+', [[
+ 1
+ 2
+ 3]])
+ end)
+ it('can find the previous sequence after undoing to a branch', function()
+ undo_and_redo(4, 'u', '<C-r>', '1')
+ undo_and_redo(4, 'g-', 'g+', '1')
+ end)
+end)
diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua
index 4247be0417..7c391db18c 100644
--- a/test/functional/terminal/ex_terminal_spec.lua
+++ b/test/functional/terminal/ex_terminal_spec.lua
@@ -112,4 +112,40 @@ describe(':terminal (with fake shell)', function()
eq(2, eval("1+1")) -- Still alive?
end)
+ it('works with findfile()', function()
+ execute('terminal')
+ eq('term://', string.match(eval('bufname("%")'), "^term://"))
+ eq('scripts/shadacat.py', eval('findfile("scripts/shadacat.py", ".")'))
+ end)
+
+ it('works with :find', function()
+ terminal_with_fake_shell()
+ wait()
+ screen:expect([[
+ ready $ |
+ [Process exited 0] |
+ |
+ -- TERMINAL -- |
+ ]])
+ eq('term://', string.match(eval('bufname("%")'), "^term://"))
+ helpers.feed([[<C-\><C-N>]])
+ execute([[find */shadacat.py]])
+ eq('scripts/shadacat.py', eval('bufname("%")'))
+ end)
+
+ it('works with gf', function()
+ terminal_with_fake_shell([[echo "scripts/shadacat.py"]])
+ wait()
+ screen:expect([[
+ ready $ echo "scripts/shadacat.py" |
+ |
+ [Process exited 0] |
+ -- TERMINAL -- |
+ ]])
+ helpers.feed([[<C-\><C-N>]])
+ eq('term://', string.match(eval('bufname("%")'), "^term://"))
+ helpers.feed([[ggf"lgf]])
+ eq('scripts/shadacat.py', eval('bufname("%")'))
+ end)
+
end)
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index 41ebfd2334..6da22b6a3a 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -352,6 +352,14 @@ describe(":substitute, 'inccommand' preserves undo", function()
feed("2u")
feed(substring .. "<esc>")
+ expect([[
+ 1]])
+ feed("g-")
+ expect([[
+ ]])
+ feed("g+")
+ expect([[
+ 1]])
feed("<c-r>")
expect([[
1
@@ -374,9 +382,7 @@ describe(":substitute, 'inccommand' preserves undo", function()
2]])
end
- -- TODO(vim): This does not work, even in Vim.
- -- Waiting for fix (perhaps from upstream).
- pending("at a non-leaf of the undo tree", function()
+ it("at a non-leaf of the undo tree", function()
for _, case in pairs(cases) do
for _, str in pairs(substrings) do
for _, redoable in pairs({true}) do
diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua
index 47b2516188..33086a61b1 100644
--- a/test/functional/ui/output_spec.lua
+++ b/test/functional/ui/output_spec.lua
@@ -41,6 +41,11 @@ describe("shell command :!", function()
end)
it("throttles shell-command output greater than ~10KB", function()
+ if os.getenv("TRAVIS") and session.os_name() == "osx" then
+ pending("[Unreliable on Travis macOS.]", function() end)
+ return
+ end
+
screen.timeout = 20000 -- Avoid false failure on slow systems.
child_session.feed_data(
":!for i in $(seq 2 3000); do echo XXXXXXXXXX $i; done\n")
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index bb82f11a58..54f43387dc 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -613,7 +613,7 @@ function Screen:_pprint_attrs(attrs)
return table.concat(items, ", ")
end
-function backward_find_meaningful(tbl, from) -- luacheck: ignore
+local function backward_find_meaningful(tbl, from) -- luacheck: no unused
for i = from or #tbl, 1, -1 do
if tbl[i] ~= ' ' then
return i + 1
diff --git a/test/unit/memory_spec.lua b/test/unit/memory_spec.lua
new file mode 100644
index 0000000000..73a32724ef
--- /dev/null
+++ b/test/unit/memory_spec.lua
@@ -0,0 +1,51 @@
+local helpers = require("test.unit.helpers")
+
+local cimport = helpers.cimport
+local cstr = helpers.cstr
+local eq = helpers.eq
+local ffi = helpers.ffi
+local to_cstr = helpers.to_cstr
+
+local cimp = cimport('stdlib.h', './src/nvim/memory.h')
+
+describe('xstrlcat()', function()
+ local function test_xstrlcat(dst, src, dsize)
+ assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
+ local dst_cstr = cstr(dsize, dst)
+ local src_cstr = to_cstr(src)
+ eq(string.len(dst .. src), cimp.xstrlcat(dst_cstr, src_cstr, dsize))
+ return ffi.string(dst_cstr)
+ end
+
+ local function test_xstrlcat_overlap(dst, src_idx, dsize)
+ assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
+ local dst_cstr = cstr(dsize, dst)
+ local src_cstr = dst_cstr + src_idx -- pointer into `dst` (overlaps)
+ eq(string.len(dst) + string.len(dst) - src_idx,
+ cimp.xstrlcat(dst_cstr, src_cstr, dsize))
+ return ffi.string(dst_cstr)
+ end
+
+ it('concatenates strings', function()
+ eq('ab', test_xstrlcat('a', 'b', 3))
+ eq('ab', test_xstrlcat('a', 'b', 4096))
+ eq('ABCיהZdefgiיהZ', test_xstrlcat('ABCיהZ', 'defgiיהZ', 4096))
+ eq('b', test_xstrlcat('', 'b', 4096))
+ eq('a', test_xstrlcat('a', '', 4096))
+ end)
+
+ it('concatenates overlapping strings', function()
+ eq('abcabc', test_xstrlcat_overlap('abc', 0, 7))
+ eq('abca', test_xstrlcat_overlap('abc', 0, 5))
+ eq('abcb', test_xstrlcat_overlap('abc', 1, 5))
+ eq('abcc', test_xstrlcat_overlap('abc', 2, 10))
+ eq('abcabc', test_xstrlcat_overlap('abc', 0, 2343))
+ end)
+
+ it('truncates if `dsize` is too small', function()
+ eq('a', test_xstrlcat('a', 'b', 2))
+ eq('', test_xstrlcat('', 'b', 1))
+ eq('ABCיהZd', test_xstrlcat('ABCיהZ', 'defgiיהZ', 10))
+ end)
+
+end)