Skip to content

Commit fe64a36

Browse files
committed
add nil ref test case
1 parent 5b10e7f commit fe64a36

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/root.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3660,6 +3660,25 @@ test "ref and unref in user table" {
36603660
try std.testing.expectEqual(0, lua.lengthOf(1));
36613661
}
36623662

3663+
test "ref should return nil" {
3664+
const lua = try Lua.init(std.testing.allocator);
3665+
defer lua.deinit();
3666+
3667+
lua.newTable();
3668+
lua.pushNil();
3669+
const ref = lua.ref(1);
3670+
3671+
try std.testing.expectEqual(1, lua.getTop());
3672+
try std.testing.expectEqual(Lua.Ref.Nil, ref);
3673+
3674+
const t = lua.getTableIndexRaw(1, ref);
3675+
try std.testing.expectEqual(Lua.Type.nil, t);
3676+
try std.testing.expect(lua.isNil(-1));
3677+
3678+
lua.unref(1, ref);
3679+
try std.testing.expectEqual(0, lua.lengthOf(1));
3680+
}
3681+
36633682
test "ref and unref in registry" {
36643683
const lua = try Lua.init(std.testing.allocator);
36653684
defer lua.deinit();

0 commit comments

Comments
 (0)