mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 07:05:47 +02:00
Add not-in: operator (#1661)
This commit is contained in:
@ -26,6 +26,7 @@ pub fn apply_operator(
|
||||
Operator::Multiply => value::compute_values(op, left, right),
|
||||
Operator::Divide => value::compute_values(op, left, right),
|
||||
Operator::In => table_contains(left, right).map(UntaggedValue::boolean),
|
||||
Operator::NotIn => table_contains(left, right).map(|x| UntaggedValue::boolean(!x)),
|
||||
Operator::And => match (left.as_bool(), right.as_bool()) {
|
||||
(Ok(left), Ok(right)) => Ok(UntaggedValue::boolean(left && right)),
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
|
@ -20,6 +20,26 @@ fn filters_with_nothing_comparison() {
|
||||
assert_eq!(actual, "7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from-json | where name in: ["foo"] | get size | sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual, "5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn where_not_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from-json | where name not-in: ["foo"] | get size | sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_block_condition() {
|
||||
let actual = nu!(
|
||||
|
Reference in New Issue
Block a user