diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2023-12-04 14:32:39 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-04 14:32:39 -0800 |
| commit | c3836e40a2bffbc1d4e06531145b7825788dd818 (patch) | |
| tree | 895e994179074983789a5f893b96dc75d39f6e6b /test/client | |
| parent | 45fe4d11add933df76a2ea4bf52ce8904f4a778b (diff) | |
| download | rneovim-c3836e40a2bffbc1d4e06531145b7825788dd818.tar.gz rneovim-c3836e40a2bffbc1d4e06531145b7825788dd818.tar.bz2 rneovim-c3836e40a2bffbc1d4e06531145b7825788dd818.zip | |
build: enable lintlua for test/unit/ dir #26396
Problem:
Not all Lua code is checked by stylua. Automating code-style is an
important mechanism for reducing time spent on accidental
(non-essential) complexity.
Solution:
- Enable lintlua for `test/unit/` directory.
- TODO: only `test/functional/` remains unchecked.
previous: 45fe4d11add933df76a2ea4bf52ce8904f4a778b
previous: 517f0cc634b985057da5b95cf4ad659ee456a77e
Diffstat (limited to 'test/client')
| -rw-r--r-- | test/client/msgpack_rpc_stream.lua | 52 | ||||
| -rw-r--r-- | test/client/session.lua | 28 | ||||
| -rw-r--r-- | test/client/uv_stream.lua | 27 |
3 files changed, 63 insertions, 44 deletions
diff --git a/test/client/msgpack_rpc_stream.lua b/test/client/msgpack_rpc_stream.lua index 5711616b17..ff054ae62b 100644 --- a/test/client/msgpack_rpc_stream.lua +++ b/test/client/msgpack_rpc_stream.lua @@ -3,13 +3,19 @@ local mpack = require('mpack') -- temporary hack to be able to manipulate buffer/window/tabpage local Buffer = {} Buffer.__index = Buffer -function Buffer.new(id) return setmetatable({id=id}, Buffer) end +function Buffer.new(id) + return setmetatable({ id = id }, Buffer) +end local Window = {} Window.__index = Window -function Window.new(id) return setmetatable({id=id}, Window) end +function Window.new(id) + return setmetatable({ id = id }, Window) +end local Tabpage = {} Tabpage.__index = Tabpage -function Tabpage.new(id) return setmetatable({id=id}, Tabpage) end +function Tabpage.new(id) + return setmetatable({ id = id }, Tabpage) +end local Response = {} Response.__index = Response @@ -17,7 +23,7 @@ Response.__index = Response function Response.new(msgpack_rpc_stream, request_id) return setmetatable({ _msgpack_rpc_stream = msgpack_rpc_stream, - _request_id = request_id + _request_id = request_id, }, Response) end @@ -41,19 +47,31 @@ function MsgpackRpcStream.new(stream) _stream = stream, _pack = mpack.Packer({ ext = { - [Buffer] = function(o) return 0, mpack.encode(o.id) end, - [Window] = function(o) return 1, mpack.encode(o.id) end, - [Tabpage] = function(o) return 2, mpack.encode(o.id) end - } + [Buffer] = function(o) + return 0, mpack.encode(o.id) + end, + [Window] = function(o) + return 1, mpack.encode(o.id) + end, + [Tabpage] = function(o) + return 2, mpack.encode(o.id) + end, + }, }), _session = mpack.Session({ unpack = mpack.Unpacker({ ext = { - [0] = function(_c, s) return Buffer.new(mpack.decode(s)) end, - [1] = function(_c, s) return Window.new(mpack.decode(s)) end, - [2] = function(_c, s) return Tabpage.new(mpack.decode(s)) end - } - }) + [0] = function(_c, s) + return Buffer.new(mpack.decode(s)) + end, + [1] = function(_c, s) + return Window.new(mpack.decode(s)) + end, + [2] = function(_c, s) + return Tabpage.new(mpack.decode(s)) + end, + }, + }), }), }, MsgpackRpcStream) end @@ -67,7 +85,7 @@ function MsgpackRpcStream:write(method, args, response_cb) data = self._session:notify() end - data = data .. self._pack(method) .. self._pack(args) + data = data .. self._pack(method) .. self._pack(args) self._stream:write(data) end @@ -80,12 +98,10 @@ function MsgpackRpcStream:read_start(request_cb, notification_cb, eof_cb) local pos = 1 local len = #data while pos <= len do - type, id_or_cb, method_or_error, args_or_result, pos = - self._session:receive(data, pos) + type, id_or_cb, method_or_error, args_or_result, pos = self._session:receive(data, pos) if type == 'request' or type == 'notification' then if type == 'request' then - request_cb(method_or_error, args_or_result, Response.new(self, - id_or_cb)) + request_cb(method_or_error, args_or_result, Response.new(self, id_or_cb)) else notification_cb(method_or_error, args_or_result) end diff --git a/test/client/session.lua b/test/client/session.lua index b1bf5ea75e..78909d1061 100644 --- a/test/client/session.lua +++ b/test/client/session.lua @@ -7,7 +7,7 @@ if package.loaded['jit'] then -- luajit pcall is already coroutine safe Session.safe_pcall = pcall else - Session.safe_pcall = require'coxpcall'.pcall + Session.safe_pcall = require 'coxpcall'.pcall end local function resume(co, ...) @@ -25,7 +25,7 @@ local function resume(co, ...) end local function coroutine_exec(func, ...) - local args = {...} + local args = { ... } local on_complete if #args > 0 and type(args[#args]) == 'function' then @@ -50,18 +50,18 @@ function Session.new(stream) _pending_messages = {}, _prepare = uv.new_prepare(), _timer = uv.new_timer(), - _is_running = false + _is_running = false, }, Session) end function Session:next_message(timeout) local function on_request(method, args, response) - table.insert(self._pending_messages, {'request', method, args, response}) + table.insert(self._pending_messages, { 'request', method, args, response }) uv.stop() end local function on_notification(method, args) - table.insert(self._pending_messages, {'notification', method, args}) + table.insert(self._pending_messages, { 'notification', method, args }) uv.stop() end @@ -83,11 +83,11 @@ function Session:next_message(timeout) end function Session:notify(method, ...) - self._msgpack_rpc_stream:write(method, {...}) + self._msgpack_rpc_stream:write(method, { ... }) end function Session:request(method, ...) - local args = {...} + local args = { ... } local err, result if self._is_running then err, result = self:_yielding_request(method, args) @@ -141,8 +141,12 @@ function Session:stop() end function Session:close(signal) - if not self._timer:is_closing() then self._timer:close() end - if not self._prepare:is_closing() then self._prepare:close() end + if not self._timer:is_closing() then + self._timer:close() + end + if not self._prepare:is_closing() then + self._prepare:close() + end self._msgpack_rpc_stream:close(signal) self.closed = true end @@ -159,11 +163,11 @@ function Session:_blocking_request(method, args) local err, result local function on_request(method_, args_, response) - table.insert(self._pending_messages, {'request', method_, args_, response}) + table.insert(self._pending_messages, { 'request', method_, args_, response }) end local function on_notification(method_, args_) - table.insert(self._pending_messages, {'notification', method_, args_}) + table.insert(self._pending_messages, { 'notification', method_, args_ }) end self._msgpack_rpc_stream:write(method, args, function(e, r) @@ -187,7 +191,7 @@ function Session:_run(request_cb, notification_cb, timeout) end self._msgpack_rpc_stream:read_start(request_cb, notification_cb, function() uv.stop() - self.eof_err = {1, "EOF was received from Nvim. Likely the Nvim process crashed."} + self.eof_err = { 1, 'EOF was received from Nvim. Likely the Nvim process crashed.' } end) uv.run() self._prepare:stop() diff --git a/test/client/uv_stream.lua b/test/client/uv_stream.lua index cea77f0dbd..f37a0ec3ce 100644 --- a/test/client/uv_stream.lua +++ b/test/client/uv_stream.lua @@ -6,7 +6,7 @@ StdioStream.__index = StdioStream function StdioStream.open() local self = setmetatable({ _in = uv.new_pipe(false), - _out = uv.new_pipe(false) + _out = uv.new_pipe(false), }, StdioStream) self._in:open(0) self._out:open(1) @@ -42,9 +42,9 @@ function SocketStream.open(file) local socket = uv.new_pipe(false) local self = setmetatable({ _socket = socket, - _stream_error = nil + _stream_error = nil, }, SocketStream) - uv.pipe_connect(socket, file, function (err) + uv.pipe_connect(socket, file, function(err) self._stream_error = self._stream_error or err end) return self @@ -54,15 +54,14 @@ function SocketStream.connect(host, port) local socket = uv.new_tcp() local self = setmetatable({ _socket = socket, - _stream_error = nil + _stream_error = nil, }, SocketStream) - uv.tcp_connect(socket, host, port, function (err) + uv.tcp_connect(socket, host, port, function(err) self._stream_error = self._stream_error or err end) return self end - function SocketStream:write(data) if self._stream_error then error(self._stream_error) @@ -102,9 +101,9 @@ ChildProcessStream.__index = ChildProcessStream function ChildProcessStream.spawn(argv, env, io_extra) local self = setmetatable({ - _child_stdin = uv.new_pipe(false); - _child_stdout = uv.new_pipe(false); - _exiting = false; + _child_stdin = uv.new_pipe(false), + _child_stdout = uv.new_pipe(false), + _exiting = false, }, ChildProcessStream) local prog = argv[1] local args = {} @@ -112,7 +111,7 @@ function ChildProcessStream.spawn(argv, env, io_extra) args[#args + 1] = argv[i] end self._proc, self._pid = uv.spawn(prog, { - stdio = {self._child_stdin, self._child_stdout, 2, io_extra}, + stdio = { self._child_stdin, self._child_stdout, 2, io_extra }, args = args, env = env, }, function(status, signal) @@ -154,7 +153,7 @@ function ChildProcessStream:close(signal) self._child_stdin:close() self._child_stdout:close() if type(signal) == 'string' then - self._proc:kill('sig'..signal) + self._proc:kill('sig' .. signal) end while self.status == nil do uv.run 'once' @@ -163,7 +162,7 @@ function ChildProcessStream:close(signal) end return { - StdioStream = StdioStream; - ChildProcessStream = ChildProcessStream; - SocketStream = SocketStream; + StdioStream = StdioStream, + ChildProcessStream = ChildProcessStream, + SocketStream = SocketStream, } |