Merge pull request #10430 from dotCooCoo/fix/format-test-tolerances

Tests: format tests check exact values instead of wide tolerances
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-01 03:16:25 -08:00
commit c3c545dc69
5 files changed
+29 -8

No files matched your search

+1 -1
View File
@@ -457,7 +457,7 @@ mod tests {
n.transform(Affine::scale_non_uniform(1.0, 0.25), false);
assert!(n.extras().image_quad.is_none());
let b = n.geometric_bounds().unwrap();
assert!(b.height() < 1e-6 && (b.width() - 150.0).abs() < 60.0, "{b:?}");
assert!(b.height() < 1e-6 && (b.x0 + 200.0 / 9.0).abs() < 1e-6 && (b.x1 - 1400.0 / 9.0).abs() < 1e-6, "{b:?}");
}
/// A file's corners that the image cannot take are dropped as it is read, so a later scale
+12 -4
View File
@@ -64,8 +64,12 @@ fn type42_descendants_draw_their_own_glyphs() {
}
// The H, then the I one H's width along; both stand on the baseline, a cap height tall.
let (bh, bi) = (bounds(paths[0]), bounds(paths[1]));
assert!((bh.x0 - 10.0).abs() < 8.0 && bh.width() > 20.0 && bh.width() < 50.0 * wh, "{bh:?}");
assert!((bh.height() - bi.height()).abs() < 0.5 && bh.height() > 25.0 && bh.height() < 40.0, "{bh:?} {bi:?}");
// The bundled font's H spans (90, 0)–(562, 656) of its 1000-unit em: at 50 pt from x = 10 that
// is 14.5 to 38.1, 32.8 tall.
assert!((bh.x0 - 14.5).abs() < 0.01 && (bh.width() - 23.6).abs() < 0.01 && (bh.height() - 32.8).abs() < 0.01, "{bh:?}");
// In the y-down document the baseline at y = 20 lands at 80, and the cap height 32.8 above it at 47.2.
assert!((bh.y0 - 47.2).abs() < 0.01 && (bh.y1 - 80.0).abs() < 0.01, "{bh:?}");
assert!((bh.height() - bi.height()).abs() < 0.5, "{bh:?} {bi:?}");
assert!(bi.x0 > 10.0 + 50.0 * wh - 1.0 && bi.x1 < 10.0 + 50.0 * (wh + wi), "{bi:?}");
}
@@ -78,8 +82,12 @@ fn type42_descendants_measure_space_and_outline_their_glyphs() {
check(format!("(\\000\\001\\000\\002) stringwidth pop {} sub abs 0.01 lt", 50.0 * (wh + wi)));
// xyshow places each character where its numbers say.
check("gsave nulldevice 10 20 moveto (\\000\\001\\000\\002) [30 0 7 0] xyshow currentpoint grestore pop 47 sub abs 0.01 lt".into());
// charpath outlines them.
check("newpath 10 20 moveto (\\000\\001) true charpath pathbbox exch pop sub abs 25 gt exch 10 sub abs 8 lt and".into());
// charpath outlines them: the H's box is (14.5, 20)–(38.1, 52.8).
check(
"newpath 10 20 moveto (\\000\\001) true charpath pathbbox 52.8 sub abs 0.01 lt exch 38.1 sub abs 0.01 lt and \
exch 20 sub abs 0.01 lt and exch 14.5 sub abs 0.01 lt and"
.into(),
);
}
/// A descendant that is a font by name only (its program isn't run) sets its characters as type,
+4 -2
View File
@@ -731,7 +731,8 @@ fn hatched_brushes_fill_with_their_average_color() {
let p = paths(&back.document);
assert_eq!(p.len(), 1);
let [r, g, b] = fill_rgb(&p[0]).unwrap();
assert!(b == 255 && r == g && r > 0 && r < 255, "{:?}", [r, g, b]);
// The horizontal hatch covers one row in eight of its 8 × 8 tile: 8 blue and 56 white pixels.
assert_eq!([r, g, b], [223, 223, 255]);
// With a transparent background (SETBKMODE 1) the hatch is blue with gaps: a translucent fill.
let mut records = records;
records.insert(0, (18, le(&[1])));
@@ -739,7 +740,8 @@ fn hatched_brushes_fill_with_their_average_color() {
let p = paths(&back.document);
assert_eq!(fill_rgb(&p[0]), Some([0, 0, 255]));
let AppearanceItem::Fill(f) = &p[0].appearance.items[0] else { panic!("a fill") };
assert!(f.opacity > 0.0 && f.opacity < 1.0, "{}", f.opacity);
// One eighth of 255, truncated to 31.
assert!((f.opacity - 31.0 / 255.0).abs() < 1e-6, "{}", f.opacity);
}
#[test]
+2 -1
View File
@@ -272,7 +272,8 @@ fn a_page_without_area_gets_the_size_viewers_give_it() {
let bytes = pdf(&[PdfPage { media: [0.0, 0.0, 0.0, 0.0], ..PdfPage::new(0.0, 0.0, "") }], None);
let i = info(&bytes, None).unwrap();
let (w, h) = (i.pages[0].width, i.pages[0].height);
assert!(w > 0.0 && h > 0.0);
// US Letter, 8.5 × 11 in.
assert_eq!((w, h), (612.0, 792.0));
for crop in [CropTo::Crop, CropTo::Media, CropTo::Art] {
let ab = open(&bytes, ImportOptions { crop, ..Default::default() }).artboards[0].rect;
assert_eq!((ab.width(), ab.height()), (w, h), "{crop:?}");
+10
View File
@@ -84,6 +84,16 @@ fn a_patch_is_cut_no_finer_than_its_colour_changes() {
let d = doc(2, 2, |_, c| Color::rgb8(100 + c as u8, 100 + c as u8, 100 + c as u8));
let svg = export(&d, &ExportOptions::default());
assert!(pieces(&svg) <= 4, "{} pieces", pieces(&svg));
// Each piece takes its patch's middle color: 100.5 and 101.5 round to 101 and 102.
let mut fills: Vec<&str> = svg.split("fill=\"").skip(1).filter_map(|s| s.split('"').next()).filter(|f| f.starts_with('#')).collect();
fills.sort_unstable();
fills.dedup();
assert_eq!(fills, ["#656565", "#666666"], "{svg}");
// The left column's pieces take 101 and the right column's 102, in both rows.
let img = resvg_render(&svg);
for (x, y, want) in [(60, 60, 101), (60, 140, 101), (140, 60, 102), (140, 140, 102)] {
assert_eq!(&img.pixel(x, y)[..3], &[want; 3], "({x}, {y}) {svg}");
}
assert_looks_alike(&d, &svg, in_square, 2, 0.0);
}