mirror of
https://github.com/nushell/nushell.git
synced 2025-04-10 14:08:40 +02:00
Support in
operator for record and value stream
This commit is contained in:
parent
7db6b876ab
commit
7f06d6144f
@ -277,6 +277,7 @@ pub fn math_result_type(
|
|||||||
(t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None),
|
(t, Type::List(u)) if type_compatible(t, u) => (Type::Bool, None),
|
||||||
(Type::Int | Type::Float, Type::Range) => (Type::Bool, None),
|
(Type::Int | Type::Float, Type::Range) => (Type::Bool, None),
|
||||||
(Type::String, Type::String) => (Type::Bool, None),
|
(Type::String, Type::String) => (Type::Bool, None),
|
||||||
|
(Type::String, Type::Record(_, _)) => (Type::Bool, None),
|
||||||
|
|
||||||
(Type::Unknown, _) => (Type::Bool, None),
|
(Type::Unknown, _) => (Type::Bool, None),
|
||||||
(_, Type::Unknown) => (Type::Bool, None),
|
(_, Type::Unknown) => (Type::Bool, None),
|
||||||
|
@ -1066,9 +1066,25 @@ impl Value {
|
|||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
(lhs, Value::List { vals: rhs, .. }) => Ok(Value::Bool {
|
(lhs, Value::List { vals: rhs, .. }) => Ok(Value::Bool {
|
||||||
val: rhs
|
val: rhs.iter().any(|x| {
|
||||||
.iter()
|
matches!(
|
||||||
.any(|x| lhs.eq(Span::unknown(), x).map_or(false, |v| v.is_true())),
|
lhs.eq(Span::unknown(), x),
|
||||||
|
Ok(Value::Bool { val: true, .. })
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
span,
|
||||||
|
}),
|
||||||
|
(Value::String { val: lhs, .. }, Value::Record { cols: rhs, .. }) => Ok(Value::Bool {
|
||||||
|
val: rhs.contains(lhs),
|
||||||
|
span,
|
||||||
|
}),
|
||||||
|
(lhs, Value::Stream { stream: rhs, .. }) => Ok(Value::Bool {
|
||||||
|
val: rhs.clone().any(|x| {
|
||||||
|
matches!(
|
||||||
|
lhs.eq(Span::unknown(), &x),
|
||||||
|
Ok(Value::Bool { val: true, .. })
|
||||||
|
)
|
||||||
|
}),
|
||||||
span,
|
span,
|
||||||
}),
|
}),
|
||||||
_ => Err(ShellError::OperatorMismatch {
|
_ => Err(ShellError::OperatorMismatch {
|
||||||
|
23
src/tests.rs
23
src/tests.rs
@ -608,3 +608,26 @@ fn int_in_exclusive_range() -> TestResult {
|
|||||||
fn non_number_in_range() -> TestResult {
|
fn non_number_in_range() -> TestResult {
|
||||||
fail_test(r#"'a' in 1..3"#, "mismatched for operation")
|
fail_test(r#"'a' in 1..3"#, "mismatched for operation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_in_record() -> TestResult {
|
||||||
|
run_test(r#""a" in ('{ "a": 13, "b": 14 }' | from json)"#, "true")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_string_in_record() -> TestResult {
|
||||||
|
fail_test(
|
||||||
|
r#"4 in ('{ "a": 13, "b": 14 }' | from json)"#,
|
||||||
|
"mismatch during operation",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_in_valuestream() -> TestResult {
|
||||||
|
run_test(
|
||||||
|
r#"
|
||||||
|
'Hello' in ("Hello
|
||||||
|
World" | lines)"#,
|
||||||
|
"true",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user