use crate::llm::json_parsing::*;
fn value_of(extracted: Option<Extracted>) -> Value {
match extracted {
Some(Extracted::Truncated(v)) => v,
other => panic!("expected Truncated, got {other:?}"),
}
}
#[test]
fn three_unclosed_braces_need_three_closers() {
let v = value_of(extract_json(r#"{"a":{"b":{"c":1"#));
assert_eq!(v["a"]["b"]["c"], 1, "all three levels must survive");
}
#[test]
fn nested_unclosed_brackets_need_matching_closers() {
let v = value_of(extract_json(r#"{"xs":[[1,2],[3"#));
assert_eq!(v["xs"][0][0], 1);
assert_eq!(
v["xs"][1][0], 3,
"the inner array must close before the outer"
);
}
#[test]
fn braces_and_brackets_are_counted_separately() {
let v = value_of(extract_json(r#"{"xs":[{"k":1"#));
assert_eq!(v["xs"][0]["k"], 1);
}
#[test]
fn braces_inside_strings_are_not_structural() {
let v = value_of(extract_json(r#"{"msg":"a { brace","n":1"#));
assert_eq!(v["msg"], "a { brace");
assert_eq!(v["n"], 1);
}
#[test]
fn escaped_quotes_do_not_end_the_string() {
let v = value_of(extract_json(r#"{"m":"x\"[[[","n":1"#));
assert_eq!(v["m"], r#"x"[[["#);
assert_eq!(v["n"], 1);
}
#[test]
fn an_escaped_backslash_does_not_swallow_the_closing_quote() {
let v = value_of(extract_json(r#"{"path":"C:\\","n":2"#));
assert_eq!(v["path"], r"C:\");
assert_eq!(v["n"], 2);
}