Skip to content

Commit

Permalink
add tests for "loosy" tables
Browse files Browse the repository at this point in the history
  • Loading branch information
amtoine committed Jul 14, 2024
1 parent 73aef28 commit 62eee55
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/nu/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ mod tests {
"{} should be a table",
default_value_repr(&table)
);

assert_eq!(
is_table(&table, true),
Table::IsValid,
"{} should be a loose table",
default_value_repr(&table)
);
}

let not_a_table_missing_field = (
Expand Down Expand Up @@ -617,6 +624,26 @@ mod tests {
);
}

let loosy_table_incompatible_types = Value::test_list(vec![
Value::test_record(record! {
"a" => Value::test_string("a"),
"b" => Value::test_int(1),
}),
Value::test_record(record! {
"a" => Value::test_string("a"),
"b" => Value::test_list(vec![Value::test_int(1)]),
}),
]);

for loosy_table in [loosy_table_incompatible_types] {
assert_eq!(
is_table(&loosy_table, true),
Table::IsValid,
"{} should be a loose table",
default_value_repr(&loosy_table)
);
}

assert_eq!(is_table(&Value::test_int(0), false), Table::NotAList);
assert_eq!(is_table(&Value::test_list(vec![]), false), Table::Empty);
}
Expand Down

0 comments on commit 62eee55

Please sign in to comment.