Skip to content

Commit 2beca6e

Browse files
committed
Add test for Table::for_each_value
1 parent 09da7a4 commit 2beca6e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/table.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,22 @@ fn test_table_for_each() -> Result<()> {
272272
Ok(())
273273
}
274274

275+
#[test]
276+
fn test_table_for_each_value() -> Result<()> {
277+
let lua = Lua::new();
278+
279+
let table = lua.load("{1, 2, 3, 4, 5, nil, 7}").eval::<Table>()?;
280+
let mut sum = 0;
281+
table.for_each_value::<i32>(|v| {
282+
sum += v;
283+
Ok(())
284+
})?;
285+
// Iterations stops at the first nil
286+
assert_eq!(sum, 1 + 2 + 3 + 4 + 5);
287+
288+
Ok(())
289+
}
290+
275291
#[test]
276292
fn test_table_scope() -> Result<()> {
277293
let lua = Lua::new();

0 commit comments

Comments
 (0)