mirror of
https://github.com/storytold/designcraft.git
synced 2026-11-16 07:12:43 +00:00
Apply review fixes
- crates/engine/src/script.rs
This commit is contained in:
1 parent
8b9f297181
commit
6914f12209
1 file changed
+3
-2
@@ -51,7 +51,7 @@ pub fn parse(text: &str) -> Result<Vec<Step>, String> {
|
||||
let (id, rest) = l.split_at(split);
|
||||
let rest = rest.trim_start_matches(['=', ' ', '\t']).trim();
|
||||
let params = if rest.is_empty() { Ok(json!({})) } else { serde_json::from_str(rest).map_err(|e| e.to_string()) };
|
||||
params.and_then(|params: Value| {
|
||||
params.map(|p: Value| if p.is_null() { json!({}) } else { p }).and_then(|params: Value| {
|
||||
if params.is_object() { Ok(Step { command: id.to_string(), params }) } else { Err("`params` must be an object".to_string()) }
|
||||
})
|
||||
};
|
||||
@@ -199,10 +199,11 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn compact_lines_require_object_params() {
|
||||
for bad in ["a.b 5", "a.b [1]", "a.b \"x\"", "a.b=true", "a.b null"] {
|
||||
for bad in ["a.b 5", "a.b [1]", "a.b \"x\"", "a.b=true"] {
|
||||
assert_eq!(parse(bad), Err("line 1: `params` must be an object".to_string()), "{bad}");
|
||||
}
|
||||
assert_eq!(parse("\na.b={\"x\":1}").unwrap()[0].params, json!({"x": 1}));
|
||||
assert_eq!(parse("a.b null").unwrap()[0].params, json!({}));
|
||||
}
|
||||
|
||||
/// Windows editors and PowerShell 5.1 save "UTF-8 with BOM" with CRLF line endings; the BOM
|
||||
|
||||
Reference in new issue
Block a user