add in a new select test that exercises a different match arm of the select command (#718)

This commit is contained in:
Michael Angerman 2022-01-10 13:29:52 -08:00 committed by GitHub
parent d3bfc61524
commit 160339bd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 63 deletions

View File

@ -133,65 +133,3 @@ fn select(
_ => Ok(PipelineData::new(span)),
}
}
// #[cfg(test)]
// mod tests {
// use nu_protocol::ColumnPath;
// use nu_source::Span;
// use nu_source::SpannedItem;
// use nu_source::Tag;
// use nu_stream::InputStream;
// use nu_test_support::value::nothing;
// use nu_test_support::value::row;
// use nu_test_support::value::string;
// use super::select;
// use super::Command;
// use super::ShellError;
// #[test]
// fn examples_work_as_expected() -> Result<(), ShellError> {
// use crate::examples::test as test_examples;
// test_examples(Command {})
// }
// #[test]
// fn select_using_sparse_table() {
// // Create a sparse table with 3 rows:
// // col_foo | col_bar
// // -----------------
// // foo |
// // | bar
// // foo |
// let input = vec![
// row(indexmap! {"col_foo".into() => string("foo")}),
// row(indexmap! {"col_bar".into() => string("bar")}),
// row(indexmap! {"col_foo".into() => string("foo")}),
// ];
// let expected = vec![
// row(
// indexmap! {"col_none".into() => nothing(), "col_foo".into() => string("foo"), "col_bar".into() => nothing()},
// ),
// row(
// indexmap! {"col_none".into() => nothing(), "col_foo".into() => nothing(), "col_bar".into() => string("bar")},
// ),
// row(
// indexmap! {"col_none".into() => nothing(), "col_foo".into() => string("foo"), "col_bar".into() => nothing()},
// ),
// ];
// let actual = select(
// Tag::unknown(),
// vec![
// ColumnPath::build(&"col_none".to_string().spanned(Span::test_data())),
// ColumnPath::build(&"col_foo".to_string().spanned(Span::test_data())),
// ColumnPath::build(&"col_bar".to_string().spanned(Span::test_data())),
// ],
// input.into(),
// );
// assert_eq!(Ok(expected), actual.map(InputStream::into_vec));
// }
// }

View File

@ -186,13 +186,21 @@ fn get() -> TestResult {
}
#[test]
fn select() -> TestResult {
fn select_1() -> TestResult {
run_test(
r#"([[name, age]; [a, 1], [b, 2]]) | select name | get 1 | get name"#,
"b",
)
}
#[test]
fn select_2() -> TestResult {
run_test(
r#"[[name, age]; [a, 1] [b, 2]] | get 1 | select age | get age"#,
"2",
)
}
#[test]
fn update_will_insert() -> TestResult {
run_test(r#"{} | update a b | get a"#, "b")