Add test for Table::for_each_value

This commit is contained in:
Alex Orlenko
2025-09-12 11:49:19 +01:00
parent 09da7a41e5
commit 2beca6ebe1
+16
View File
@@ -272,6 +272,22 @@ fn test_table_for_each() -> Result<()> {
Ok(())
}
#[test]
fn test_table_for_each_value() -> Result<()> {
let lua = Lua::new();
let table = lua.load("{1, 2, 3, 4, 5, nil, 7}").eval::<Table>()?;
let mut sum = 0;
table.for_each_value::<i32>(|v| {
sum += v;
Ok(())
})?;
// Iterations stops at the first nil
assert_eq!(sum, 1 + 2 + 3 + 4 + 5);
Ok(())
}
#[test]
fn test_table_scope() -> Result<()> {
let lua = Lua::new();