refactor: Update filter parser tests to use get and as_str for options

Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-09-10 16:12:33 -03:00
parent 22cd07284b
commit 84bf7ac5f4

View File

@@ -108,24 +108,35 @@ mod tests {
let result = parse_filter_string("head_lines(10)").unwrap(); let result = parse_filter_string("head_lines(10)").unwrap();
assert_eq!(result.len(), 1); assert_eq!(result.len(), 1);
assert_eq!(result[0].name, "head_lines"); assert_eq!(result[0].name, "head_lines");
assert_eq!(result[0].options["head_lines"], 10); assert_eq!(result[0].options.len(), 1);
if let serde_json::Value::Number(n) = result[0].options.get("head_lines").unwrap() {
assert_eq!(n.as_i64(), Some(10));
} else {
panic!("Expected number");
}
} }
#[test] #[test]
fn test_parse_filter_with_named_options() { fn test_parse_filter_with_named_options() {
let result = parse_filter_string("grep(pattern=\"error\")").unwrap(); let result = parse_filter_string(r#"grep(pattern="error")"#).unwrap();
assert_eq!(result.len(), 1); assert_eq!(result.len(), 1);
assert_eq!(result[0].name, "grep"); assert_eq!(result[0].name, "grep");
assert_eq!(result[0].options["pattern"], "error"); assert_eq!(result[0].options.get("pattern").unwrap().as_str(), Some("error"));
} }
#[test] #[test]
fn test_parse_multiple_filters() { fn test_parse_multiple_filters() {
let result = parse_filter_string("head_lines(10)|grep(pattern=\"error\")").unwrap(); let result = parse_filter_string(r#"head_lines(10)|grep(pattern="error")"#).unwrap();
assert_eq!(result.len(), 2); assert_eq!(result.len(), 2);
assert_eq!(result[0].name, "head_lines"); assert_eq!(result[0].name, "head_lines");
assert_eq!(result[0].options["head_lines"], 10); assert_eq!(result[0].options.len(), 1);
if let serde_json::Value::Number(n) = result[0].options.get("head_lines").unwrap() {
assert_eq!(n.as_i64(), Some(10));
} else {
panic!("Expected number");
}
assert_eq!(result[1].name, "grep"); assert_eq!(result[1].name, "grep");
assert_eq!(result[1].options["pattern"], "error"); assert_eq!(result[1].options.len(), 1);
assert_eq!(result[1].options.get("pattern").unwrap().as_str(), Some("error"));
} }
} }