Merge pull request #4952 from bfredl/counttest

test: fix command_count_spec
This commit is contained in:
Björn Linse 2016-06-23 19:02:40 +02:00 committed by GitHub
commit 65af001f2b
6 changed files with 24 additions and 25 deletions

View File

@ -10,8 +10,8 @@ local redir_exec = helpers.redir_exec
local NIL = helpers.NIL local NIL = helpers.NIL
describe('json_decode() function', function() describe('json_decode() function', function()
local restart = function(cmd) local restart = function(...)
clear(cmd) clear(...)
execute('language C') execute('language C')
execute([[ execute([[
function Eq(exp, act) function Eq(exp, act)
@ -490,13 +490,13 @@ describe('json_decode() function', function()
end) end)
it('converts strings to latin1 when &encoding is latin1', function() it('converts strings to latin1 when &encoding is latin1', function()
restart('set encoding=latin1') restart('--cmd', 'set encoding=latin1')
eq('\171', funcs.json_decode('"\\u00AB"')) eq('\171', funcs.json_decode('"\\u00AB"'))
sp_decode_eq({_TYPE='string', _VAL={'\n\171\n'}}, '"\\u0000\\u00AB\\u0000"') sp_decode_eq({_TYPE='string', _VAL={'\n\171\n'}}, '"\\u0000\\u00AB\\u0000"')
end) end)
it('fails to convert string to latin1 if it is impossible', function() it('fails to convert string to latin1 if it is impossible', function()
restart('set encoding=latin1') restart('--cmd', 'set encoding=latin1')
eq('Vim(call):E474: Failed to convert string "ꯍ" from UTF-8', eq('Vim(call):E474: Failed to convert string "ꯍ" from UTF-8',
exc_exec('call json_decode(\'"\\uABCD"\')')) exc_exec('call json_decode(\'"\\uABCD"\')'))
end) end)
@ -532,7 +532,7 @@ describe('json_decode() function', function()
-- When &encoding is latin1 string "«" is U+00C2 U+00AB U+00C2: «Â. So if -- When &encoding is latin1 string "«" is U+00C2 U+00AB U+00C2: «Â. So if
-- '"«"' was parsed as latin1 json_decode would return three characters, and -- '"«"' was parsed as latin1 json_decode would return three characters, and
-- only one U+00AB when this string is parsed as latin1. -- only one U+00AB when this string is parsed as latin1.
restart('set encoding=latin1') restart('--cmd', 'set encoding=latin1')
eq(('%c'):format(0xAB), funcs.json_decode('"«"')) eq(('%c'):format(0xAB), funcs.json_decode('"«"'))
end) end)
@ -763,7 +763,7 @@ describe('json_encode() function', function()
end) end)
it('converts strings from latin1 when &encoding is latin1', function() it('converts strings from latin1 when &encoding is latin1', function()
clear('set encoding=latin1') clear('--cmd', 'set encoding=latin1')
eq('"\\u00AB"', funcs.json_encode('\171')) eq('"\\u00AB"', funcs.json_encode('\171'))
eq('"\\u0000\\u00AB\\u0000"', eval('json_encode({"_TYPE": v:msgpack_types.string, "_VAL": ["\\n\171\\n"]})')) eq('"\\u0000\\u00AB\\u0000"', eval('json_encode({"_TYPE": v:msgpack_types.string, "_VAL": ["\\n\171\\n"]})'))
end) end)

View File

@ -22,7 +22,7 @@ describe('&encoding', function()
end) end)
it('can be changed before startup', function() it('can be changed before startup', function()
clear('set enc=latin1') clear('--cmd', 'set enc=latin1')
execute('set encoding=utf-8') execute('set encoding=utf-8')
-- error message expected -- error message expected
feed('<cr>') feed('<cr>')
@ -32,7 +32,7 @@ describe('&encoding', function()
it('is not changed by `set all&`', function() it('is not changed by `set all&`', function()
-- we need to set &encoding to something non-default. Use 'latin1' -- we need to set &encoding to something non-default. Use 'latin1'
clear('set enc=latin1') clear('--cmd', 'set enc=latin1')
execute('set all&') execute('set all&')
eq('latin1', eval('&encoding')) eq('latin1', eval('&encoding'))
eq(4, eval('strwidth("Bär")')) eq(4, eval('strwidth("Bär")'))

View File

@ -3,7 +3,7 @@ local clear = helpers.clear
describe(':qa', function() describe(':qa', function()
before_each(function() before_each(function()
clear('qa') clear('--cmd', 'qa')
end) end)
it('verify #3334', function() it('verify #3334', function()

View File

@ -12,7 +12,7 @@ describe(':write', function()
end) end)
it('&backupcopy=auto preserves symlinks', function() it('&backupcopy=auto preserves symlinks', function()
clear('set backupcopy=auto') clear('--cmd', 'set backupcopy=auto')
write_file('test_bkc_file.txt', 'content0') write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[ source([[
@ -25,7 +25,7 @@ describe(':write', function()
end) end)
it('&backupcopy=no replaces symlink with new file', function() it('&backupcopy=no replaces symlink with new file', function()
clear('set backupcopy=no') clear('--cmd', 'set backupcopy=no')
write_file('test_bkc_file.txt', 'content0') write_file('test_bkc_file.txt', 'content0')
execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt")
source([[ source([[

View File

@ -221,11 +221,10 @@ local function spawn(argv, merge)
return Session.new(child_stream) return Session.new(child_stream)
end end
local function clear(extra_cmd) local function clear(...)
local args = {unpack(nvim_argv)} local args = {unpack(nvim_argv)}
if extra_cmd ~= nil then for _, arg in ipairs({...}) do
table.insert(args, '--cmd') table.insert(args, arg)
table.insert(args, extra_cmd)
end end
set_session(spawn(args)) set_session(spawn(args))
end end

View File

@ -2,24 +2,19 @@
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local clear, source, expect = helpers.clear, helpers.source, helpers.expect local clear, source, expect = helpers.clear, helpers.source, helpers.expect
local execute, spawn = helpers.execute, helpers.spawn local execute = helpers.execute
local nvim_prog = helpers.nvim_prog
describe('command_count', function() describe('command_count', function()
setup(clear)
teardown(function()
os.remove('test.out')
end)
it('is working', function() it('is working', function()
-- It is relevant for the test to load a file initially. If this is -- It is relevant for the test to load a file initially. If this is
-- emulated with :arg the buffer count is wrong as nvim creates an empty -- emulated with :arg the buffer count is wrong as nvim creates an empty
-- buffer if it was started without a filename. -- buffer if it was started without a filename.
local nvim2 = spawn({nvim_prog, '-u', 'NONE', '-i', 'NONE', '--embed', clear('test_command_count.in')
'test_command_count.in'})
helpers.set_session(nvim2)
source([[ source([[
let g:tmpname = tempname()
call mkdir(g:tmpname)
execute "cd ".g:tmpname
lang C lang C
let g:lines = [] let g:lines = []
com -range=% RangeLines com -range=% RangeLines
@ -239,5 +234,10 @@ describe('command_count', function()
bufdo: 2 3 4 5 6 7 8 9 10 15 bufdo: 2 3 4 5 6 7 8 9 10 15
bufdo: 4 5 6 7 bufdo: 4 5 6 7
tabdo: 2 3 4]]) tabdo: 2 3 4]])
source([[
cd ..
call delete(g:tmpname, 'rf')
]])
end) end)
end) end)