forked from teal-language/tl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfornum_spec.lua
More file actions
97 lines (85 loc) · 2.04 KB
/
Copy pathfornum_spec.lua
File metadata and controls
97 lines (85 loc) · 2.04 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
local util = require("spec.util")
describe("fornum", function()
it("5.3: doesn't generate control variable that is local to the iteration", util.gen([[
local t: {string} = { "a", "b", "c" }
for i = 1, #t do
i = i + 1
print(t[i])
end
]], [[
local t = { "a", "b", "c" }
for i = 1, #t do
i = i + 1
print(t[i])
end
]], "5.3"))
it("5.4: generates control variable that is local to the iteration", util.gen([[
local t: {string} = { "a", "b", "c" }
for i = 1, #t do
i = i + 1
print(t[i])
end
]], [[
local t = { "a", "b", "c" }
for i = 1, #t do local i = i
i = i + 1
print(t[i])
end
]], "5.4"))
it("5.4: does not generate control variable if not assigned to", util.gen([[
local t: {string} = { "a", "b", "c" }
for i = 1, #t do
local j = i + 1
print(t[j])
end
]], [[
local t = { "a", "b", "c" }
for i = 1, #t do
local j = i + 1
print(t[j])
end
]], "5.4"))
it("5.4: generates control variable for a loop with a step", util.gen([[
for i = 10, 1, -2 do
i = i // 2
print(i)
end
]], [[
for i = 10, 1, -2 do local i = i
i = i // 2
print(i)
end
]], "5.4"))
it("5.4: detects an assignment made from a nested function", util.gen([[
for i = 1, 3 do
local function bump()
i = i + 1
end
bump()
print(i)
end
]], [[
for i = 1, 3 do local i = i
local function bump()
i = i + 1
end
bump()
print(i)
end
]], "5.4"))
it("5.4: only shadows the loops that are assigned to", util.gen([[
for i = 1, 3 do
for j = 1, 3 do
j = j + 1
print(i, j)
end
end
]], [[
for i = 1, 3 do
for j = 1, 3 do local j = j
j = j + 1
print(i, j)
end
end
]], "5.4"))
end)