summaryrefslogtreecommitdiff
path: root/test-beta/rename
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-23 00:05:30 +0800
commit6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch)
treefdc22d78150fd1c5edc46732c8b151ccfefb519f /test-beta/rename
parentd0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff)
downloadlua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip
正路目录
Diffstat (limited to 'test-beta/rename')
-rw-r--r--test-beta/rename/init.lua165
1 files changed, 165 insertions, 0 deletions
diff --git a/test-beta/rename/init.lua b/test-beta/rename/init.lua
new file mode 100644
index 00000000..a1595d9a
--- /dev/null
+++ b/test-beta/rename/init.lua
@@ -0,0 +1,165 @@
+local core = require 'core.rename'
+local files = require 'files'
+
+local function replace(text, positions)
+ local buf = {}
+ table.sort(positions, function (a, b)
+ return a.start < b.start
+ end)
+ local lastPos = 1
+ for _, info in ipairs(positions) do
+ buf[#buf+1] = text:sub(lastPos, info.start - 1)
+ buf[#buf+1] = info.text
+ lastPos = info.finish + 1
+ end
+ buf[#buf+1] = text:sub(lastPos)
+ return table.concat(buf)
+end
+
+function TEST(oldName, newName)
+ return function (oldScript)
+ return function (newScript)
+ files.removeAll()
+ files.setText('', oldScript)
+ local pos = oldScript:find('[^%w_]'..oldName..'[^%w_]')
+ assert(pos)
+
+ local positions = core.rename('', pos+1, newName)
+ local script = oldScript
+ if positions then
+ script = replace(script, positions)
+ end
+ assert(script == newScript)
+ end
+ end
+end
+
+TEST ('a', 'b') [[
+local a = 1
+]] [[
+local b = 1
+]]
+
+TEST ('a', 'b') [[
+local a = 1
+a = 2
+a = a
+]] [[
+local b = 1
+b = 2
+b = b
+]]
+
+TEST ('a', 'b') [[
+t.a = 1
+a = t.a
+a = t['a']
+a = t["a"]
+a = t[ [=[a]=] ]
+]] [[
+t.b = 1
+a = t.b
+a = t['b']
+a = t["b"]
+a = t[ [=[b]=] ]
+]]
+
+TEST ('a', 'b') [[
+:: a ::
+goto a
+]] [[
+:: b ::
+goto b
+]]
+
+TEST ('a', 'b') [[
+local function f(a)
+ return a
+end
+]] [[
+local function f(b)
+ return b
+end
+]]
+
+TEST ('a', '!!!') [[
+t = {
+ a = 0
+}
+t.a = 1
+a = t.a
+]] [[
+t = {
+ ["!!!"] = 0
+}
+t["!!!"] = 1
+a = t["!!!"]
+]]
+
+TEST ('a', '!!!') [[
+t = {
+ ['a'] = 0
+}
+t.a = 1
+a = t.a
+]] [[
+t = {
+ ['!!!'] = 0
+}
+t["!!!"] = 1
+a = t["!!!"]
+]]
+
+TEST ('a', '"') [[
+print(t[ "a" ])
+]] [[
+print(t[ "\"" ])
+]]
+
+TEST ('a', '!!!') [[
+function mt:a()
+end
+mt:a()
+]] [[
+mt["!!!"] = function (self)
+end
+mt:!!!()
+]]
+
+TEST ('a', '!!!') [[
+function mt:a(x, y)
+end
+mt:a()
+]] [[
+mt["!!!"] = function (self, x, y)
+end
+mt:!!!()
+]]
+
+TEST ('a', '!!!') [[
+a = a
+]] [[
+_ENV["!!!"] = _ENV["!!!"]
+]]
+
+TEST ('a', '!!!') [[
+function a() end
+]] [[
+_ENV["!!!"] = function () end
+]]
+
+TEST ('a', 'a.b') [[
+function a() end
+a()
+]] [[
+function a.b() end
+a.b()
+]]
+
+TEST ('a', 'a:b') [[
+function a() end
+a()
+]] [[
+function a:b() end
+a:b()
+]]