Add Tests for Optional Params with Empty Default (Fixed in v1.0.24) (#2567)

Co-authored-by: Yingjie He <yingjiehe@squareup.com>
Co-authored-by: Yingjie He <yingjiehe@block.xyz>
This commit is contained in:
Greg Knoblauch
2025-05-19 13:25:02 -06:00
committed by GitHub
parent 58cf6b48f8
commit 1b6209d0b2
+28
View File
@@ -295,6 +295,13 @@ mod tests {
let result = render_content_with_params(content, &params).unwrap();
assert_eq!(result, "Hello World!");
// Test empty parameter substitution
let content = "Hello {{ empty }}!";
let mut params = HashMap::new();
params.insert("empty".to_string(), "".to_string());
let result = render_content_with_params(content, &params).unwrap();
assert_eq!(result, "Hello !");
// Test multiple parameters
let content = "{{ greeting }} {{ name }}!";
let mut params = HashMap::new();
@@ -444,6 +451,27 @@ mod tests {
);
}
#[test]
fn test_load_recipe_as_template_optional_parameters_with_empty_default_values_in_recipe_file() {
let instructions_and_parameters = r#"
"instructions": "Test instructions with {{ optional_param }}",
"parameters": [
{
"key": "optional_param",
"input_type": "string",
"requirement": "optional",
"description": "A test parameter",
"default": "",
}
]"#;
let (_temp_dir, recipe_path) = setup_recipe_file(instructions_and_parameters);
let recipe = load_recipe_as_template(recipe_path.to_str().unwrap(), Vec::new()).unwrap();
assert_eq!(recipe.title, "Test Recipe");
assert_eq!(recipe.description, "A test recipe");
assert_eq!(recipe.instructions.unwrap(), "Test instructions with ");
}
#[test]
fn test_load_recipe_as_template_optional_parameters_without_default_values_in_recipe_file() {
let instructions_and_parameters = r#"