diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-03-08 21:17:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-03-08 21:17:43 +0800 |
commit | 48a3aab6e3becb5127ad467964c44f19187cac35 (patch) | |
tree | 87cbce0f6523c60100fbd69e4c9621120ba67d17 /test | |
parent | f462813bee496adb2613389b0bfbb3e558617916 (diff) | |
download | lua-language-server-48a3aab6e3becb5127ad467964c44f19187cac35.zip |
don't treat `_ENV` as param
fix #1715
Diffstat (limited to 'test')
-rw-r--r-- | test/diagnostics/common.lua | 6 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 33 |
2 files changed, 38 insertions, 1 deletions
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 89537771..a1dbe819 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -2262,3 +2262,9 @@ else function X.f() end end ]] + +TESTWITH 'global-in-nil-env' [[ +local function foo(_ENV) + Joe = "human" +end +]] diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 3c19e58d..827d4d08 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -27,7 +27,7 @@ local function founded(targets, results) end ---@diagnostic disable: await-in-sync -function TEST(script, ...) +function TEST(script) local newScript, catched = catch(script, '!') files.setText(TESTURI, newScript) files.open(TESTURI) @@ -53,5 +53,36 @@ function TEST(script, ...) end end +function TESTWITH(code) + return function (script) + local newScript, catched = catch(script, '!') + files.setText(TESTURI, newScript) + files.open(TESTURI) + local origins = {} + local results = {} + core(TESTURI, false, function (result) + if code ~= result.code then + return + end + results[#results+1] = { result.start, result.finish } + origins[#origins+1] = result + end) + + if results[1] then + if not founded(catched['!'] or {}, results) then + error(('%s\n%s'):format(util.dump(catched['!']), util.dump(results))) + end + else + assert(#catched['!'] == 0) + end + + files.remove(TESTURI) + + return function (callback) + callback(origins) + end + end +end + require 'diagnostics.common' require 'diagnostics.type-check' |