test: handle non-deterministic message cadence

This commit is contained in:
Justin M. Keyes 2018-03-08 20:28:51 +01:00
parent 9154782386
commit 2bf0869160

View File

@ -292,8 +292,16 @@ describe('jobs', function()
nvim('command', 'let g:job_opts.user = {"n": 5, "s": "str", "l": [1]}')
nvim('command', [[call jobstart('echo "foo"', g:job_opts)]])
local data = {n = 5, s = 'str', l = {1}}
eq({'notification', 'stdout', {data, {'foo', ''}}}, next_msg())
eq({'notification', 'stdout', {data, {''}}}, next_msg())
expect_msg_seq(
{ {'notification', 'stdout', {data, {'foo', ''}}},
{'notification', 'stdout', {data, {''}}},
},
-- Alternative sequence:
{ {'notification', 'stdout', {data, {'foo'}}},
{'notification', 'stdout', {data, {'', ''}}},
{'notification', 'stdout', {data, {''}}},
}
)
eq({'notification', 'exit', {data, 0}}, next_msg())
end)
@ -310,11 +318,12 @@ describe('jobs', function()
nvim('command', [[call jobstart('echo "foo"', g:job_opts)]])
expect_msg_seq(
{ {'notification', 'stdout', {5, {'foo', ''} } },
{'notification', 'stdout', {5, {''} } }
{'notification', 'stdout', {5, {''} } },
},
-- Alternative sequence:
{ {'notification', 'stdout', {5, {'foo'} } },
{'notification', 'stdout', {5, {'', ''} } }
{'notification', 'stdout', {5, {'', ''} } },
{'notification', 'stdout', {5, {''} } },
}
)
end)
@ -417,7 +426,14 @@ describe('jobs', function()
let g:job_opts = {'on_stdout': Callback}
call jobstart('echo "some text"', g:job_opts)
]])
eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
expect_msg_seq(
{ {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}},
},
-- Alternative sequence:
{ {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}},
{'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}},
}
)
end)
it('jobstart() works with closures', function()
@ -430,7 +446,14 @@ describe('jobs', function()
let g:job_opts = {'on_stdout': MkFun()}
call jobstart('echo "some text"', g:job_opts)
]])
eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
expect_msg_seq(
{ {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}},
},
-- Alternative sequence:
{ {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}},
{'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}},
}
)
end)
it('jobstart() works when closure passed directly to `jobstart`', function()
@ -438,7 +461,14 @@ describe('jobs', function()
let g:job_opts = {'on_stdout': {id, data, event -> rpcnotify(g:channel, '1', 'foo', 'bar', Normalize(data), event)}}
call jobstart('echo "some text"', g:job_opts)
]])
eq({'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}}, next_msg())
expect_msg_seq(
{ {'notification', '1', {'foo', 'bar', {'some text', ''}, 'stdout'}},
},
-- Alternative sequence:
{ {'notification', '1', {'foo', 'bar', {'some text'}, 'stdout'}},
{'notification', '1', {'foo', 'bar', {'', ''}, 'stdout'}},
}
)
end)
describe('jobwait', function()