Blank-lines guard test for the generator

The reported symptom (a blank line after every line of generated
source) was investigated Nov 29, 2026 and does NOT reproduce in the
current generator: all 16 gen_matrix cases measure a
blank-after-content ratio of 0.01-0.06 (section separators only),
while double-spaced output scores ~1.0. This test pins the clean
output so a regression fails loudly: it generates all 16 cases and
asserts every main.cpp has a blank-after-content ratio < 0.20.
Verified: passes on clean output; the same ratio function fails a
double-spaced file at 0.99 (checked via the C guard script).
This commit is contained in:
cnmcdee committed 2026-11-30 03:59:10 +00:00
1 parent 1ae85cd6c3
commit cee17059a3
1 file changed
+51
@@ -445,6 +445,57 @@ fn compare_case(out_base: &Path, name: &str, project: &Project) {
}
}
/// Blank-lines guard: generated source must not have a blank line after
/// every line (double-spaced output). Clean output uses blank lines
/// only as section separators (measured ratio 0.01-0.06 across the 16
/// cases); double-spaced output scores ~1.0. Threshold 0.20.
/// The symptom was investigated Nov 29, 2026 and does not reproduce
/// in the current generator; this test pins the clean output.
fn blank_after_ratio(text: &str) -> f64 {
let mut lines: Vec<&str> = text.split('\n').collect();
if let Some(last) = lines.last() {
if last.is_empty() {
lines.pop();
}
}
let mut content = 0usize;
let mut blank_after = 0usize;
for (i, line) in lines.iter().enumerate() {
if !line.trim().is_empty() {
content += 1;
if i + 1 < lines.len() && lines[i + 1].trim().is_empty() {
blank_after += 1;
}
}
}
if content == 0 {
return 0.0;
}
blank_after as f64 / content as f64
}
#[test]
fn generated_source_has_no_blank_lines() {
let out_base = std::env::temp_dir().join("lightgui-gen-blank-guard");
let _ = std::fs::remove_dir_all(&out_base);
std::fs::create_dir_all(&out_base).unwrap();
let cases = build_cases();
assert_eq!(cases.len(), 16);
for (name, project) in &cases {
let out_case = out_base.join(name);
let widgets = project.widgets.clone();
let r = generate_project(project, &widgets, &out_case);
assert!(r.ok, "case {name}: generation failed: {}", r.error);
let main_cpp = std::fs::read_to_string(out_case.join("main.cpp"))
.unwrap_or_else(|_| panic!("case {name}: no main.cpp"));
let ratio = blank_after_ratio(&main_cpp);
assert!(
ratio < 0.20,
"case {name}: main.cpp blank-after-content ratio {ratio:.2} (>= 0.20)"
);
}
}
#[test]
fn generator_matches_cpp_fixtures() {
let out_base = std::env::temp_dir().join("lightgui-gen-fixture-test");