aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/clipboard/clipboard_provider_spec.lua50
-rw-r--r--test/functional/eval/glob_spec.lua25
-rw-r--r--test/functional/eval/msgpack_functions_spec.lua615
-rw-r--r--test/functional/ex_cmds/grep_spec.lua22
-rw-r--r--test/functional/fixtures/autoload/provider/clipboard.vim12
-rw-r--r--test/functional/helpers.lua1
-rw-r--r--test/functional/legacy/077_mf_hash_grow_spec.lua2
-rw-r--r--test/functional/legacy/mapping_spec.lua13
-rw-r--r--test/functional/provider/define_spec.lua (renamed from test/functional/runtime/autoload/remote/define_spec.lua)0
-rw-r--r--test/functional/provider/python3_spec.lua (renamed from test/functional/runtime/autoload/provider/python3_spec.lua)10
-rw-r--r--test/functional/provider/python_spec.lua (renamed from test/functional/runtime/autoload/provider/python_spec.lua)10
-rw-r--r--test/functional/shell/viml_system_spec.lua4
-rw-r--r--test/functional/ui/screen.lua9
-rw-r--r--test/unit/fixtures/queue.c16
-rw-r--r--test/unit/fixtures/queue.h4
-rw-r--r--test/unit/os/fs_spec.lua70
-rw-r--r--test/unit/queue_spec.lua123
17 files changed, 935 insertions, 51 deletions
diff --git a/test/functional/clipboard/clipboard_provider_spec.lua b/test/functional/clipboard/clipboard_provider_spec.lua
index f6d6188d82..0550d22fa6 100644
--- a/test/functional/clipboard/clipboard_provider_spec.lua
+++ b/test/functional/clipboard/clipboard_provider_spec.lua
@@ -232,12 +232,15 @@ describe('clipboard usage', function()
expect('words')
eq({{'words'}, 'v'}, eval("g:test_clip['*']"))
+ -- "+ shouldn't have changed
+ eq({''}, eval("g:test_clip['+']"))
+
execute("let g:test_clip['*'] = ['linewise stuff','']")
feed('p')
expect([[
words
linewise stuff]])
- end)
+ end)
it('does not clobber "0 when pasting', function()
insert('a line')
@@ -284,6 +287,50 @@ describe('clipboard usage', function()
end)
+ describe('with clipboard=unnamedplus', function()
+ before_each(function()
+ execute('set clipboard=unnamedplus')
+ end)
+
+ it('links the "+ and unnamed registers', function()
+ insert("one two")
+ feed('^"+dwdw"+P')
+ expect('two')
+ eq({{'two'}, 'v'}, eval("g:test_clip['+']"))
+
+ -- "* shouldn't have changed
+ eq({''}, eval("g:test_clip['*']"))
+
+ execute("let g:test_clip['+'] = ['three']")
+ feed('p')
+ expect('twothree')
+ end)
+
+ it('and unnamed, yanks to both', function()
+ execute('set clipboard=unnamedplus,unnamed')
+ insert([[
+ really unnamed
+ text]])
+ feed('ggdd"*p"+p')
+ expect([[
+ text
+ really unnamed
+ really unnamed]])
+ eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['+']"))
+ eq({{'really unnamed', ''}, 'V'}, eval("g:test_clip['*']"))
+
+ -- unnamedplus takes predecence when pasting
+ execute("let g:test_clip['+'] = ['the plus','']")
+ execute("let g:test_clip['*'] = ['the star','']")
+ feed("p")
+ expect([[
+ text
+ really unnamed
+ really unnamed
+ the plus]])
+ end)
+ end)
+
it('supports :put', function()
insert("a line")
execute("let g:test_clip['*'] = ['some text']")
@@ -322,6 +369,7 @@ describe('clipboard usage', function()
[2] = {foreground = Screen.colors.Blue},
[3] = {bold = true, foreground = Screen.colors.SeaGreen}},
{{bold = true, foreground = Screen.colors.Blue}})
+ feed('<cr>') -- clear out of Press ENTER screen
end)
it('can paste "* to the commandline', function()
diff --git a/test/functional/eval/glob_spec.lua b/test/functional/eval/glob_spec.lua
new file mode 100644
index 0000000000..136417249c
--- /dev/null
+++ b/test/functional/eval/glob_spec.lua
@@ -0,0 +1,25 @@
+local helpers = require('test.functional.helpers')
+local clear, execute, eval, eq = helpers.clear, helpers.execute, helpers.eval, helpers.eq
+
+before_each(function()
+ clear()
+ lfs.mkdir('test-glob')
+ execute('cd test-glob')
+end)
+
+after_each(function()
+ lfs.rmdir('test-glob')
+end)
+
+describe('glob()', function()
+ it("glob('.*') returns . and .. ", function()
+ eq({'.', '..'}, eval("glob('.*', 0, 1)"))
+ -- Do it again to verify scandir_next_with_dots() internal state.
+ eq({'.', '..'}, eval("glob('.*', 0, 1)"))
+ end)
+ it("glob('*') returns an empty list ", function()
+ eq({}, eval("glob('*', 0, 1)"))
+ -- Do it again to verify scandir_next_with_dots() internal state.
+ eq({}, eval("glob('*', 0, 1)"))
+ end)
+end)
diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua
new file mode 100644
index 0000000000..8ca2cca32c
--- /dev/null
+++ b/test/functional/eval/msgpack_functions_spec.lua
@@ -0,0 +1,615 @@
+local helpers = require('test.functional.helpers')
+local clear, feed, execute = helpers.clear, helpers.feed, helpers.execute
+local eval, eq, neq = helpers.eval, helpers.eq, helpers.neq
+local execute, source = helpers.execute, helpers.source
+local nvim = helpers.nvim
+describe('msgpack*() functions', function()
+ before_each(function()
+ clear()
+ end)
+ local obj_test = function(msg, obj)
+ it(msg, function()
+ nvim('set_var', 'obj', obj)
+ eq(obj, eval('msgpackparse(msgpackdump(g:obj))'))
+ end)
+ end
+ -- Regression test: msgpack_list_write was failing to write buffer with zero
+ -- length.
+ obj_test('are able to dump and restore {"file": ""}', {{file=''}})
+ -- Regression test: msgpack_list_write was failing to write buffer with NL at
+ -- the end.
+ obj_test('are able to dump and restore {0, "echo mpack"}', {{0, 'echo mpack'}})
+ obj_test('are able to dump and restore "Test\\n"', {'Test\n'})
+ -- Regression test: msgpack_list_write was failing to write buffer with NL
+ -- inside.
+ obj_test('are able to dump and restore "Test\\nTest 2"', {'Test\nTest 2'})
+ -- Test that big objects (requirement: dump to something that is bigger then
+ -- IOSIZE) are also fine. This particular object is obtained by concatenating
+ -- 5 identical shada files.
+ local big_obj = {
+ 1, 1436711454, 78, {
+ encoding="utf-8",
+ max_kbyte=10,
+ pid=19269,
+ version="NVIM 0.0.0-alpha+201507121634"
+ },
+ 8, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 8, 1436711391, 8, { file="" },
+ 4, 1436700940, 30, { 0, "call mkdir('/tmp/tty/tty')" },
+ 4, 1436701355, 35, { 0, "call mkdir('/tmp/tty/tty', 'p')" },
+ 4, 1436701368, 24, { 0, "call mkdir('/', 'p')" },
+ 4, 1436701375, 26, { 0, "call mkdir('/tty/tty')" },
+ 4, 1436701383, 30, { 0, "call mkdir('/tty/tty/tty')" },
+ 4, 1436701407, 35, { 0, "call mkdir('/usr/tty/tty', 'p')" },
+ 4, 1436701666, 35, { 0, "call mkdir('/tty/tty/tty', 'p')" },
+ 4, 1436708101, 25, { 0, "echo msgpackdump([1])" },
+ 4, 1436708966, 6, { 0, "cq" },
+ 4, 1436709606, 25, { 0, "echo msgpackdump([5])" },
+ 4, 1436709610, 26, { 0, "echo msgpackdump([10])" },
+ 4, 1436709615, 31, { 0, "echo msgpackdump([5, 5, 5])" },
+ 4, 1436709618, 35, { 0, "echo msgpackdump([5, 5, 5, 10])" },
+ 4, 1436709634, 57, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1}]])"
+ },
+ 4, 1436709651, 67, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}]])"
+ },
+ 4, 1436709660, 70, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}], 0])"
+ },
+ 4, 1436710095, 29, { 0, "echo msgpackparse([\"\\n\"])" },
+ 4, 1436710100, 28, { 0, "echo msgpackparse([\"j\"])" },
+ 4, 1436710109, 31, { 0, "echo msgpackparse([\"\", \"\"])" },
+ 4, 1436710424, 33, { 0, "echo msgpackparse([\"\", \"\\n\"])" },
+ 4, 1436710428, 32, { 0, "echo msgpackparse([\"\", \"j\"])" },
+ 4, 1436711142, 14, { 0, "echo mpack" },
+ 4, 1436711196, 45, { 0, "let lengths = map(mpack[:], 'len(v:val)')" },
+ 4, 1436711206, 16, { 0, "echo lengths" },
+ 4, 1436711244, 92, {
+ 0,
+ ("let sum = len(lengths) - 1 | call map(copy(lengths), "
+ .. "'extend(g:, {\"sum\": sum + v:val})')")
+ },
+ 4, 1436711245, 12, { 0, "echo sum" },
+ 4, 1436711398, 10, { 0, "echo s" },
+ 4, 1436711404, 41, { 0, "let mpack = readfile('/tmp/foo', 'b')" },
+ 4, 1436711408, 41, { 0, "let shada_objects=msgpackparse(mpack)" },
+ 4, 1436711415, 22, { 0, "echo shada_objects" },
+ 4, 1436711451, 30, { 0, "e ~/.nvim/shada/main.shada" },
+ 4, 1436711454, 6, { 0, "qa" },
+ 4, 1436711442, 9, { 1, "test", 47 },
+ 4, 1436711443, 15, { 1, "aontsuesan", 47 },
+ 2, 1436711443, 38, { hlsearch=1, pat="aontsuesan", smartcase=1 },
+ 2, 0, 31, { islast=0, pat="", smartcase=1, sub=1 },
+ 3, 0, 3, { "" },
+ 10, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 1, 1436711454, 78, {
+ encoding="utf-8",
+ max_kbyte=10,
+ pid=19269,
+ version="NVIM 0.0.0-alpha+201507121634"
+ },
+ 8, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 8, 1436711391, 8, { file="" },
+ 4, 1436700940, 30, { 0, "call mkdir('/tmp/tty/tty')" },
+ 4, 1436701355, 35, { 0, "call mkdir('/tmp/tty/tty', 'p')" },
+ 4, 1436701368, 24, { 0, "call mkdir('/', 'p')" },
+ 4, 1436701375, 26, { 0, "call mkdir('/tty/tty')" },
+ 4, 1436701383, 30, { 0, "call mkdir('/tty/tty/tty')" },
+ 4, 1436701407, 35, { 0, "call mkdir('/usr/tty/tty', 'p')" },
+ 4, 1436701666, 35, { 0, "call mkdir('/tty/tty/tty', 'p')" },
+ 4, 1436708101, 25, { 0, "echo msgpackdump([1])" },
+ 4, 1436708966, 6, { 0, "cq" },
+ 4, 1436709606, 25, { 0, "echo msgpackdump([5])" },
+ 4, 1436709610, 26, { 0, "echo msgpackdump([10])" },
+ 4, 1436709615, 31, { 0, "echo msgpackdump([5, 5, 5])" },
+ 4, 1436709618, 35, { 0, "echo msgpackdump([5, 5, 5, 10])" },
+ 4, 1436709634, 57, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1}]])"
+ },
+ 4, 1436709651, 67, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}]])"
+ },
+ 4, 1436709660, 70, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}], 0])"
+ },
+ 4, 1436710095, 29, { 0, "echo msgpackparse([\"\\n\"])" },
+ 4, 1436710100, 28, { 0, "echo msgpackparse([\"j\"])" },
+ 4, 1436710109, 31, { 0, "echo msgpackparse([\"\", \"\"])" },
+ 4, 1436710424, 33, { 0, "echo msgpackparse([\"\", \"\\n\"])" },
+ 4, 1436710428, 32, { 0, "echo msgpackparse([\"\", \"j\"])" },
+ 4, 1436711142, 14, { 0, "echo mpack" },
+ 4, 1436711196, 45, { 0, "let lengths = map(mpack[:], 'len(v:val)')" },
+ 4, 1436711206, 16, { 0, "echo lengths" },
+ 4, 1436711244, 92, {
+ 0,
+ ("let sum = len(lengths) - 1 | call map(copy(lengths), "
+ .. "'extend(g:, {\"sum\": sum + v:val})')")
+ },
+ 4, 1436711245, 12, { 0, "echo sum" },
+ 4, 1436711398, 10, { 0, "echo s" },
+ 4, 1436711404, 41, { 0, "let mpack = readfile('/tmp/foo', 'b')" },
+ 4, 1436711408, 41, { 0, "let shada_objects=msgpackparse(mpack)" },
+ 4, 1436711415, 22, { 0, "echo shada_objects" },
+ 4, 1436711451, 30, { 0, "e ~/.nvim/shada/main.shada" },
+ 4, 1436711454, 6, { 0, "qa" },
+ 4, 1436711442, 9, { 1, "test", 47 },
+ 4, 1436711443, 15, { 1, "aontsuesan", 47 },
+ 2, 1436711443, 38, { hlsearch=1, pat="aontsuesan", smartcase=1 },
+ 2, 0, 31, { islast=0, pat="", smartcase=1, sub=1 },
+ 3, 0, 3, { "" },
+ 10, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 1, 1436711454, 78, {
+ encoding="utf-8",
+ max_kbyte=10,
+ pid=19269,
+ version="NVIM 0.0.0-alpha+201507121634"
+ },
+ 8, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 8, 1436711391, 8, { file="" },
+ 4, 1436700940, 30, { 0, "call mkdir('/tmp/tty/tty')" },
+ 4, 1436701355, 35, { 0, "call mkdir('/tmp/tty/tty', 'p')" },
+ 4, 1436701368, 24, { 0, "call mkdir('/', 'p')" },
+ 4, 1436701375, 26, { 0, "call mkdir('/tty/tty')" },
+ 4, 1436701383, 30, { 0, "call mkdir('/tty/tty/tty')" },
+ 4, 1436701407, 35, { 0, "call mkdir('/usr/tty/tty', 'p')" },
+ 4, 1436701666, 35, { 0, "call mkdir('/tty/tty/tty', 'p')" },
+ 4, 1436708101, 25, { 0, "echo msgpackdump([1])" },
+ 4, 1436708966, 6, { 0, "cq" },
+ 4, 1436709606, 25, { 0, "echo msgpackdump([5])" },
+ 4, 1436709610, 26, { 0, "echo msgpackdump([10])" },
+ 4, 1436709615, 31, { 0, "echo msgpackdump([5, 5, 5])" },
+ 4, 1436709618, 35, { 0, "echo msgpackdump([5, 5, 5, 10])" },
+ 4, 1436709634, 57, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1}]])"
+ },
+ 4, 1436709651, 67, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}]])"
+ },
+ 4, 1436709660, 70, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}], 0])"
+ },
+ 4, 1436710095, 29, { 0, "echo msgpackparse([\"\\n\"])" },
+ 4, 1436710100, 28, { 0, "echo msgpackparse([\"j\"])" },
+ 4, 1436710109, 31, { 0, "echo msgpackparse([\"\", \"\"])" },
+ 4, 1436710424, 33, { 0, "echo msgpackparse([\"\", \"\\n\"])" },
+ 4, 1436710428, 32, { 0, "echo msgpackparse([\"\", \"j\"])" },
+ 4, 1436711142, 14, { 0, "echo mpack" },
+ 4, 1436711196, 45, { 0, "let lengths = map(mpack[:], 'len(v:val)')" },
+ 4, 1436711206, 16, { 0, "echo lengths" },
+ 4, 1436711244, 92, {
+ 0,
+ ("let sum = len(lengths) - 1 | call map(copy(lengths), "
+ .. "'extend(g:, {\"sum\": sum + v:val})')")
+ },
+ 4, 1436711245, 12, { 0, "echo sum" },
+ 4, 1436711398, 10, { 0, "echo s" },
+ 4, 1436711404, 41, { 0, "let mpack = readfile('/tmp/foo', 'b')" },
+ 4, 1436711408, 41, { 0, "let shada_objects=msgpackparse(mpack)" },
+ 4, 1436711415, 22, { 0, "echo shada_objects" },
+ 4, 1436711451, 30, { 0, "e ~/.nvim/shada/main.shada" },
+ 4, 1436711454, 6, { 0, "qa" },
+ 4, 1436711442, 9, { 1, "test", 47 },
+ 4, 1436711443, 15, { 1, "aontsuesan", 47 },
+ 2, 1436711443, 38, { hlsearch=1, pat="aontsuesan", smartcase=1 },
+ 2, 0, 31, { islast=0, pat="", smartcase=1, sub=1 },
+ 3, 0, 3, { "" },
+ 10, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 1, 1436711454, 78, {
+ encoding="utf-8",
+ max_kbyte=10,
+ pid=19269,
+ version="NVIM 0.0.0-alpha+201507121634"
+ },
+ 8, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 8, 1436711391, 8, { file="" },
+ 4, 1436700940, 30, { 0, "call mkdir('/tmp/tty/tty')" },
+ 4, 1436701355, 35, { 0, "call mkdir('/tmp/tty/tty', 'p')" },
+ 4, 1436701368, 24, { 0, "call mkdir('/', 'p')" },
+ 4, 1436701375, 26, { 0, "call mkdir('/tty/tty')" },
+ 4, 1436701383, 30, { 0, "call mkdir('/tty/tty/tty')" },
+ 4, 1436701407, 35, { 0, "call mkdir('/usr/tty/tty', 'p')" },
+ 4, 1436701666, 35, { 0, "call mkdir('/tty/tty/tty', 'p')" },
+ 4, 1436708101, 25, { 0, "echo msgpackdump([1])" },
+ 4, 1436708966, 6, { 0, "cq" },
+ 4, 1436709606, 25, { 0, "echo msgpackdump([5])" },
+ 4, 1436709610, 26, { 0, "echo msgpackdump([10])" },
+ 4, 1436709615, 31, { 0, "echo msgpackdump([5, 5, 5])" },
+ 4, 1436709618, 35, { 0, "echo msgpackdump([5, 5, 5, 10])" },
+ 4, 1436709634, 57, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1}]])"
+ },
+ 4, 1436709651, 67, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}]])"
+ },
+ 4, 1436709660, 70, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}], 0])"
+ },
+ 4, 1436710095, 29, { 0, "echo msgpackparse([\"\\n\"])" },
+ 4, 1436710100, 28, { 0, "echo msgpackparse([\"j\"])" },
+ 4, 1436710109, 31, { 0, "echo msgpackparse([\"\", \"\"])" },
+ 4, 1436710424, 33, { 0, "echo msgpackparse([\"\", \"\\n\"])" },
+ 4, 1436710428, 32, { 0, "echo msgpackparse([\"\", \"j\"])" },
+ 4, 1436711142, 14, { 0, "echo mpack" },
+ 4, 1436711196, 45, { 0, "let lengths = map(mpack[:], 'len(v:val)')" },
+ 4, 1436711206, 16, { 0, "echo lengths" },
+ 4, 1436711244, 92, {
+ 0,
+ ("let sum = len(lengths) - 1 | call map(copy(lengths), "
+ .. "'extend(g:, {\"sum\": sum + v:val})')")
+ },
+ 4, 1436711245, 12, { 0, "echo sum" },
+ 4, 1436711398, 10, { 0, "echo s" },
+ 4, 1436711404, 41, { 0, "let mpack = readfile('/tmp/foo', 'b')" },
+ 4, 1436711408, 41, { 0, "let shada_objects=msgpackparse(mpack)" },
+ 4, 1436711415, 22, { 0, "echo shada_objects" },
+ 4, 1436711451, 30, { 0, "e ~/.nvim/shada/main.shada" },
+ 4, 1436711454, 6, { 0, "qa" },
+ 4, 1436711442, 9, { 1, "test", 47 },
+ 4, 1436711443, 15, { 1, "aontsuesan", 47 },
+ 2, 1436711443, 38, { hlsearch=1, pat="aontsuesan", smartcase=1 },
+ 2, 0, 31, { islast=0, pat="", smartcase=1, sub=1 },
+ 3, 0, 3, { "" },
+ 10, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 1, 1436711454, 78, {
+ encoding="utf-8",
+ max_kbyte=10,
+ pid=19269,
+ version="NVIM 0.0.0-alpha+201507121634"
+ },
+ 8, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" },
+ 8, 1436711391, 8, { file="" },
+ 4, 1436700940, 30, { 0, "call mkdir('/tmp/tty/tty')" },
+ 4, 1436701355, 35, { 0, "call mkdir('/tmp/tty/tty', 'p')" },
+ 4, 1436701368, 24, { 0, "call mkdir('/', 'p')" },
+ 4, 1436701375, 26, { 0, "call mkdir('/tty/tty')" },
+ 4, 1436701383, 30, { 0, "call mkdir('/tty/tty/tty')" },
+ 4, 1436701407, 35, { 0, "call mkdir('/usr/tty/tty', 'p')" },
+ 4, 1436701666, 35, { 0, "call mkdir('/tty/tty/tty', 'p')" },
+ 4, 1436708101, 25, { 0, "echo msgpackdump([1])" },
+ 4, 1436708966, 6, { 0, "cq" },
+ 4, 1436709606, 25, { 0, "echo msgpackdump([5])" },
+ 4, 1436709610, 26, { 0, "echo msgpackdump([10])" },
+ 4, 1436709615, 31, { 0, "echo msgpackdump([5, 5, 5])" },
+ 4, 1436709618, 35, { 0, "echo msgpackdump([5, 5, 5, 10])" },
+ 4, 1436709634, 57, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1}]])"
+ },
+ 4, 1436709651, 67, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}]])"
+ },
+ 4, 1436709660, 70, {
+ 0,
+ "echo msgpackdump([5, 5, 5, 10, [10, 20, {\"abc\": 1, \"def\": 0}], 0])"
+ },
+ 4, 1436710095, 29, { 0, "echo msgpackparse([\"\\n\"])" },
+ 4, 1436710100, 28, { 0, "echo msgpackparse([\"j\"])" },
+ 4, 1436710109, 31, { 0, "echo msgpackparse([\"\", \"\"])" },
+ 4, 1436710424, 33, { 0, "echo msgpackparse([\"\", \"\\n\"])" },
+ 4, 1436710428, 32, { 0, "echo msgpackparse([\"\", \"j\"])" },
+ 4, 1436711142, 14, { 0, "echo mpack" },
+ 4, 1436711196, 45, { 0, "let lengths = map(mpack[:], 'len(v:val)')" },
+ 4, 1436711206, 16, { 0, "echo lengths" },
+ 4, 1436711244, 92, {
+ 0,
+ ("let sum = len(lengths) - 1 | call map(copy(lengths), "
+ .. "'extend(g:, {\"sum\": sum + v:val})')")
+ },
+ 4, 1436711245, 12, { 0, "echo sum" },
+ 4, 1436711398, 10, { 0, "echo s" },
+ 4, 1436711404, 41, { 0, "let mpack = readfile('/tmp/foo', 'b')" },
+ 4, 1436711408, 41, { 0, "let shada_objects=msgpackparse(mpack)" },
+ 4, 1436711415, 22, { 0, "echo shada_objects" },
+ 4, 1436711451, 30, { 0, "e ~/.nvim/shada/main.shada" },
+ 4, 1436711454, 6, { 0, "qa" },
+ 4, 1436711442, 9, { 1, "test", 47 },
+ 4, 1436711443, 15, { 1, "aontsuesan", 47 },
+ 2, 1436711443, 38, { hlsearch=1, pat="aontsuesan", smartcase=1 },
+ 2, 0, 31, { islast=0, pat="", smartcase=1, sub=1 },
+ 3, 0, 3, { "" },
+ 10, 1436711451, 40, { file="/home/zyx/.nvim/shada/main.shada" }
+ }
+ obj_test('are able to dump and restore rather big object', big_obj)
+
+ obj_test('are able to dump and restore floating-point value', {0.125})
+
+ it('restore nil as special dict', function()
+ execute('let dumped = ["\\xC0"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL=0}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.nil'))
+ end)
+
+ it('restore boolean false as zero', function()
+ execute('let dumped = ["\\xC2"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL=0}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean'))
+ end)
+
+ it('restore boolean true as one', function()
+ execute('let dumped = ["\\xC3"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL=1}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean'))
+ end)
+
+ it('dump string as BIN 8', function()
+ nvim('set_var', 'obj', {'Test'})
+ eq({"\196\004Test"}, eval('msgpackdump(obj)'))
+ end)
+
+ it('restore FIXSTR as special dict', function()
+ execute('let dumped = ["\\xa2ab"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL={'ab'}}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.string'))
+ end)
+
+ it('restore BIN 8 as string', function()
+ execute('let dumped = ["\\xC4\\x02ab"]')
+ eq({'ab'}, eval('msgpackparse(dumped)'))
+ end)
+
+ it('restore FIXEXT1 as special dictionary', function()
+ execute('let dumped = ["\\xD4\\x10", ""]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL={0x10, {"", ""}}}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.ext'))
+ end)
+
+ it('restore MAP with BIN key as special dictionary', function()
+ execute('let dumped = ["\\x81\\xC4\\x01a\\xC4\\n"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL={{'a', ''}}}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
+ end)
+
+ it('restore MAP with duplicate STR keys as special dictionary', function()
+ execute('let dumped = ["\\x82\\xA1a\\xC4\\n\\xA1a\\xC4\\n"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL={{{_TYPE={}, _VAL={'a'}}, ''},
+ {{_TYPE={}, _VAL={'a'}}, ''}}}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
+ eq(1, eval('g:parsed[0]._VAL[0][0]._TYPE is v:msgpack_types.string'))
+ eq(1, eval('g:parsed[0]._VAL[1][0]._TYPE is v:msgpack_types.string'))
+ end)
+
+ it('restore MAP with MAP key as special dictionary', function()
+ execute('let dumped = ["\\x81\\x80\\xC4\\n"]')
+ execute('let parsed = msgpackparse(dumped)')
+ eq({{_TYPE={}, _VAL={{{}, ''}}}}, eval('parsed'))
+ eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.map'))
+ end)
+
+ it('can restore and dump UINT64_MAX', function()
+ execute('let dumped = ["\\xCF" . repeat("\\xFF", 8)]')
+ execute('let parsed = msgpackparse(dumped)')
+ execute('let dumped2 = msgpackdump(parsed)')
+ eq(1, eval('type(parsed[0]) == type(0) ' ..
+ '|| parsed[0]._TYPE is v:msgpack_types.integer'))
+ if eval('type(parsed[0]) == type(0)') == 1 then
+ eq(1, eval('0xFFFFFFFFFFFFFFFF == parsed[0]'))
+ else
+ eq({_TYPE={}, _VAL={1, 3, 0x7FFFFFFF, 0x7FFFFFFF}}, eval('parsed[0]'))
+ end
+ eq(1, eval('dumped ==# dumped2'))
+ end)
+
+ it('can restore and dump INT64_MIN', function()
+ execute('let dumped = ["\\xD3\\x80" . repeat("\\n", 7)]')
+ execute('let parsed = msgpackparse(dumped)')
+ execute('let dumped2 = msgpackdump(parsed)')
+ eq(1, eval('type(parsed[0]) == type(0) ' ..
+ '|| parsed[0]._TYPE is v:msgpack_types.integer'))
+ if eval('type(parsed[0]) == type(0)') == 1 then
+ eq(1, eval('-0x8000000000000000 == parsed[0]'))
+ else
+ eq({_TYPE={}, _VAL={-1, 2, 0, 0}}, eval('parsed[0]'))
+ end
+ eq(1, eval('dumped ==# dumped2'))
+ end)
+
+ it('can restore and dump BIN string with zero byte', function()
+ execute('let dumped = ["\\xC4\\x01\\n"]')
+ execute('let parsed = msgpackparse(dumped)')
+ execute('let dumped2 = msgpackdump(parsed)')
+ eq({{_TYPE={}, _VAL={'\n'}}}, eval('parsed'))
+ eq(1, eval('parsed[0]._TYPE is v:msgpack_types.binary'))
+ eq(1, eval('dumped ==# dumped2'))
+ end)
+
+ it('can restore and dump STR string with zero byte', function()
+ execute('let dumped = ["\\xA1\\n"]')
+ execute('let parsed = msgpackparse(dumped)')
+ execute('let dumped2 = msgpackdump(parsed)')
+ eq({{_TYPE={}, _VAL={'\n'}}}, eval('parsed'))
+ eq(1, eval('parsed[0]._TYPE is v:msgpack_types.string'))
+ eq(1, eval('dumped ==# dumped2'))
+ end)
+
+ it('can restore and dump BIN string with NL', function()
+ execute('let dumped = ["\\xC4\\x01", ""]')
+ execute('let parsed = msgpackparse(dumped)')
+ execute('let dumped2 = msgpackdump(parsed)')
+ eq({"\n"}, eval('parsed'))
+ eq(1, eval('dumped ==# dumped2'))
+ end)
+
+ it('can dump generic mapping with generic mapping keys and values', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ execute('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ execute('let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []}')
+ execute('call add(todump._VAL, [todumpv1, todumpv2])')
+ eq({'\129\128\128'}, eval('msgpackdump([todump])'))
+ end)
+
+ it('can dump generic mapping with ext', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
+ eq({'\212\005', ''}, eval('msgpackdump([todump])'))
+ end)
+
+ it('can dump generic mapping with array', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]}')
+ eq({'\146\005\145\196\n'}, eval('msgpackdump([todump])'))
+ end)
+
+ it('can dump generic mapping with UINT64_MAX', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.integer}')
+ execute('let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF]')
+ eq({'\207\255\255\255\255\255\255\255\255'}, eval('msgpackdump([todump])'))
+ end)
+
+ it('can dump generic mapping with INT64_MIN', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.integer}')
+ execute('let todump._VAL = [-1, 2, 0, 0]')
+ eq({'\211\128\n\n\n\n\n\n\n'}, eval('msgpackdump([todump])'))
+ end)
+
+ it('dump and restore generic mapping with floating-point value', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125}')
+ eq({0.125}, eval('msgpackparse(msgpackdump([todump]))'))
+ end)
+
+ it('fails to dump a function reference', function()
+ execute('let Todump = function("tr")')
+ execute([[
+ try
+ let dumped = msgpackdump([Todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: attempt to dump function reference',
+ eval('exception'))
+ end)
+
+ it('fails to dump a function reference in a list', function()
+ execute('let todump = [function("tr")]')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: attempt to dump function reference',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive list', function()
+ execute('let todump = [[[]]]')
+ execute('call add(todump[0][0], todump)')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive dict', function()
+ execute('let todump = {"d": {"d": {}}}')
+ execute('call extend(todump.d.d, {"d": todump})')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive list in a special dict', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ execute('call add(todump._VAL, todump)')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive (key) map in a special dict', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ execute('call add(todump._VAL, [todump, 0])')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive (val) map in a special dict', function()
+ execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ execute('call add(todump._VAL, [0, todump])')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('fails to dump a recursive (val) special list in a special dict',
+ function()
+ execute('let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []}')
+ execute('call add(todump._VAL, [0, todump._VAL])')
+ execute([[
+ try
+ let dumped = msgpackdump([todump])
+ let exception = 0
+ catch
+ let exception = v:exception
+ endtry
+ ]])
+ eq('Vim(let):E475: Invalid argument: container references itself',
+ eval('exception'))
+ end)
+
+ it('msgpackparse(systemlist(...)) does not segfault. #3135', function()
+ local cmd = "msgpackparse(systemlist('"
+ ..helpers.nvim_prog.." --api-info'))['_TYPE']['_VAL'][0][0]"
+ local api_info = eval(cmd)
+ api_info = eval(cmd) -- do it again (try to force segfault)
+ api_info = eval(cmd) -- do it again
+ eq('functions', api_info)
+ end)
+end)
diff --git a/test/functional/ex_cmds/grep_spec.lua b/test/functional/ex_cmds/grep_spec.lua
new file mode 100644
index 0000000000..9c792099c1
--- /dev/null
+++ b/test/functional/ex_cmds/grep_spec.lua
@@ -0,0 +1,22 @@
+local helpers = require('test.functional.helpers')
+local clear, execute, nvim, feed, eq, ok, eval =
+ helpers.clear, helpers.execute, helpers.nvim, helpers.feed,
+ helpers.eq, helpers.ok, helpers.eval
+
+describe(':grep', function()
+ before_each(clear)
+
+ it('does not hang on large input #2983', function()
+ if eval("executable('grep')") == 0 then
+ pending('missing "grep" command')
+ return
+ end
+
+ execute([[set grepprg=grep\ -r]])
+ -- Change to test directory so that the test does not run too long.
+ execute('cd test')
+ execute('grep a **/*')
+ feed('<cr>') -- Press ENTER
+ ok(eval('len(getqflist())') > 9000) -- IT'S OVER 9000!!1
+ end)
+end)
diff --git a/test/functional/fixtures/autoload/provider/clipboard.vim b/test/functional/fixtures/autoload/provider/clipboard.vim
index a28484169a..0935ea45ff 100644
--- a/test/functional/fixtures/autoload/provider/clipboard.vim
+++ b/test/functional/fixtures/autoload/provider/clipboard.vim
@@ -9,16 +9,22 @@ function! s:methods.get(reg)
if g:cliperror
return 0
end
+ let reg = a:reg == '"' ? '+' : a:reg
if g:cliplossy
" behave like pure text clipboard
- return g:test_clip[a:reg][0]
+ return g:test_clip[reg][0]
else
- "behave like VIMENC clipboard
- return g:test_clip[a:reg]
+ " behave like VIMENC clipboard
+ return g:test_clip[reg]
end
endfunction
function! s:methods.set(lines, regtype, reg)
+ if a:reg == '"'
+ call s:methods.set(a:lines,a:regtype,'+')
+ call s:methods.set(a:lines,a:regtype,'*')
+ return 0
+ end
let g:test_clip[a:reg] = [a:lines, a:regtype]
endfunction
diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua
index d5c22c6f1c..1159707282 100644
--- a/test/functional/helpers.lua
+++ b/test/functional/helpers.lua
@@ -6,7 +6,6 @@ local AsyncSession = require('nvim.async_session')
local Session = require('nvim.session')
local nvim_prog = os.getenv('NVIM_PROG') or 'build/bin/nvim'
---- FIXME: 'autoindent' messes up the insert() function
local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N',
'--cmd', 'set shortmess+=I background=light noswapfile noautoindent',
'--embed'}
diff --git a/test/functional/legacy/077_mf_hash_grow_spec.lua b/test/functional/legacy/077_mf_hash_grow_spec.lua
index 01d916ef04..825f08e968 100644
--- a/test/functional/legacy/077_mf_hash_grow_spec.lua
+++ b/test/functional/legacy/077_mf_hash_grow_spec.lua
@@ -15,7 +15,7 @@ describe('mf_hash_grow()', function()
-- Check to see if cksum exists, otherwise skip the test
if os.execute('which cksum 2>&1 > /dev/null') ~= 0 then
- pending("was not tested because cksum was not found")
+ pending('was not tested because cksum was not found', function() end)
else
it('is working', function()
execute('set fileformat=unix undolevels=-1')
diff --git a/test/functional/legacy/mapping_spec.lua b/test/functional/legacy/mapping_spec.lua
index c387d7484c..0843506827 100644
--- a/test/functional/legacy/mapping_spec.lua
+++ b/test/functional/legacy/mapping_spec.lua
@@ -23,16 +23,27 @@ describe('mapping', function()
execute('set langmap=+{ langnoremap')
feed('o+<esc>')
- -- expr mapping with langmap.
+ -- Insert mode expr mapping with langmap.
execute('inoremap <expr> { "FAIL_iexplangmap"')
feed('o+<esc>')
+ -- langmap should not get remapped in cmdline mode.
+ execute('cnoremap { FAIL_clangmap')
+ feed('o+<esc>')
+ execute('cunmap {')
+
+ -- cmdline mode expr mapping with langmap.
+ execute('cnoremap <expr> { "FAIL_cexplangmap"')
+ feed('o+<esc>')
+ execute('cunmap {')
-- Assert buffer contents.
expect([[
test starts here:
vim
+
+ +
+ +
+]])
end)
end)
diff --git a/test/functional/runtime/autoload/remote/define_spec.lua b/test/functional/provider/define_spec.lua
index 9b97ed84d9..9b97ed84d9 100644
--- a/test/functional/runtime/autoload/remote/define_spec.lua
+++ b/test/functional/provider/define_spec.lua
diff --git a/test/functional/runtime/autoload/provider/python3_spec.lua b/test/functional/provider/python3_spec.lua
index 43889b7b2a..5be5390370 100644
--- a/test/functional/runtime/autoload/provider/python3_spec.lua
+++ b/test/functional/provider/python3_spec.lua
@@ -1,19 +1,19 @@
do
- local proc =
- io.popen([[python3 -c 'import neovim, sys; sys.stdout.write("ok")' 2> /dev/null]])
+ local proc = io.popen(
+ [[python3 -c 'import neovim, sys; sys.stdout.write("ok")' 2> /dev/null]])
if proc:read() ~= 'ok' then
- -- Don't run these tests if python3 is not available
+ pending(
+ 'python3 (or the python3 neovim module) is broken or missing',
+ function() end)
return
end
end
-
local helpers = require('test.functional.helpers')
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect, write_file = helpers.expect, helpers.write_file
-
describe('python3 commands and functions', function()
before_each(function()
clear()
diff --git a/test/functional/runtime/autoload/provider/python_spec.lua b/test/functional/provider/python_spec.lua
index e71a7a4309..ec1a853546 100644
--- a/test/functional/runtime/autoload/provider/python_spec.lua
+++ b/test/functional/provider/python_spec.lua
@@ -1,19 +1,19 @@
do
- local proc =
- io.popen([[python -c 'import neovim, sys; sys.stdout.write("ok")' 2> /dev/null]])
+ local proc = io.popen(
+ [[python -c 'import neovim, sys; sys.stdout.write("ok")' 2> /dev/null]])
if proc:read() ~= 'ok' then
- -- Don't run these tests if python is not available
+ pending(
+ 'python (or the python neovim module) is broken or missing',
+ function() end)
return
end
end
-
local helpers = require('test.functional.helpers')
local eval, command, feed = helpers.eval, helpers.command, helpers.feed
local eq, clear, insert = helpers.eq, helpers.clear, helpers.insert
local expect, write_file = helpers.expect, helpers.write_file
-
describe('python commands and functions', function()
before_each(function()
clear()
diff --git a/test/functional/shell/viml_system_spec.lua b/test/functional/shell/viml_system_spec.lua
index 6e10715612..4985c24aec 100644
--- a/test/functional/shell/viml_system_spec.lua
+++ b/test/functional/shell/viml_system_spec.lua
@@ -186,7 +186,7 @@ describe('system()', function()
describe("with a program that doesn't close stdout", function()
if not xclip then
- pending('skipped (missing xclip)')
+ pending('skipped (missing xclip)', function() end)
else
it('will exit properly after passing input', function()
eq('', eval([[system('xclip -i -selection clipboard', 'clip-data')]]))
@@ -365,7 +365,7 @@ describe('systemlist()', function()
describe("with a program that doesn't close stdout", function()
if not xclip then
- pending('skipped (missing xclip)')
+ pending('skipped (missing xclip)', function() end)
else
it('will exit properly after passing input', function()
eq({}, eval(
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 60198bb008..1d616ed853 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -340,12 +340,9 @@ function Screen:_handle_mouse_off()
self._mouse_enabled = false
end
-function Screen:_handle_insert_mode()
- self._mode = 'insert'
-end
-
-function Screen:_handle_normal_mode()
- self._mode = 'normal'
+function Screen:_handle_mode_change(mode)
+ assert(mode == 'insert' or mode == 'replace' or mode == 'normal')
+ self._mode = mode
end
function Screen:_handle_set_scroll_region(top, bot, left, right)
diff --git a/test/unit/fixtures/queue.c b/test/unit/fixtures/queue.c
new file mode 100644
index 0000000000..bbb6274b21
--- /dev/null
+++ b/test/unit/fixtures/queue.c
@@ -0,0 +1,16 @@
+#include <string.h>
+#include <stdlib.h>
+#include "nvim/event/queue.h"
+#include "queue.h"
+
+
+void ut_queue_put(Queue *queue, const char *str)
+{
+ queue_put(queue, NULL, 1, str);
+}
+
+const char *ut_queue_get(Queue *queue)
+{
+ Event event = queue_get(queue);
+ return event.argv[0];
+}
diff --git a/test/unit/fixtures/queue.h b/test/unit/fixtures/queue.h
new file mode 100644
index 0000000000..ae949c9f29
--- /dev/null
+++ b/test/unit/fixtures/queue.h
@@ -0,0 +1,4 @@
+#include "nvim/event/queue.h"
+
+void ut_queue_put(Queue *queue, const char *str);
+const char *ut_queue_get(Queue *queue);
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 20aca9109e..28e831229f 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -32,6 +32,14 @@ local directory = nil
local absolute_executable = nil
local executable_name = nil
+local function set_bit(number, to_set)
+ return bit.bor(number, to_set)
+end
+
+local function unset_bit(number, to_unset)
+ return bit.band(number, (bit.bnot(to_unset)))
+end
+
local function assert_file_exists(filepath)
neq(nil, lfs.attributes(filepath))
end
@@ -40,11 +48,24 @@ local function assert_file_does_not_exist(filepath)
eq(nil, lfs.attributes(filepath))
end
+local function os_setperm(filename, perm)
+ return fs.os_setperm((to_cstr(filename)), perm)
+end
+
+local function os_getperm(filename)
+ local perm = fs.os_getperm((to_cstr(filename)))
+ return tonumber(perm)
+end
+
describe('fs function', function()
+ local orig_test_file_perm
setup(function()
lfs.mkdir('unit-test-directory');
+
io.open('unit-test-directory/test.file', 'w').close()
+ orig_test_file_perm = os_getperm('unit-test-directory/test.file')
+
io.open('unit-test-directory/test_2.file', 'w').close()
lfs.link('test.file', 'unit-test-directory/test_link.file', true)
-- Since the tests are executed, they are called by an executable. We use
@@ -188,6 +209,10 @@ describe('fs function', function()
end)
describe('file permissions', function()
+ before_each(function()
+ os_setperm('unit-test-directory/test.file', orig_test_file_perm)
+ end)
+
local function os_getperm(filename)
local perm = fs.os_getperm((to_cstr(filename)))
return tonumber(perm)
@@ -204,8 +229,8 @@ describe('fs function', function()
return res
end
- local function os_file_is_readonly(filename)
- return fs.os_file_is_readonly((to_cstr(filename)))
+ local function os_file_is_readable(filename)
+ return fs.os_file_is_readable((to_cstr(filename)))
end
local function os_file_is_writable(filename)
@@ -216,14 +241,6 @@ describe('fs function', function()
return 0 ~= (bit.band(number, check_bit))
end
- local function set_bit(number, to_set)
- return bit.bor(number, to_set)
- end
-
- local function unset_bit(number, to_unset)
- return bit.band(number, (bit.bnot(to_unset)))
- end
-
describe('os_getperm', function()
it('returns -1 when the given file does not exist', function()
eq(-1, (os_getperm('non-existing-file')))
@@ -270,7 +287,7 @@ describe('fs function', function()
-- Some systems may not have `id` utility.
if (os.execute('id -G > /dev/null 2>&1') ~= 0) then
- pending('skipped (missing `id` utility)')
+ pending('skipped (missing `id` utility)', function() end)
else
it('owner of a file may change the group of the file to any group of which that owner is a member', function()
local file_gid = lfs.attributes(filename, 'gid')
@@ -293,10 +310,8 @@ describe('fs function', function()
end)
end
- -- On Windows `os_fchown` always returns 0
- -- because `uv_fs_chown` is no-op on this platform.
if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then
- pending('skipped (os_fchown is no-op on Windows)')
+ pending('skipped (uv_fs_chown is no-op on Windows)', function() end)
else
it('returns nonzero if process has not enough permissions', function()
-- chown to root
@@ -305,33 +320,36 @@ describe('fs function', function()
end
end)
- describe('os_file_is_readonly', function()
- it('returns true if the file is readonly', function()
+
+ describe('os_file_is_readable', function()
+ it('returns false if the file is not readable', function()
local perm = os_getperm('unit-test-directory/test.file')
- local perm_orig = perm
- perm = unset_bit(perm, ffi.C.kS_IWUSR)
- perm = unset_bit(perm, ffi.C.kS_IWGRP)
- perm = unset_bit(perm, ffi.C.kS_IWOTH)
+ perm = unset_bit(perm, ffi.C.kS_IRUSR)
+ perm = unset_bit(perm, ffi.C.kS_IRGRP)
+ perm = unset_bit(perm, ffi.C.kS_IROTH)
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
- eq(true, os_file_is_readonly('unit-test-directory/test.file'))
- eq(OK, (os_setperm('unit-test-directory/test.file', perm_orig)))
+ eq(false, os_file_is_readable('unit-test-directory/test.file'))
+ end)
+
+ it('returns false if the file does not exist', function()
+ eq(false, os_file_is_readable(
+ 'unit-test-directory/what_are_you_smoking.gif'))
end)
- it('returns false if the file is writable', function()
- eq(false, os_file_is_readonly('unit-test-directory/test.file'))
+ it('returns true if the file is readable', function()
+ eq(true, os_file_is_readable(
+ 'unit-test-directory/test.file'))
end)
end)
describe('os_file_is_writable', function()
it('returns 0 if the file is readonly', function()
local perm = os_getperm('unit-test-directory/test.file')
- local perm_orig = perm
perm = unset_bit(perm, ffi.C.kS_IWUSR)
perm = unset_bit(perm, ffi.C.kS_IWGRP)
perm = unset_bit(perm, ffi.C.kS_IWOTH)
eq(OK, (os_setperm('unit-test-directory/test.file', perm)))
eq(0, os_file_is_writable('unit-test-directory/test.file'))
- eq(OK, (os_setperm('unit-test-directory/test.file', perm_orig)))
end)
it('returns 1 if the file is writable', function()
diff --git a/test/unit/queue_spec.lua b/test/unit/queue_spec.lua
new file mode 100644
index 0000000000..9326c1cad6
--- /dev/null
+++ b/test/unit/queue_spec.lua
@@ -0,0 +1,123 @@
+local helpers = require("test.unit.helpers")
+
+local ffi = helpers.ffi
+local eq = helpers.eq
+
+local queue = helpers.cimport("./test/unit/fixtures/queue.h")
+
+describe('queue', function()
+ local parent, child1, child2, child3
+
+ local function put(q, str)
+ queue.ut_queue_put(q, str)
+ end
+
+ local function get(q)
+ return ffi.string(queue.ut_queue_get(q))
+ end
+
+ local function free(q)
+ queue.queue_free(q)
+ end
+
+ before_each(function()
+ parent = queue.queue_new_parent(ffi.NULL, ffi.NULL)
+ child1 = queue.queue_new_child(parent)
+ child2 = queue.queue_new_child(parent)
+ child3 = queue.queue_new_child(parent)
+ put(child1, 'c1i1')
+ put(child1, 'c1i2')
+ put(child2, 'c2i1')
+ put(child1, 'c1i3')
+ put(child2, 'c2i2')
+ put(child2, 'c2i3')
+ put(child2, 'c2i4')
+ put(child3, 'c3i1')
+ put(child3, 'c3i2')
+ end)
+
+ it('removing from parent removes from child', function()
+ eq('c1i1', get(parent))
+ eq('c1i2', get(parent))
+ eq('c2i1', get(parent))
+ eq('c1i3', get(parent))
+ eq('c2i2', get(parent))
+ eq('c2i3', get(parent))
+ eq('c2i4', get(parent))
+ end)
+
+ it('removing from child removes from parent', function()
+ eq('c2i1', get(child2))
+ eq('c2i2', get(child2))
+ eq('c1i1', get(child1))
+ eq('c1i2', get(parent))
+ eq('c1i3', get(parent))
+ eq('c2i3', get(parent))
+ eq('c2i4', get(parent))
+ end)
+
+ it('removing from child at the beginning of parent', function()
+ eq('c1i1', get(child1))
+ eq('c1i2', get(child1))
+ eq('c2i1', get(parent))
+ end)
+
+ it('removing from parent after get from parent and put to child', function()
+ eq('c1i1', get(parent))
+ eq('c1i2', get(parent))
+ eq('c2i1', get(parent))
+ eq('c1i3', get(parent))
+ eq('c2i2', get(parent))
+ eq('c2i3', get(parent))
+ eq('c2i4', get(parent))
+ eq('c3i1', get(parent))
+ put(child1, 'c1i11')
+ put(child1, 'c1i22')
+ eq('c3i2', get(parent))
+ eq('c1i11', get(parent))
+ eq('c1i22', get(parent))
+ end)
+
+ it('removing from parent after get and put to child', function()
+ eq('c1i1', get(child1))
+ eq('c1i2', get(child1))
+ eq('c2i1', get(child2))
+ eq('c1i3', get(child1))
+ eq('c2i2', get(child2))
+ eq('c2i3', get(child2))
+ eq('c2i4', get(child2))
+ eq('c3i1', get(child3))
+ eq('c3i2', get(parent))
+ put(child1, 'c1i11')
+ put(child2, 'c2i11')
+ put(child1, 'c1i12')
+ eq('c2i11', get(child2))
+ eq('c1i11', get(parent))
+ eq('c1i12', get(parent))
+ end)
+
+ it('put after removing from child at the end of parent', function()
+ eq('c3i1', get(child3))
+ eq('c3i2', get(child3))
+ put(child1, 'c1i11')
+ put(child2, 'c2i11')
+ eq('c1i1', get(parent))
+ eq('c1i2', get(parent))
+ eq('c2i1', get(parent))
+ eq('c1i3', get(parent))
+ eq('c2i2', get(parent))
+ eq('c2i3', get(parent))
+ eq('c2i4', get(parent))
+ eq('c1i11', get(parent))
+ eq('c2i11', get(parent))
+ end)
+
+ it('removes from parent queue when child is freed', function()
+ free(child2)
+ eq('c1i1', get(parent))
+ eq('c1i2', get(parent))
+ eq('c1i3', get(parent))
+ eq('c3i1', get(child3))
+ eq('c3i2', get(child3))
+ end)
+end)