Skip to content

Commit 0c31e30

Browse files
committed
Added tests
1 parent 393f3e8 commit 0c31e30

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

locale/en-us/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ ACTION_ADD_DICT =
449449
ACTION_FIX_ADD_PAREN = -- TODO: need translate!
450450
'Add parentheses.'
451451
ACTION_AUTOREQUIRE = -- TODO: need translate!
452-
"Import {} as '{}'"
452+
"Import '{}' as {}"
453453

454454
COMMAND_DISABLE_DIAG =
455455
'Disable diagnostics'

script/core/code-action.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ local function checkMissingRequire(results, uri, start, finish)
703703

704704
for _, target in ipairs(findRequireTargets(visiblePaths)) do
705705
results[#results+1] = {
706-
title = lang.script('ACTION_AUTOREQUIRE', global, target),
706+
title = lang.script('ACTION_AUTOREQUIRE', target, global),
707707
kind = 'refactor.rewrite',
708708
command = {
709709
title = 'autoRequire',

test/code_action/init.lua

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ local t = {
183183
-- },
184184
--}
185185

186-
-- TODO: Add some tests for ACTION_AUTOREQUIRE
187-
188186
TEST_CROSSFILE {
189187
[[
190188
<?unrequiredModule?>.myFunction()
@@ -214,4 +212,67 @@ TEST_CROSSFILE {
214212
},
215213
}
216214
}
215+
}
216+
217+
TEST_CROSSFILE {
218+
[[
219+
<?myModule?>.myFunction()
220+
]],
221+
{
222+
path = 'myModule/init.lua',
223+
content = [[
224+
local m = {}
225+
m.myFunction = print
226+
return m
227+
]]
228+
}
229+
} {
230+
{
231+
title = lang.script('ACTION_AUTOREQUIRE', 'myModule.init', 'myModule'),
232+
kind = 'refactor.rewrite',
233+
command = {
234+
title = 'autoRequire',
235+
command = 'lua.autoRequire',
236+
arguments = {
237+
{
238+
uri = TESTURI,
239+
target = furi.encode 'myModule/init.lua',
240+
name = 'myModule',
241+
requireName = 'myModule.init'
242+
},
243+
},
244+
}
245+
},
246+
{
247+
title = lang.script('ACTION_AUTOREQUIRE', 'init', 'myModule'),
248+
kind = 'refactor.rewrite',
249+
command = {
250+
title = 'autoRequire',
251+
command = 'lua.autoRequire',
252+
arguments = {
253+
{
254+
uri = TESTURI,
255+
target = furi.encode 'myModule/init.lua',
256+
name = 'myModule',
257+
requireName = 'init'
258+
},
259+
},
260+
}
261+
},
262+
{
263+
title = lang.script('ACTION_AUTOREQUIRE', 'myModule', 'myModule'),
264+
kind = 'refactor.rewrite',
265+
command = {
266+
title = 'autoRequire',
267+
command = 'lua.autoRequire',
268+
arguments = {
269+
{
270+
uri = TESTURI,
271+
target = furi.encode 'myModule/init.lua',
272+
name = 'myModule',
273+
requireName = 'myModule'
274+
},
275+
},
276+
}
277+
},
217278
}

0 commit comments

Comments
 (0)