aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/executor.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/executor.rs b/src/executor.rs
index b296c65..14f0927 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -33,7 +33,7 @@ impl Context {
pub fn substitute(&self, string: &str) -> String {
let mut buffer = string.to_string();
- let re = Regex::new(r"\{(?P<key>[A-Za-z0-9_]+)(?::-(?P<value>.*))?\}").unwrap();
+ let re = Regex::new(r"\{(?P<key>[A-Za-z0-9_]+)(?::-(?P<value>.*?))?\}").unwrap();
let empty_string = String::from("");
for var in re.captures_iter(string) {
@@ -254,6 +254,18 @@ mod tests_context {
}
#[test]
+ fn test_context_substitute_multi_value_with_default() {
+ let vars: Vec<(String, String)> = vec![(String::from("chewie"), String::from("han"))];
+ let ctx = Context::new(vars.into_iter());
+ assert_eq!(
+ ctx.substitute(&String::from(
+ "blah blah {chewie:-wookie} {c3po:-r2d2} blah"
+ )),
+ String::from("blah blah han r2d2 blah")
+ );
+ }
+
+ #[test]
fn test_context_substitute_empty_default() {
let vars: Vec<(String, String)> = vec![];
let ctx = Context::new(vars.into_iter());