Add starts with operator (#5061)

* add starts_with operator

* added a test
This commit is contained in:
Darren Schroeder
2022-04-01 13:35:46 -05:00
committed by GitHub
parent a088081695
commit 2cb815b7b4
8 changed files with 68 additions and 0 deletions

View File

@ -376,6 +376,19 @@ pub(super) fn compute_series_single_value(
rhs_span: right.span()?,
}),
},
Operator::StartsWith => match &right {
Value::String { val, .. } => {
let starts_with_pattern = format!("^{}", val);
contains_series_pat(&lhs, &starts_with_pattern, lhs_span)
}
_ => Err(ShellError::OperatorMismatch {
op_span: operator.span,
lhs_ty: left.get_type(),
lhs_span: left.span()?,
rhs_ty: right.get_type(),
rhs_span: right.span()?,
}),
},
_ => Err(ShellError::OperatorMismatch {
op_span: operator.span,
lhs_ty: left.get_type(),