summaryrefslogtreecommitdiff
path: root/tests/modules/for_loop
diff options
context:
space:
mode:
authorruki <[email protected]>2026-04-15 00:46:49 +0800
committerruki <[email protected]>2026-04-15 00:46:49 +0800
commit03133fa624c9f27554b0c393e9151213cc99996e (patch)
tree4a2848daefc54915560b8605785a91f8dfdb28e0 /tests/modules/for_loop
parent088cae88b4600bde070c73b9e218712195fe77ee (diff)
fix review issue
Diffstat (limited to 'tests/modules/for_loop')
-rw-r--r--tests/modules/for_loop/test.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/modules/for_loop/test.lua b/tests/modules/for_loop/test.lua
index 231337a29..42217ed40 100644
--- a/tests/modules/for_loop/test.lua
+++ b/tests/modules/for_loop/test.lua
@@ -114,6 +114,41 @@ function test_hashset_items_reassign(t)
end
end
+function test_hashset_items_skip_nil_member(t)
+ -- A nil member lives in hashset under the `_NIL` sentinel; iteration
+ -- must skip it rather than terminate, so real entries after it are
+ -- still visited regardless of `next`'s order.
+ local set = hashset.new()
+ set:insert("a")
+ set:insert(nil)
+ set:insert("b")
+ set:insert("c")
+ local seen = {}
+ for item in set:items() do
+ seen[item] = true
+ end
+ local count = 0
+ for _ in pairs(seen) do count = count + 1 end
+ t:require(count == 3)
+ t:require(seen.a and seen.b and seen.c)
+end
+
+function test_hashset_orderitems_skip_nil_member(t)
+ -- use numeric members so the existing orderitems sort (which coerces
+ -- `_NIL` to math.inf) stays within one comparable type.
+ local set = hashset.new()
+ set:insert(1)
+ set:insert(nil)
+ set:insert(2)
+ set:insert(3)
+ local collected = {}
+ for item in set:orderitems() do
+ table.insert(collected, item)
+ end
+ t:require(#collected == 3)
+ t:require(collected[1] == 1 and collected[2] == 2 and collected[3] == 3)
+end
+
function test_ipairs_reassign_index(t)
-- With the stock Lua 5.4 `ipairs`, writing to the first loop variable
-- would silently shift the index on the next iteration (no error,