diff --git a/src/context.rs b/src/context.rs index f0fdf69..27650a8 100644 --- a/src/context.rs +++ b/src/context.rs @@ -931,7 +931,18 @@ pub async fn set_values_in_context_one( len } - _ => 1, + _ => match &lst0[i + 1] { + Syntax::ValStr(s) if s.len() > 0 => { + let s: Vec = s.chars().collect(); + match str1.windows(s.len()).position(|x| x == s) { + Some(idx) => idx, + None => { + return ComparisonResult::Matched(false); + } + } + } + _ => 1, + }, }; let c: String = str1.drain(0..len).collect(); diff --git a/src/tests/execute.rs b/src/tests/execute.rs index 97ec476..cdd250b 100644 --- a/src/tests/execute.rs +++ b/src/tests/execute.rs @@ -2310,3 +2310,61 @@ async fn test_infinite_match_map() { .await ); } + +#[tokio::test] +async fn test_contains_string() { + assert_eq!( + Ok("\"xy\"".to_string()), + parse_to_str( + "if let [x:\"test\":y] = \"xtesty\" then x + y else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); + assert_eq!( + Ok("\"x\"".to_string()), + parse_to_str( + "if let [x:\"test\":y] = \"xtest\" then x + y else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); + assert_eq!( + Ok("\"x01y\"".to_string()), + parse_to_str( + "if let [x:\"test\":y] = \"x0test1y\" then x + y else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); + assert_eq!( + Ok("(\"x0\", \"1y\")".to_string()), + parse_to_str( + "if let [x:\"test\":y] = \"x0test1y\" then (x, y) else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); + assert_eq!( + Ok("@false".to_string()), + parse_to_str( + "if let [x:\"test\":y] = \"x0tes1y\" then x + y else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); + assert_eq!( + Ok("((\"x\", \"0\"), \"1y\")".to_string()), + parse_to_str( + "if let [z:x:\"test\":y] = \"x0test1y\" then (z, x, y) else @false", + &mut ContextHandler::async_default().await, + &mut SystemHandler::default() + ) + .await + ); +}