mirror of
https://github.com/nushell/nushell.git
synced 2024-11-07 17:14:23 +01:00
working for comparing filepath to string (#2906)
* working for comparing filepath to string * added tests
This commit is contained in:
parent
93e8f6c05e
commit
231a445809
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -3156,18 +3156,6 @@ dependencies = [
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-core-commands"
|
||||
version = "0.25.1"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"eml-parser",
|
||||
"nu-errors",
|
||||
"nu-protocol",
|
||||
"nu-source",
|
||||
"serde 1.0.118",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-data"
|
||||
version = "0.25.1"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use nu_data::value;
|
||||
use nu_data::{value, value::compare_values};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::hir::Operator;
|
||||
use nu_protocol::{Primitive, ShellTypeName, UntaggedValue, Value};
|
||||
@ -79,9 +79,15 @@ fn table_contains(
|
||||
left: &UntaggedValue,
|
||||
right: &UntaggedValue,
|
||||
) -> Result<bool, (&'static str, &'static str)> {
|
||||
let left = left.clone();
|
||||
match right {
|
||||
UntaggedValue::Table(values) => Ok(values.iter().any(|x| x.value == left)),
|
||||
UntaggedValue::Table(values) => {
|
||||
Ok(values
|
||||
.iter()
|
||||
.any(|x| match compare_values(Operator::Equal, &left, &x.value) {
|
||||
Ok(coerced) => coerced,
|
||||
_ => false,
|
||||
}))
|
||||
}
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
}
|
||||
}
|
||||
|
1
crates/nu-engine/tests/evaluate/mod.rs
Normal file
1
crates/nu-engine/tests/evaluate/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
mod operator;
|
38
crates/nu-engine/tests/evaluate/operator.rs
Normal file
38
crates/nu-engine/tests/evaluate/operator.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use nu_test_support::fs::Stub::EmptyFile;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn filter_ls_by_in_array() {
|
||||
Playground::setup("filter_ls_by_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![
|
||||
EmptyFile("jean-luc.cap"),
|
||||
EmptyFile("riker.cmdr"),
|
||||
EmptyFile("data.ltcmdr"),
|
||||
EmptyFile("troi.ltcmdr"),
|
||||
EmptyFile("worf.lt"),
|
||||
EmptyFile("geordi.lt"),
|
||||
]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls | where name in ['data.ltcmdr', 'riker.cmdr'] | get name | to json
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[\"data.ltcmdr\",\"riker.cmdr\"]");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filter_json_with_in_array() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where size in [2] | get name
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "foo");
|
||||
}
|
3
crates/nu-engine/tests/main.rs
Normal file
3
crates/nu-engine/tests/main.rs
Normal file
@ -0,0 +1,3 @@
|
||||
extern crate nu_test_support;
|
||||
|
||||
mod evaluate;
|
Loading…
Reference in New Issue
Block a user