-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSlashCommands.test.lua
More file actions
executable file
·109 lines (78 loc) · 3.67 KB
/
Copy pathSlashCommands.test.lua
File metadata and controls
executable file
·109 lines (78 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
_G.SlashCmdList = {}
_G.SLASH_DisenchantBuddy1 = nil
describe("SlashCommands", function()
---@type DisenchantBuddy
local DisenchantBuddy
before_each(function()
_G.IsShiftKeyDown = spy.new(function() return false end)
_G.IsAltKeyDown = spy.new(function() return false end)
_G.IsControlKeyDown = spy.new(function() return false end)
_G.print = spy.new(function() end)
_G.DisenchantBuddy_Profile = {}
DisenchantBuddy = {
L = {
["Modifier is now: %s"] = "Modifier is now: %s",
["Syntax:"] = "Syntax:",
}
}
loadfile("SlashCommands.lua")("DisenchantBuddy", DisenchantBuddy)
end)
describe("ProcessCommand", function()
it("should set modifier to SHIFT", function()
DisenchantBuddy.ProcessCommand("modifier shift")
assert.are_same("SHIFT", _G.DisenchantBuddy_Profile.Modifier)
end)
it("should set modifier to ALT", function()
DisenchantBuddy.ProcessCommand("modifier alt")
assert.are_same("ALT", _G.DisenchantBuddy_Profile.Modifier)
end)
it("should set modifier to CONTROL", function()
DisenchantBuddy.ProcessCommand("modifier control")
assert.are_same("CONTROL", _G.DisenchantBuddy_Profile.Modifier)
end)
it("should set modifier to OFF when off is passed", function()
DisenchantBuddy.ProcessCommand("modifier off")
assert.are_same("OFF", _G.DisenchantBuddy_Profile.Modifier)
end)
it("should set modifier to OFF for unknown value", function()
DisenchantBuddy.ProcessCommand("modifier banana")
assert.are_same("OFF", _G.DisenchantBuddy_Profile.Modifier)
end)
it("should print translated modifier confirmation", function()
DisenchantBuddy.L["Modifier is now: %s"] = "Modifier ist jetzt: %s"
loadfile("SlashCommands.lua")("DisenchantBuddy", DisenchantBuddy)
DisenchantBuddy.ProcessCommand("modifier shift")
assert.spy(_G.print).was.called_with("Modifier ist jetzt: SHIFT")
end)
it("should print translated syntax help for unknown command", function()
DisenchantBuddy.L["Syntax:"] = "Syntaxe:"
loadfile("SlashCommands.lua")("DisenchantBuddy", DisenchantBuddy)
DisenchantBuddy.ProcessCommand("test")
assert.spy(_G.print).was.called_with("Syntaxe: /disenchantbuddy modifier ( shift | alt | control | off )")
end)
it("should print syntax help for unknown command", function()
DisenchantBuddy.ProcessCommand("test")
assert.spy(_G.print).was.called()
end)
end)
describe("IsModifierDown", function()
it("should return true when no modifier is set", function()
assert.is_true(DisenchantBuddy.IsModifierDown("INVALID"))
end)
it("should check shift key when modifier is SHIFT", function()
_G.IsShiftKeyDown = spy.new(function() return true end)
local result = DisenchantBuddy.IsModifierDown("SHIFT")
assert.is_true(result)
end)
it("should check alt key when modifier is ALT", function()
_G.IsAltKeyDown = spy.new(function() return true end)
local result = DisenchantBuddy.IsModifierDown("ALT")
assert.is_true(result)
end)
it("should check control key when modifier is CONTROL", function()
_G.IsControlKeyDown = spy.new(function() return true end)
local result = DisenchantBuddy.IsModifierDown("CONTROL")
assert.is_true(result)
end)
end)
end)