use ifc_lite_core::build_entity_index;
#[test]
fn in_string_semicolons_and_escaped_quotes_do_not_terminate_a_record() {
let content = b"ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n\
#1=IFCLABEL('a;b '' c;d');\n\
#2=IFCTEXT('plain');\n\
ENDSEC;\nEND-ISO-10303-21;\n";
let idx = build_entity_index(content);
assert!(idx.contains_key(&1), "entity #1 must be indexed");
assert!(idx.contains_key(&2), "entity #2 must be indexed");
let (s1, e1) = idx[&1];
let rec1 = std::str::from_utf8(&content[s1..e1]).unwrap();
assert!(
rec1.contains("c;d')"),
"record #1 was terminated early at an in-string ';': {rec1:?}"
);
assert!(
rec1.trim_end().ends_with(';'),
"record #1 must end at the record-terminating ';': {rec1:?}"
);
let (s2, e2) = idx[&2];
let rec2 = std::str::from_utf8(&content[s2..e2]).unwrap();
assert!(rec2.contains("IFCTEXT('plain')"), "record #2 wrong: {rec2:?}");
}
#[test]
fn trailing_escaped_quote_at_string_end_still_finds_the_terminator() {
let content = b"DATA;\n#1=IFCLABEL('ab''');\n#2=IFCLABEL('next');\nENDSEC;\n";
let idx = build_entity_index(content);
assert!(idx.contains_key(&1), "entity #1 must be indexed");
assert!(idx.contains_key(&2), "entity #2 must be indexed");
let (s2, e2) = idx[&2];
assert!(
std::str::from_utf8(&content[s2..e2]).unwrap().contains("'next'"),
"record #2 mis-indexed after a trailing escaped quote"
);
}