summaryrefslogtreecommitdiff
path: root/test/diagnostics/uppercase-local.lua
diff options
context:
space:
mode:
authorAndreaWalchshoferSCCH <122894794+AndreaWalchshoferSCCH@users.noreply.github.com>2023-04-04 11:02:59 +0200
committerGitHub <noreply@github.com>2023-04-04 11:02:59 +0200
commit27cfa2e23648b015a94fab6e0938ec42a5a040e5 (patch)
treee247b1aac92882c72e5c694eb8090f883d43c76c /test/diagnostics/uppercase-local.lua
parentf85e039b9e9369fc2936e899c81056837f04403e (diff)
downloadlua-language-server-27cfa2e23648b015a94fab6e0938ec42a5a040e5.zip
Add diagnostic to enforce lowercase local element names (#6)
- diagnostic `uppercase-local` in group `conventions`, disabled by default - isolated unit tests for diagnostic
Diffstat (limited to 'test/diagnostics/uppercase-local.lua')
-rw-r--r--test/diagnostics/uppercase-local.lua66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/diagnostics/uppercase-local.lua b/test/diagnostics/uppercase-local.lua
new file mode 100644
index 00000000..fc0b95d1
--- /dev/null
+++ b/test/diagnostics/uppercase-local.lua
@@ -0,0 +1,66 @@
+local config = require 'config'
+local util = require 'utility'
+
+-- disable all default groups to make isolated tests
+config.set(nil, 'Lua.diagnostics.groupFileStatus',
+{
+ ['ambiguity'] = 'None',
+ ['await'] = 'None',
+ ['codestyle'] = 'None',
+ ['conventions'] = 'None',
+ ['duplicate'] = 'None',
+ ['global'] = 'None',
+ ['luadoc'] = 'None',
+ ['redefined'] = 'None',
+ ['strict'] = 'None',
+ ['strong'] = 'None',
+ ['type-check'] = 'None',
+ ['unbalanced'] = 'None',
+ ['unused'] = 'None'
+})
+
+-- enable single diagnostic that is to be tested
+config.set(nil, 'Lua.diagnostics.neededFileStatus',
+{
+ ['uppercase-local'] = 'Any!' -- override groupFileStatus
+})
+
+-- check that global elements are not warned about
+TEST [[
+Var1 = "global"
+VAR2 = "global"
+
+local x = true
+local <!Y!> = false
+local <!Var!> = false
+]]
+
+TEST [[
+local function test1()
+ print()
+end
+
+local function <!Test2!>()
+ print()
+end
+]]
+
+TEST [[
+local function closure1()
+ local elem1 = 1
+ local <!Elem2!> = 2
+end
+
+local function <!Closure2!>()
+ local elem1 = 1
+ local <!Elem2!> = 2
+end
+]]
+
+-- reset configurations
+config.set(nil, 'Lua.diagnostics.groupFileStatus',
+{})
+config.set(nil, 'Lua.diagnostics.neededFileStatus',
+{})
+config.set(nil, 'Lua.diagnostics.globals',
+{})