From c2d2e7a92461dafab0b3446cd30db67d00eed570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 17 Jan 2022 15:32:44 +0800 Subject: prepare client test --- test/client/init.lua | 1 + test/client/lclient.lua | 61 +++++++++++++++++++++++++++++++++++++++ test/client/tests/single-mode.lua | 0 3 files changed, 62 insertions(+) create mode 100644 test/client/init.lua create mode 100644 test/client/lclient.lua create mode 100644 test/client/tests/single-mode.lua (limited to 'test') diff --git a/test/client/init.lua b/test/client/init.lua new file mode 100644 index 00000000..af373a30 --- /dev/null +++ b/test/client/init.lua @@ -0,0 +1 @@ +require 'client.tests.single-mode' diff --git a/test/client/lclient.lua b/test/client/lclient.lua new file mode 100644 index 00000000..ecf9f539 --- /dev/null +++ b/test/client/lclient.lua @@ -0,0 +1,61 @@ +local gc = require 'gc' +local util = require 'utility' + +---@class languageClient +---@field _inFile file* +---@field _outFile file* +---@field _gc gc +local mt = {} +mt.__index = mt + +function mt:__close() + self:remove() +end + +function mt:_openIO() + local r = math.random(1, 10000) + self._inPath = ('%s/%s.in'):format(LOGPATH, r) + self._outPath = ('%s/%s.out'):format(LOGPATH, r) + local stdin = io.open(self._inPath, 'rb') + local stdout = io.open(self._outPath, 'wb') + self._inFile = io.open(self._inPath, 'wb') + self._outFile = io.open(self._outPath, 'rb') + io.stdin = stdin + io.stdout = stdout + self:gc(function () + stdin:close() + stdout:close() + self._inFile:close() + self._outFile:close() + end) +end + +function mt:_flushServer() + -- reset scopes + local ws = require 'workspace' + local scope = require 'workspace.scope' + local files = require 'files' + ws.reset() + scope.reset() + files.reset() +end + +function mt:start() + self:_openIO() + self:_flushServer() +end + +function mt:gc(obj) + return self._gc:add(obj) +end + +function mt:remove() + self._gc:remove() +end + +return function () + local self = setmetatable({ + _gc = gc(), + }, mt) + return self +end diff --git a/test/client/tests/single-mode.lua b/test/client/tests/single-mode.lua new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3