diff --git a/crates/nu-engine/src/evaluate/operator.rs b/crates/nu-engine/src/evaluate/operator.rs index 4cea18f20f..c6318382d0 100644 --- a/crates/nu-engine/src/evaluate/operator.rs +++ b/crates/nu-engine/src/evaluate/operator.rs @@ -55,8 +55,8 @@ pub fn apply_operator( )), _ => res, }), - Operator::In => table_contains(left, right).map(UntaggedValue::boolean), - Operator::NotIn => table_contains(left, right).map(|x| UntaggedValue::boolean(!x)), + Operator::In => inside_of(left, right).map(UntaggedValue::boolean), + Operator::NotIn => inside_of(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())), @@ -89,12 +89,12 @@ fn string_contains( } } -fn table_contains( +fn inside_of( left: &UntaggedValue, right: &UntaggedValue, ) -> Result { - match right { - UntaggedValue::Table(values) => { + match (left, right) { + (_, UntaggedValue::Table(values)) => { Ok(values .iter() .any(|x| match compare_values(Operator::Equal, left, &x.value) { @@ -102,6 +102,10 @@ fn table_contains( _ => false, })) } + ( + UntaggedValue::Primitive(Primitive::String(lhs)), + UntaggedValue::Primitive(Primitive::String(rhs)), + ) => Ok(rhs.contains(lhs)), _ => Err((left.type_name(), right.type_name())), } } diff --git a/crates/nu-protocol/src/return_value.rs b/crates/nu-protocol/src/return_value.rs index 01a89a431b..f097c60443 100644 --- a/crates/nu-protocol/src/return_value.rs +++ b/crates/nu-protocol/src/return_value.rs @@ -130,7 +130,8 @@ mod tests { #[test] fn return_value_can_be_used_in_assert_eq() { - let v: ReturnValue = ReturnSuccess::value(UntaggedValue::nothing()); - assert_eq!(v, v); + let v1: ReturnValue = ReturnSuccess::value(UntaggedValue::nothing()); + let v2: ReturnValue = ReturnSuccess::value(UntaggedValue::nothing()); + assert_eq!(v1, v2); } } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 789b5d9e79..108421b5d7 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -679,6 +679,31 @@ fn negative_decimal_start() { assert_eq!(actual.out, "2.7"); } + +#[test] +fn string_inside_of() { + let actual = nu!( + cwd: ".", + r#" + "bob" in "bobby" + "# + ); + + assert_eq!(actual.out, "true"); +} + +#[test] +fn string_not_inside_of() { + let actual = nu!( + cwd: ".", + r#" + "bob" not-in "bobby" + "# + ); + + assert_eq!(actual.out, "false"); +} + #[test] fn index_row() { let actual = nu!(