-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.lua
200 lines (156 loc) · 3.88 KB
/
tests.lua
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
local sharecart = require('sharecart')
if not sharecart.valid('.') then
error("tests aren't being run from a valid directory")
end
local cart_data = sharecart.load('.')
function setup()
cart_data.MapX = 0
cart_data.MapY = 0
cart_data.Misc0 = 0
cart_data.Misc1 = 0
cart_data.Misc2 = 0
cart_data.Misc3 = 0
cart_data.PlayerName = 'empty'
cart_data.Switch0 = false
cart_data.Switch1 = false
cart_data.Switch2 = false
cart_data.Switch3 = false
cart_data.Switch4 = false
cart_data.Switch5 = false
cart_data.Switch6 = false
cart_data.Switch7 = false
end
setup()
function should_fail(fn)
assert(not pcall(fn))
io.write('.')
end
function should_equal(a, b)
assert(a == b)
io.write('.')
end
-- Map keys
for _, k in ipairs({'MapX', 'MapY'}) do
-- integers in [0, 1023] should be saved
cart_data[k] = 512
should_equal(cart_data[k], 512)
cart_data[k] = 0
should_equal(cart_data[k], 0)
cart_data[k] = 1023
should_equal(cart_data[k], 1023)
-- anything less than 0 should fail
should_fail(function()
cart_data[k] = -1
end)
should_fail(function()
cart_data[k] = -512
end)
-- anything greater than 1023 should fail
should_fail(function()
cart_data[k] = 1024
end)
should_fail(function()
cart_data[k] = 65535
end)
-- booleans can't be saved to map keys
should_fail(function()
cart_data[k] = true
end)
should_fail(function()
cart_data[k] = false
end)
-- strings can't be saved to map keys
should_fail(function()
cart_data[k] = 'blah'
end)
-- should still have last saved value
should_equal(cart_data[k], 1023)
end
-- Misc keys
for _, k in ipairs({'Misc0', 'Misc1', 'Misc2', 'Misc3'}) do
-- integers in [0, 65535] should be saved
cart_data[k] = 1024
should_equal(cart_data[k], 1024)
cart_data[k] = 0
should_equal(cart_data[k], 0)
cart_data[k] = 65535
should_equal(cart_data[k], 65535)
-- anything less than 0 should fail
should_fail(function()
cart_data[k] = -1
end)
should_fail(function()
cart_data[k] = -512
end)
-- anything greater than 65535 should fail
should_fail(function()
cart_data[k] = 65536
end)
-- booleans can't be saved to map keys
should_fail(function()
cart_data[k] = true
end)
should_fail(function()
cart_data[k] = false
end)
-- strings can't be saved to map keys
should_fail(function()
cart_data[k] = 'blah'
end)
-- fractional numbers can't be saved to map keys
should_fail(function()
cart_data[k] = 0.1
end)
-- should still have last saved value
should_equal(cart_data[k], 65535)
end
-- PlayerName
cart_data.PlayerName = 'cool'
should_equal(cart_data.PlayerName, 'cool')
cart_data.PlayerName = 'other name'
should_equal(cart_data.PlayerName, 'other name')
-- booleans can't be saved to PlayerName
should_fail(function()
cart_data.PlayerName = true
end)
should_fail(function()
cart_data.PlayerName = false
end)
-- numbers can't be saved to PlayerName
should_fail(function()
cart_data.PlayerName = 0
end)
should_fail(function()
cart_data.PlayerName = 0.1
end)
-- should still have last saved value
should_equal(cart_data.PlayerName, 'other name')
-- Switches
for _, k in ipairs({'Switch0', 'Switch1', 'Switch2', 'Switch3', 'Switch4', 'Switch5', 'Switch6', 'Switch7'}) do
-- booleans can be written to Switches
cart_data[k] = true
should_equal(cart_data[k], true)
cart_data[k] = false
should_equal(cart_data[k], false)
-- numbers can't be saved to Switches
should_fail(function()
cart_data[k] = 0
end)
should_fail(function()
cart_data[k] = 0.1
end)
-- strings can't be saved to Switches
should_fail(function()
cart_data[k] = 'blah'
end)
-- should still have last saved value
should_equal(cart_data[k], false)
end
-- nonexistent keys should fail
should_fail(function()
cart_data.Garbage = 'garbage'
end)
should_fail(function()
cart_data.HotGarbage = true
end)
print('\nDone!')