Add tests for get_data_by_key (#2658)

* Add test for get_data_by_key

* Apply same order for ValuExt impl

* Nothing helper for tests

* Use get_data_by_key from ValueExt
This commit is contained in:
Chris Gillespie
2020-10-12 20:46:58 -07:00
committed by GitHub
parent 95e61773a5
commit 38bdb053d2
6 changed files with 63 additions and 19 deletions

View File

@ -97,14 +97,6 @@ impl ValueExt for Value {
insert_data_at_member(self, member, new_value)
}
fn insert_data_at_column_path(
&self,
split_path: &ColumnPath,
new_value: Value,
) -> Result<Value, ShellError> {
insert_data_at_column_path(self, split_path, new_value)
}
fn forgiving_insert_data_at_column_path(
&self,
split_path: &ColumnPath,
@ -113,6 +105,14 @@ impl ValueExt for Value {
forgiving_insert_data_at_column_path(self, split_path, new_value)
}
fn insert_data_at_column_path(
&self,
split_path: &ColumnPath,
new_value: Value,
) -> Result<Value, ShellError> {
insert_data_at_column_path(self, split_path, new_value)
}
fn replace_data_at_column_path(
&self,
split_path: &ColumnPath,
@ -911,4 +911,43 @@ mod tests {
*string("Arepas de Yehuda")
);
}
#[test]
fn get_row_data_by_key() {
let row = row(indexmap! {
"lines".to_string() => int(0),
"words".to_string() => int(7),
});
assert_eq!(
row.get_data_by_key("lines".spanned_unknown()).unwrap(),
int(0)
);
assert!(row.get_data_by_key("chars".spanned_unknown()).is_none());
}
#[test]
fn get_table_data_by_key() {
let row1 = row(indexmap! {
"lines".to_string() => int(0),
"files".to_string() => int(10),
});
let row2 = row(indexmap! {
"files".to_string() => int(1)
});
let table_value = table(&[row1, row2]);
assert_eq!(
table_value
.get_data_by_key("files".spanned_unknown())
.unwrap(),
table(&[int(10), int(1)])
);
assert_eq!(
table_value
.get_data_by_key("chars".spanned_unknown())
.unwrap(),
table(&[nothing(), nothing()])
);
}
}