Tests: run the attached recolor import test on a synthetic document

The recolor adjustment test read test.af from the repository root and
returned early when the file was absent, so it never ran in CI. It now
builds a magenta rectangle with an attached Recolor adjustment in the
test and checks that lightness 1 imports as a white fill, that
lightness 0.5 at hue 0 draws pure red, and that a hidden adjustment
leaves the fill unchanged.
This commit is contained in:
dotCooCoo committed 2026-11-30 23:03:43 -08:00
1 parent 84335645da
commit f08d12949c
1 file changed
+36 -15
+36 -15
View File
@@ -744,20 +744,41 @@ fn objects_beyond_the_document_range_are_left_out() {
assert!(loaded.warnings.iter().any(|w| w.contains("beyond the document range")), "{:?}", loaded.warnings);
}
/// A magenta rectangle with a Recolor adjustment (`RcRA`) attached, at `lightness`.
fn recolored(visible: bool, lightness: f64) -> F {
let mut node = rectangle(10, (0.0, 0.0), (50.0, 50.0));
let recolor = F::Def(
20,
vec![tag(b"RcRA")],
vec![
(tag(b"Visi"), F::Bool(visible)),
(tag(b"AdjP"), F::Obj(tag(b"RecP"), vec![(tag(b"RecH"), F::F64(0.0)), (tag(b"RecS"), F::F64(1.0)), (tag(b"RecL"), F::F64(lightness))])),
],
);
if let F::Def(_, _, fields) = &mut node {
fields.push((tag(b"AdCh"), F::Shared(vec![recolor])));
}
node
}
fn first_fill(n: &Node) -> Paint {
let Some(AppearanceItem::Fill(fill)) = n.appearance.items.first() else { panic!("no fill: {:?}", n.appearance) };
fill.paint.clone()
}
#[test]
fn test_af_g_symbol_fill_is_white() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test.af");
let Ok(bytes) = std::fs::read(&path) else {
return;
};
let loaded = vectorcraft_engine::cmd::fileio::load("test.af", &bytes).unwrap();
assert!(!loaded.preview_only, "{:?}", loaded.warnings);
let d = &loaded.doc;
// The visible "g41" group holds the "g" symbol (path43).
let g41 = all(d).into_iter().find(|n| n.visible && n.name.as_deref() == Some("g41")).expect("visible g41 group must be present");
let path43 = g41.children().and_then(|c| c.iter().find(|n| n.name.as_deref() == Some("path43"))).expect("path43 inside g41 must be present");
let Some(AppearanceItem::Fill(fill)) = path43.appearance.items.first() else {
panic!("path43 has no fill: {:?}", path43.appearance);
};
assert_eq!(fill.paint, Paint::solid(Color::rgb(1.0, 1.0, 1.0)), "The 'g' symbol must have a white fill in test.af, got {:?}", fill.paint);
fn attached_recolor_adjustments_recolor_the_shape() {
// Lightness 1 recolors to white.
let loaded = open("recolor.af", &canvas_with(vec![recolored(true, 1.0)], None));
assert!(!loaded.warnings.iter().any(|w| w.contains("attached to other layers")), "{:?}", loaded.warnings);
let rect = named(&loaded.doc, "Magenta box");
assert!(rect.appearance.effects.is_empty());
assert_eq!(first_fill(rect), Paint::solid(Color::rgb(1.0, 1.0, 1.0)));
// Lightness 0.5 at hue 0 and full saturation is pure red.
let d = open("red.af", &canvas_with(vec![recolored(true, 0.5)], None)).doc;
let [r, g, b, a] = pixel(&d, 25, 25);
assert!(r > 250 && g < 5 && b < 5 && a == 255, "{:?}", [r, g, b, a]);
// A hidden adjustment leaves the shape as it is.
let d = open("hidden.af", &canvas_with(vec![recolored(false, 1.0)], None)).doc;
assert_eq!(first_fill(named(&d, "Magenta box")), Paint::solid(Color::cmyk(0.0, 1.0, 0.0, 0.0)));
}