mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Add new operators has
and not-has
(#14841)
# Description This PR add 2 new operators, `has` and `not-has`. They are basically `in` and `not-in` with the order of operands swapped. Motivation for this was the awkward way of searching for rows that contain an item using `where` ```nushell [[name, children]; [foo, [a, b, c]], [bar [d, e, f]]] | where ("e" in $it.children) ``` vs ```nushell [[name, children]; [foo, [a, b, c]], [bar [d, e, f]]] | where children has "e" ``` # User-Facing Changes Added `has` and `not-has` operators, mirroring `in` and `not-in`. # Tests + Formatting - 🟢 toolkit fmt - 🟢 toolkit clippy - 🟢 toolkit test - 🟢 toolkit test stdlib # After Submitting
This commit is contained in:
@ -187,3 +187,25 @@ fn where_gt_null() {
|
||||
let actual = nu!("[{foo: 123} {}] | where foo? > 10 | to nuon");
|
||||
assert_eq!(actual.out, "[[foo]; [123]]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn has_operator() {
|
||||
let actual = nu!(
|
||||
r#"[[name, children]; [foo, [a, b]], [bar [b, c]], [baz, [c, d]]] | where children has "a" | to nuon"#
|
||||
);
|
||||
assert_eq!(actual.out, r#"[[name, children]; [foo, [a, b]]]"#);
|
||||
|
||||
let actual = nu!(
|
||||
r#"[[name, children]; [foo, [a, b]], [bar [b, c]], [baz, [c, d]]] | where children not-has "a" | to nuon"#
|
||||
);
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
r#"[[name, children]; [bar, [b, c]], [baz, [c, d]]]"#
|
||||
);
|
||||
|
||||
let actual = nu!(r#"{foo: 1} has foo"#);
|
||||
assert_eq!(actual.out, "true");
|
||||
|
||||
let actual = nu!(r#"{foo: 1} has bar "#);
|
||||
assert_eq!(actual.out, "false");
|
||||
}
|
||||
|
Reference in New Issue
Block a user