summaryrefslogtreecommitdiff
path: root/test/tclient/tests
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-01 20:04:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-01 20:04:35 +0800
commit671f1f4562ff284530c4be5a4296bf8ddb42b90a (patch)
tree0e2ff141fa9e8f6ef530a4403c97b2e5572a1d15 /test/tclient/tests
parent3fba691469ae30b06575174bbd151cc460b7b132 (diff)
downloadlua-language-server-671f1f4562ff284530c4be5a4296bf8ddb42b90a.zip
#831
add tests
Diffstat (limited to 'test/tclient/tests')
-rw-r--r--test/tclient/tests/modify-luarc.lua187
1 files changed, 187 insertions, 0 deletions
diff --git a/test/tclient/tests/modify-luarc.lua b/test/tclient/tests/modify-luarc.lua
new file mode 100644
index 00000000..14c9fc65
--- /dev/null
+++ b/test/tclient/tests/modify-luarc.lua
@@ -0,0 +1,187 @@
+local lclient = require 'lclient'
+local util = require 'utility'
+local ws = require 'workspace'
+local jsonc = require 'jsonc'
+local jsonb = require 'json-beautify'
+local client = require 'client'
+local provider = require 'provider'
+local json = require 'json'
+
+local configPath = LOGPATH .. '/modify-luarc.json'
+
+---@async
+lclient():start(function (languageClient)
+ languageClient:registerFakers()
+
+ CONFIGPATH = configPath
+
+ languageClient:initialize()
+
+ ws.awaitReady()
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'set',
+ key = 'Lua.runtime.version',
+ value = 'LuaJIT',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['xxxx'] = 1,
+ ['Lua.runtime.version'] = 'LuaJIT',
+ }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'add',
+ key = 'Lua.diagnostics.disable',
+ value = 'undefined-global',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['xxxx'] = 1,
+ ['Lua.diagnostics.disable'] = {
+ 'undefined-global',
+ }
+ }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['Lua.diagnostics.disable'] = {}
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'add',
+ key = 'Lua.diagnostics.disable',
+ value = 'undefined-global',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['Lua.diagnostics.disable'] = {
+ 'undefined-global',
+ }
+ }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['Lua.diagnostics.disable'] = {
+ 'unused-local'
+ }
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'add',
+ key = 'Lua.diagnostics.disable',
+ value = 'undefined-global',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['Lua.diagnostics.disable'] = {
+ 'unused-local',
+ 'undefined-global',
+ }
+ }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'prop',
+ key = 'Lua.runtime.special',
+ prop = 'include',
+ value = 'require',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['xxxx'] = 1,
+ ['Lua.runtime.special'] = {
+ ['include'] = 'require',
+ }
+ }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['Lua.runtime.special'] = json.createEmptyObject()
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'prop',
+ key = 'Lua.runtime.special',
+ prop = 'include',
+ value = 'require',
+ }
+ })
+
+ -- TODO: bug of json-edit, can not be an empty json
+ -- assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ -- ['Lua.runtime.special'] = {
+ -- ['include'] = 'require',
+ -- }
+ -- }))
+
+ -------------------------------
+
+ util.saveFile(configPath, jsonb.beautify {
+ ['Lua.runtime.special'] = {
+ ['import'] = 'require',
+ }
+ })
+
+ provider.updateConfig()
+
+ client.setConfig({
+ {
+ action = 'prop',
+ key = 'Lua.runtime.special',
+ prop = 'include',
+ value = 'require',
+ }
+ })
+
+ assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), {
+ ['Lua.runtime.special'] = {
+ ['import'] = 'require',
+ ['include'] = 'require',
+ }
+ }))
+
+end)