#![cfg(all(feature = "grammars", feature = "lang-qvr"))]
#![allow(clippy::expect_used, clippy::unwrap_used)]
use panproto_parse::ParserRegistry;
const QVR_MULTI_STEP: &[u8] = b"\
program p : X -> X:
sample a <- f()
sample b <- g()
return a
";
#[test]
fn emit_pretty_preserves_every_step_in_field_repeat() {
let reg = ParserRegistry::new();
let schema = reg
.parse_with_protocol("qvr", QVR_MULTI_STEP, "multi.qvr")
.expect("parse");
let rendered = reg
.emit_pretty_with_protocol("qvr", &schema)
.expect("emit_pretty");
let text = String::from_utf8(rendered).expect("utf8");
let f_calls = text.matches("f(").count();
let g_calls = text.matches("g(").count();
assert_eq!(
f_calls, 1,
"first step's function call f() missing from {text:?}"
);
assert_eq!(
g_calls, 1,
"second step's function call g() missing from {text:?} \
(FIELD(REPEAT) regression: second step was dropped before this fix)"
);
assert!(text.contains("return"), "return step missing from {text:?}");
}
const QVR_MULTI_ARG: &[u8] = b"\
program p : X -> X:
sample a <- f(1.0, 2.0, 3.0)
return a
";
#[test]
fn emit_pretty_preserves_every_arg_in_field_commasep1() {
let reg = ParserRegistry::new();
let schema = reg
.parse_with_protocol("qvr", QVR_MULTI_ARG, "args.qvr")
.expect("parse");
let rendered = reg
.emit_pretty_with_protocol("qvr", &schema)
.expect("emit_pretty");
let text = String::from_utf8(rendered).expect("utf8");
for arg in ["1.0", "2.0", "3.0"] {
assert!(
text.contains(arg),
"rendered output is missing arg {arg:?}; commaSep1 regression: {text:?}",
);
}
}