-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from svermeulen/sverm/infinite-loop-fix
Fix for the very common infinite loop issue, when forgetting to call getIterator
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
describe("for loop usage", function() | ||
local linq = require("lazylualinq") | ||
|
||
it("throws error when getIterator is not called", function() | ||
local seq = linq { 1, 2, 3 } | ||
|
||
assert.has_error(function() | ||
for _x in seq do | ||
end | ||
end) | ||
|
||
local items = {} | ||
for x in seq() do | ||
table.insert(items, x) | ||
end | ||
|
||
assert.is_same(#items, 3) | ||
assert.is_same(items[1], 1) | ||
assert.is_same(items[2], 2) | ||
assert.is_same(items[3], 3) | ||
|
||
items = {} | ||
for x in seq:getIterator() do | ||
table.insert(items, x) | ||
end | ||
|
||
assert.is_same(#items, 3) | ||
assert.is_same(items[1], 1) | ||
assert.is_same(items[2], 2) | ||
assert.is_same(items[3], 3) | ||
end) | ||
end) |