Merge pull request #10525 from dotCooCoo/fix/engine-test-pass

Tests: engine command and integration tests check what they claim
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-01 22:31:51 -08:00
commit 9cfa3f1d13
18 files changed
+142 -51

No files matched your search

@@ -449,6 +449,7 @@ fn cropping_off_the_pixel_grid_keeps_the_hidden_colors_in_the_pixels() {
})
.unwrap()
.to_rgba8();
assert_eq!(own.dimensions(), (6, 5), "the cut's pixels");
assert!(own.pixels().all(|p| p.0[3] == 255), "the cut pixels are the image's own, white included");
assert_eq!(drawn(d, id, 0, 0)[3], 0, "white is hidden");
s.execute(REMOVE_COLOR_MASK, &json!({"ids": [id.0]})).unwrap();
@@ -237,6 +237,7 @@ fn add_points_splits_selected_segments_evenly() {
let n = steps(&s);
assert_eq!(s.execute("addon.pathtools.addPoints", &json!({"count": 3})).unwrap()["added"], json!(3));
let xs: Vec<f64> = path(&s, l).anchors().map(|(_, _, a)| a.p.x).collect();
assert_eq!(xs.len(), 5, "{xs:?}");
assert!(xs.iter().zip([0.0, 25.0, 50.0, 75.0, 100.0]).all(|(x, w)| (x - w).abs() < 1e-3), "{xs:?}");
assert_eq!(steps(&s), n + 1);
refuses(&mut s, "addon.pathtools.addPoints", &[json!({"count": 0}), json!({"count": 101}), json!({"count": 1.5})]);
@@ -69,7 +69,8 @@ fn a_straight_ramp_sizes_each_letter_and_skips_spaces() {
assert_eq!(sizes, [('a', 10.0), ('b', 20.0), (' ', 20.0), ('c', 30.0), ('d', 40.0)], "the space keeps its size");
assert_eq!(obj(&s, id).plain_text(), "ab cd", "the text stays live");
s.execute("edit.undo", &json!({})).unwrap();
assert!(styles(&s, id).iter().all(|(_, st)| st.size == 20.0), "undone");
let undone: Vec<(char, f64)> = styles(&s, id).into_iter().map(|(c, st)| (c, st.size)).collect();
assert_eq!(undone, [('a', 20.0), ('b', 20.0), (' ', 20.0), ('c', 20.0), ('d', 20.0)], "undone");
}
#[test]
+2
View File
@@ -1586,6 +1586,8 @@ mod trace_limit_tests {
// anchors each.
let strokes = |f: &tr::SeamFills| f.strokes.iter().map(|tp| tp.path.anchor_count()).sum::<usize>();
let outlined = seams_within(&res, &params, (24, 16), MAX_TRACE_ANCHORS, true, &go).unwrap().unwrap();
assert!(!outlined.strokes.is_empty(), "{res:?}");
assert_eq!(outlined.strokes.len(), all.as_ref().unwrap().strokes.len(), "one outline for each seam fill: {outlined:?}");
assert!(outlined.strokes.iter().all(|tp| tp.stroke.is_none() && !tp.path.is_empty()), "{outlined:?}");
let n = strokes(all.as_ref().unwrap());
assert!(strokes(&outlined) <= SEAM_OUTLINE_ANCHORS * n, "{} outline anchors, {n} stroke anchors", strokes(&outlined));
+6 -2
View File
@@ -696,9 +696,13 @@ mod tests {
let c = s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap();
assert_eq!(c, layer, "the scenario needs the id to be reused");
s.execute("edit.paste", &json!({})).unwrap();
let d = &s.doc().unwrap().doc;
let st = s.doc().unwrap();
let d = &st.doc;
let compound = d.node(NodeId(c)).unwrap();
assert!(compound.children().unwrap().iter().all(|ch| matches!(ch.kind, vectorcraft_doc::NodeKind::Path { .. })));
assert_eq!(compound.children().unwrap().len(), 1, "the compound path holds only the rectangle it was made from");
let pasted = st.selection.objects.clone();
assert_eq!(pasted.len(), 1);
assert!(d.parent_of(pasted[0]).is_some_and(|p| d.node(p).unwrap().is_layer()), "the copy lands on a layer");
}
#[test]
+1 -1
View File
@@ -1722,7 +1722,7 @@ mod tests {
let jags = polyline(&ring);
let sp = SubPath::new(jags.clone(), true);
assert!(subpath_len(&sp) < 24.0);
assert!(smooth_corners(&jags, true, 1e-6).iter().all(|c| *c), "each jag turns sharply at its anchor");
assert_eq!(smooth_corners(&jags, true, 1e-6), vec![true; 16], "each jag turns sharply at its anchor");
assert_eq!(smooth_corners(&jags, true, 12.0), vec![false; 16]);
assert_eq!(smooth_corners(&polyline(&[(0.0, 0.0), (6.0, 0.0), (3.0, 5.196)]), true, 12.0), vec![true; 3]);
}
@@ -104,8 +104,15 @@ fn bmp_options_reach_the_file() {
assert_eq!(i32::from_le_bytes(flipped[22..26].try_into().unwrap()), -40, "top-down rows");
let os2 = bmp(&mut s, json!({"fileFormat": "os2", "depth": 4}));
assert_eq!(u32::from_le_bytes(os2[14..18].try_into().unwrap()), 12, "OS/2 core header");
let gray = image::load_from_memory_with_format(&bmp(&mut s, json!({"colorModel": "gray", "depth": 8})), image::ImageFormat::Bmp).unwrap();
assert!(gray.to_rgb8().pixels().all(|p| p[0] == p[1] && p[1] == p[2]));
// A red square, whose gray is neither black nor white.
let red = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 40})).unwrap()["id"].clone();
s.execute("paint.setFill", &json!({"ids": [red], "color": "#ff0000"})).unwrap();
let gray =
image::load_from_memory_with_format(&bmp(&mut s, json!({"colorModel": "gray", "depth": 8})), image::ImageFormat::Bmp).unwrap().to_rgb8();
assert_eq!(gray.dimensions(), (60, 40));
assert!(gray.pixels().all(|p| p[0] == p[1] && p[1] == p[2]));
let [r, _, _] = gray.get_pixel(5, 20).0;
assert!(r > 0 && r < 255, "red is a middle gray: {r}");
for bad in [
json!({"depth": 2}),
json!({"depth": 24, "rle": true}),
+37 -26
View File
@@ -30,19 +30,29 @@ impl Visitor for Names {
}
}
/// Reads every file, and waits on reading one until its channel sends or closes.
struct Blocked(Mutex<mpsc::Receiver<()>>);
/// Reads every file, says on its second channel that a read began, and waits on reading one until
/// its first channel sends or closes.
struct Blocked(Mutex<mpsc::Receiver<()>>, mpsc::Sender<()>);
impl Visitor for Blocked {
fn wants(&self, _: &str) -> bool {
true
}
fn items(&self, _: &Path) -> Vec<usize> {
let _ = self.1.send(());
let _ = self.0.lock().unwrap().recv();
vec![]
}
}
/// A [`Blocked`] visitor with the sender that lets its reads end and the receiver that hears each
/// read begin.
fn blocked() -> (mpsc::Sender<()>, mpsc::Receiver<()>, Arc<dyn Visitor>) {
let (go, wait_for_go) = mpsc::channel();
let (entered, reading) = mpsc::channel();
(go, reading, Arc::new(Blocked(Mutex::new(wait_for_go), entered)))
}
/// A test's folder tree, removed with everything in it when dropped, also when the test panics,
/// and also when the test locked a folder in it. A removal that fails (a walker still holding a
/// file open) is ignored.
@@ -316,29 +326,35 @@ fn the_search_ends_at_its_limits_and_when_stopped() {
#[test]
fn the_search_answers_at_its_deadline_while_a_walker_is_blocked() {
let root = tree("blocked", &["f.ttf"]);
let (tx, rx) = mpsc::channel();
let (tx, reading, visitor) = blocked();
let started = Instant::now();
let s = begin(root.clone(), rules(&root), Limits { seconds: 0.2, ..Limits::default() }, 1, 1, Arc::new(Blocked(Mutex::new(rx))));
std::thread::sleep(Duration::from_millis(300));
let s = begin(root.clone(), rules(&root), Limits::default(), 1, 1, visitor);
// The walker is blocked reading the file.
assert!(reading.recv_timeout(WAIT).is_ok(), "the walker reads the file");
assert_eq!((s.progress().state(), s.progress().read), ("searching", 1));
s.expire();
let p = s.progress();
// The search ended when it answered, and it ran no longer than the test has waited.
let waited = started.elapsed().as_secs_f64();
assert_eq!((p.state(), p.stopped()), ("stopped", Some("time")), "{p:?}");
assert!(p.seconds >= 0.2 && p.seconds <= waited, "{p:?}, {waited} s");
let (tx2, rx2) = mpsc::channel();
let s2 = begin(root.clone(), rules(&root), Limits::default(), 1, 1, Arc::new(Blocked(Mutex::new(rx2))));
let until = Instant::now() + WAIT;
while s2.progress().read == 0 && Instant::now() < until {
std::thread::sleep(Duration::from_millis(2));
}
assert!(p.seconds <= waited, "{p:?}, {waited} s");
assert_eq!(s.progress().seconds, p.seconds, "the time it ended at stays");
// A limit of no seconds has run out as the search starts; a long one hasn't.
let (_tx0, _, visitor) = blocked();
let none = begin(root.clone(), rules(&root), Limits { seconds: 0.0, ..Limits::default() }, 1, 1, visitor);
assert_eq!(none.progress().stopped(), Some("time"));
let (tx2, reading2, visitor) = blocked();
let s2 = begin(root.clone(), rules(&root), Limits::default(), 1, 1, visitor);
assert!(reading2.recv_timeout(WAIT).is_ok(), "the walker reads the file");
assert_eq!(s2.progress().state(), "searching");
s2.stop();
assert_eq!(s2.progress().stopped(), Some("stop"));
drop((tx, tx2));
}
/// Every file is item 0; reading the second file waits until the channel closes.
struct SecondBlocks(Mutex<(usize, mpsc::Receiver<()>)>);
/// Every file is item 0; reading the second file says so on the second channel, then waits until
/// the first channel closes.
struct SecondBlocks(Mutex<(usize, mpsc::Receiver<()>)>, mpsc::Sender<()>);
impl Visitor for SecondBlocks {
fn wants(&self, _: &str) -> bool {
@@ -348,6 +364,7 @@ impl Visitor for SecondBlocks {
let mut read = self.0.lock().unwrap();
read.0 += 1;
if read.0 == 2 {
let _ = self.1.send(());
let _ = read.1.recv();
}
vec![0]
@@ -360,11 +377,9 @@ impl Visitor for SecondBlocks {
fn files_found_are_kept_as_they_are_read() {
let root = tree("kept", &["a.ttf", "b.ttf", "c.ttf"]);
let (tx, rx) = mpsc::channel();
let s = begin(root.clone(), rules(&root), Limits::default(), 1, 2, Arc::new(SecondBlocks(Mutex::new((0, rx)))));
let until = Instant::now() + WAIT;
while s.progress().read < 2 && Instant::now() < until {
std::thread::sleep(Duration::from_millis(2));
}
let (second, reading_second) = mpsc::channel();
let s = begin(root.clone(), rules(&root), Limits::default(), 1, 2, Arc::new(SecondBlocks(Mutex::new((0, rx)), second)));
assert!(reading_second.recv_timeout(WAIT).is_ok(), "the walker reads a second file");
let p = s.progress();
assert_eq!((p.state(), p.hits.len()), ("searching", 1), "{p:?}");
s.stop();
@@ -527,16 +542,12 @@ fn system_roots_and_homes_are_told_by_what_they_hold() {
fn a_search_starts_with_the_threads_left_and_fails_when_none_is() {
static POOL: Pool = Pool::new(3);
let root = tree("pool", &["f.ttf"]);
let blocked = || {
let (tx, rx) = mpsc::channel();
(tx, Arc::new(Blocked(Mutex::new(rx))) as Arc<dyn Visitor>)
};
let (tx_a, a) = blocked();
let (tx_b, b) = blocked();
let (tx_a, _, a) = blocked();
let (tx_b, _, b) = blocked();
let a = start_in(&POOL, root.clone(), Some(rules(&root)), Limits::default(), 2, 1, a).unwrap();
let b = start_in(&POOL, root.clone(), Some(rules(&root)), Limits::default(), 4, 1, b).unwrap();
assert_eq!(POOL.live(), 3);
let (_, c) = blocked();
let (_, _, c) = blocked();
let c = start_in(&POOL, root.clone(), Some(rules(&root)), Limits::default(), 1, 1, c);
assert_eq!(c.err().as_deref(), Some("the search couldn't start: try again in a moment"));
drop((tx_a, tx_b));
+17 -5
View File
@@ -238,12 +238,18 @@ impl Search {
self.shared.finish(&mut w, End::Stopped);
}
/// Move the search's deadline to now, as if its time had run out.
#[cfg(test)]
pub(crate) fn expire(&self) {
self.shared.deadline.store(0, Ordering::Relaxed);
}
/// Where the search stands. Past its deadline it has ended ([`End::Time`]), even while a walker
/// is still waiting for a slow folder or file.
pub fn progress(&self) -> Progress {
let s = &self.shared;
let mut w = s.lock();
if w.end.is_none() && Instant::now() >= s.deadline {
if w.end.is_none() && s.time_up() {
s.finish(&mut w, End::Time);
}
Progress {
@@ -310,7 +316,7 @@ pub(crate) fn start_in(
entries: AtomicU64::new(0),
read: AtomicU64::new(0),
started,
deadline: started + Duration::from_secs_f64(seconds),
deadline: AtomicU64::new(u64::try_from(Duration::from_secs_f64(seconds).as_nanos()).unwrap_or(u64::MAX)),
limits,
items,
given: rules,
@@ -355,7 +361,8 @@ struct Shared {
entries: AtomicU64,
read: AtomicU64,
started: Instant,
deadline: Instant,
/// Nanoseconds after `started` at which the search's time is up.
deadline: AtomicU64,
limits: Limits,
items: usize,
/// The rules given to [`start`], else this computer's, read by the first walker.
@@ -419,7 +426,12 @@ impl Shared {
/// Whether to stop listing and reading: the search ended or its time is up.
fn should_stop(&self) -> bool {
self.stop.load(Ordering::Relaxed) || Instant::now() >= self.deadline
self.stop.load(Ordering::Relaxed) || self.time_up()
}
/// Whether the search's time is up: [`Shared::deadline`] nanoseconds passed since it started.
fn time_up(&self) -> bool {
u64::try_from(self.started.elapsed().as_nanos()).unwrap_or(u64::MAX) >= self.deadline.load(Ordering::Relaxed)
}
/// Whether the folders waiting to be listed and `more` folders found in the folder being listed
@@ -618,7 +630,7 @@ fn walker(s: &Shared) {
if w.end.is_some() {
return;
}
if Instant::now() >= s.deadline {
if s.time_up() {
s.finish(&mut w, End::Time);
return;
}
+37 -7
View File
@@ -2588,6 +2588,7 @@ fn a_line_series_draws_its_kept_stroke_on_the_line_and_its_kept_fill_on_the_mark
s.execute("graph.setData", &json!({"rows": [[1, 2], [3, 4]]})).unwrap();
let (drawn, others) = line_parts(&s, id);
assert_eq!((drawn.appearance.fill_paint(), drawn.appearance.stroke_paint()), (Paint::None, red));
assert!(!others.is_empty(), "the markers and the legend swatch are drawn");
assert!(others.iter().all(|m| m.appearance.fill_paint() == blue), "{others:?}");
}
@@ -4867,7 +4868,7 @@ fn blanks_read_back_as_null_and_year_header_rows_still_read_as_headers() {
#[test]
fn a_huge_ragged_grid_is_capped() {
let g = GraphSpec { rows: vec![vec![0.0; vectorcraft_doc::MAX_GRAPH_SERIES + 10]; 3], ..GraphSpec::default() };
assert!(g.cells().iter().all(|r| r.len() == vectorcraft_doc::MAX_GRAPH_SERIES));
assert_eq!(g.cells().iter().map(Vec::len).collect::<Vec<_>>(), [vectorcraft_doc::MAX_GRAPH_SERIES; 3]);
}
#[test]
@@ -6720,7 +6721,17 @@ fn designs_and_markers_survive_save_and_open() {
d.graph_designs.push(vectorcraft_doc::GraphDesign { name: "Dot".into(), art: std::sync::Arc::new(dot) });
let art = super::generate(&mut d, &g);
let s0 = art.iter().find(|n| n.extras().series_index == Some(0)).unwrap();
assert!(s0.children().unwrap().iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
let marks = s0.children().unwrap();
assert!(marks.iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
assert_eq!(marks.iter().filter(|n| sized(n, 5.0)).count(), 1, "a default square at the one data point");
}
/// Whether `n` is a square path `side` points across, drawn as the four corners of its bounds (a default point marker
/// is 5, a default legend swatch 8).
fn sized(n: &vectorcraft_doc::Node, side: f64) -> bool {
let Some(b) = n.geometric_bounds() else { return false };
let square = matches!(&n.kind, NodeKind::Path { path, .. } if *path == vectorcraft_geom::shapes::rectangle(b));
square && (b.width() - side).abs() < 1e-6 && (b.height() - side).abs() < 1e-6
}
#[test]
@@ -6773,7 +6784,11 @@ fn designs_too_big_for_a_graph_are_refused_and_drawn_as_squares() {
let mut d = (*s.doc().unwrap().doc).clone();
let art = super::generate(&mut d, &g);
let s0 = art.iter().find(|n| n.extras().series_index == Some(0)).unwrap();
assert!(s0.children().unwrap().iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
let marks = s0.children().unwrap();
assert!(marks.iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
assert_eq!(marks.iter().filter(|n| sized(n, 5.0)).count(), 200, "a default square at each of the 200 points");
let line = marks.iter().filter(|n| n.geometric_bounds().is_some_and(|b| b.width() > 100.0)).count();
assert_eq!(line, 1, "the series line is drawn as well");
// Too many objects for one design.
let ids: Vec<u64> = (0..2001)
.map(|i| s.execute("shape.rectangle", &json!({"x": i % 40, "y": i / 40, "width": 1, "height": 1})).unwrap()["id"].as_u64().unwrap())
@@ -7157,7 +7172,16 @@ fn graph_column_params_are_checked_and_designs_too_big_are_drawn_plain() {
let mut d = (*s.doc().unwrap().doc).clone();
let art = super::generate(&mut d, &g);
let s0 = art.iter().find(|n| n.extras().series_index == Some(0)).unwrap();
assert!(s0.children().unwrap().iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
let marks = s0.children().unwrap();
assert!(marks.iter().all(|n| matches!(n.kind, NodeKind::Path { .. })));
assert_eq!(marks.iter().filter(|n| sized(n, 8.0)).count(), 1, "a default square as the legend swatch");
let columns: Vec<_> = marks.iter().filter(|n| !sized(n, 8.0)).collect();
assert_eq!(columns.len(), 1, "one plain column for the one value");
let bounds = columns[0].geometric_bounds();
let height = bounds.map(|b| b.height());
assert!(height.is_some_and(|h| (h - 140.0).abs() < 1e-6), "the column has the value's height: {height:?}");
let rectangle = bounds.map(vectorcraft_geom::shapes::rectangle);
assert!(matches!(&columns[0].kind, NodeKind::Path { path, .. } if Some(path) == rectangle.as_ref()), "the plain column is a rectangle");
// Columns of 0 on a value axis from 10,000 to 10,001 run 2,000,000 points from the clamped zero line: a copy each
// 0.1 is past the budget too.
let far = one_series(&mut s, "column", &[0.0, 0.0]);
@@ -7840,7 +7864,9 @@ fn the_legend_across_top_keeps_above_labels_over_the_plot() {
let n = s.doc().unwrap().doc.node(col).unwrap().clone();
let texts: Vec<_> = group(&n, "Legend").children().unwrap().iter().filter_map(|c| c.geometric_bounds()).collect();
let last_row = texts.iter().map(|b| b.y0).fold(f64::MIN, f64::max);
assert!(texts.iter().filter(|b| b.y0 < last_row - 1e-6).all(|b| b.x1 <= 400.0 + 1e-6), "{texts:?}");
let above: Vec<_> = texts.iter().filter(|b| b.y0 < last_row - 1e-6).collect();
assert!(!above.is_empty(), "the legend takes more than one row: {texts:?}");
assert!(above.iter().all(|b| b.x1 <= 400.0 + 1e-6), "{texts:?}");
}
#[test]
@@ -8024,6 +8050,7 @@ fn formatting_the_whole_graphs_text_survives_it_being_drawn_again() {
s.execute("select.set", &json!({"ids": [id.0]})).unwrap();
s.execute("text.setStyle", &json!({"size": 12})).unwrap();
let looks = label_looks(&mut s, id);
assert!(!looks.is_empty());
assert!(looks.iter().all(|(_, size, _)| (*size - 12.0).abs() < 1e-6), "{looks:?}");
let g = spec(&s, id);
assert!(g.label_styles.values.is_some() && g.label_styles.categories.is_some() && g.label_styles.legend.is_some());
@@ -9145,10 +9172,13 @@ fn line_look(n: &vectorcraft_doc::Node) -> (String, f64, f32) {
(stroke, n.appearance.stroke_width(), n.opacity)
}
/// The looks of graph `id`'s lines after it is drawn again.
/// The looks of graph `id`'s lines after it is drawn again: more than three (a radar graph's
/// three spokes come first, then its rings).
fn redrawn_line_looks(s: &mut Session, id: NodeId) -> Vec<(String, f64, f32)> {
s.execute("graph.setData", &json!({"id": id.0, "csv": ",2024,2025\nQ1,3,2\nQ2,5,4\nQ3,-1,6"})).unwrap();
line_nodes(s, id).iter().map(line_look).collect()
let looks: Vec<_> = line_nodes(s, id).iter().map(line_look).collect();
assert!(looks.len() > 3, "the graph is drawn with its lines: {looks:?}");
looks
}
/// A stroke, a weight, no stroke or an opacity given to one axis line is kept for every axis line and tick mark when the
+3 -1
View File
@@ -1101,7 +1101,9 @@ fn lines_that_do_not_stack_as_a_paragraph_stay_apart() {
s.execute("select.set", &json!({"ids": [a]})).unwrap();
let r = s.execute("type.retype", &json!({})).unwrap();
assert_eq!(r["texts"], json!(["Top", "Far", "Askew"]), "{r}");
assert!(r["fonts"].as_array().unwrap().iter().all(|f| f["area"] == json!(false)), "{r}");
let fonts = r["fonts"].as_array().unwrap();
assert!(!fonts.is_empty(), "{r}");
assert!(fonts.iter().all(|f| f["area"] == json!(false)), "{r}");
}
#[test]
@@ -1854,9 +1854,12 @@ fn kana_style_and_roman_italics_are_character_features() {
}
assert_eq!(runs(&s), before);
s.execute("text.setRangeStyle", &json!({"id": id, "featureChanges": ["-hkna", "-ital"]})).unwrap();
let text = |s: &Session| runs(s).into_iter().map(|(t, _)| t).collect::<String>();
assert_eq!(text(&s), "かなAB");
assert!(runs(&s).iter().all(|(_, f)| f.is_empty()), "{:?}", runs(&s));
s.execute("charStyle.new", &json!({"name": "Kana", "attrs": {"features": ["hkna", "ital"]}})).unwrap();
s.execute("charStyle.apply", &json!({"name": "Kana", "id": id})).unwrap();
assert_eq!(text(&s), "かなAB");
assert!(runs(&s).iter().all(|(_, f)| *f == ["hkna", "ital"]), "{:?}", runs(&s));
let e = s.execute("charStyle.new", &json!({"name": "Bad", "attrs": {"features": ["ital=2"]}})).unwrap_err().to_string();
assert!(e.contains("unknown OpenType feature `ital=2`"), "{e}");
@@ -257,6 +257,7 @@ fn gaps_set_word_spacing_and_leading() {
// The layout uses the gap as the Desired word spacing; the paragraph keeps its own.
assert_eq!(t.para_at(0).justification.word_spacing, [80.0, 100.0, 133.0]);
assert_eq!(t.layout_justification(t.para_at(0)).word_spacing, [80.0, 300.0, 300.0]);
assert_eq!(t.plain_text(), "two words\nthree more words", "the runs hold the text");
assert!(t.runs.iter().all(|r| (r.style.leading.unwrap() - r.style.size - 6.0).abs() < 1e-9), "{:?}", t.runs);
assert_block(&t);
assert!(size_at(&t, 0) < size_at(&plain, 0), "wider word spaces leave the letters less room");
@@ -850,6 +851,7 @@ fn a_range_leading_change_with_block_on_moves_the_line_gap() {
let t = text(&s, id);
assert!((t.area.line_gap - 5.0).abs() < 1e-9, "line gap {}", t.area.line_gap);
assert!(leading_at(&t, 4).is_some_and(|l| (l - second - 5.0).abs() < 1e-9), "{:?}", leading_at(&t, 4));
assert_eq!(t.plain_text(), "BIG\na much longer second line\nmid one", "the runs hold the text");
assert!(t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - r.style.size - 5.0).abs() < 1e-9)), "every line spreads");
// Reset Panel's form: the leading is set and Block keeps the line gap.
s.execute("text.setRangeStyle", &json!({"id": id, "start": 4, "end": 10, "leading": "auto", "keepLineGap": true})).unwrap();
+4 -1
View File
@@ -4498,11 +4498,14 @@ fn stale_current_layer_id_never_targets_a_reused_id() {
s.execute("select.set", &json!({"ids": [a.0, b.0]})).unwrap();
let c = NodeId(s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap());
assert_eq!(c, layer, "precondition: id reused");
// Undo gives back the layer that was current before New Layer; a remembered id left over
// from elsewhere still names the compound path now.
s.doc_mut().unwrap().active_layer = Some(c);
let d = rect(&mut s, 50.0, 50.0, 10.0, 10.0);
s.execute("select.set", &json!({"ids": [d.0]})).unwrap();
s.execute("object.arrange.sendToCurrentLayer", &json!({})).unwrap();
let doc = &s.doc().unwrap().doc;
assert!(doc.node(c).unwrap().children().unwrap().iter().all(|n| n.path_data().is_some()));
assert_eq!(doc.node(c).unwrap().children().unwrap().len(), 2, "the compound path holds only the two rectangles it was made from");
assert!(doc.parent_of(d).is_some_and(|p| doc.node(p).unwrap().is_layer()));
// layer.delete without an id must not delete the compound path.
s.execute("layer.delete", &json!({})).ok();
+3 -2
View File
@@ -2,7 +2,7 @@
//! recursively) opens as editable art, and each artboard is compared with the thumbnail Affinity
//! stored in the file. Reports the mean difference per artboard (0–255, both on white); with
//! `AFFINITY_SAMPLES_OUT` set, writes each board's thumbnail crop and render side by side there.
//! Skipped when `AFFINITY_SAMPLES` is unset (as in CI).
//! Ignored by default; run it with `--ignored` and `AFFINITY_SAMPLES` set.
use std::path::{Path, PathBuf};
@@ -28,8 +28,9 @@ fn on_white(p: &[u8]) -> [f64; 3] {
}
#[test]
#[ignore = "local samples: set AFFINITY_SAMPLES to a folder of Affinity documents"]
fn local_affinity_documents_render_like_their_thumbnails() {
let Some(root) = std::env::var_os("AFFINITY_SAMPLES").map(PathBuf::from) else { return };
let root = PathBuf::from(std::env::var_os("AFFINITY_SAMPLES").expect("AFFINITY_SAMPLES names the folder of documents to check"));
let out = std::env::var_os("AFFINITY_SAMPLES_OUT").map(PathBuf::from);
let mut paths = Vec::new();
files(&root, &mut paths);
+1
View File
@@ -476,6 +476,7 @@ fn turned_horizontal_dimensions_stay_horizontal() {
let mut ys = [d.a.y.round(), d.b.y.round()];
ys.sort_by(f64::total_cmp);
assert_eq!(ys, [180.0, 280.0]);
assert_eq!(path_ends(&s, id)[2].len(), 2, "{:?}", path_ends(&s, id));
assert!(path_ends(&s, id)[2].iter().all(|(_, y)| (y - 130.0).abs() < 1e-6), "{:?}", path_ends(&s, id));
let line = run(&mut s, "shape.line", json!({"x1":100,"y1":400,"x2":200,"y2":400}))["id"].as_u64().unwrap();
let anchor = |anchor: u64| json!({"node":line,"subpath":0,"anchor":anchor});
+10 -2
View File
@@ -76,10 +76,18 @@ fn a_file_the_import_left_things_out_of_is_not_written_over_unasked() {
fn a_file_the_import_read_whole_is_written_over_as_before() {
let d = dir("b");
let src = d.join("plain.eps");
std::fs::write(&src, "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n0 0 1 0 setcmykcolor 10 10 moveto 14 10 lineto 14 14 lineto closepath fill\nshowpage\n%%EOF\n").unwrap();
let original = "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n0 0 1 0 setcmykcolor 10 10 moveto 14 10 lineto 14 14 lineto closepath fill\nshowpage\n%%EOF\n";
std::fs::write(&src, original).unwrap();
let mut s = Session::new();
s.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
let opened = s.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
assert_eq!(opened["warnings"], json!([]), "{opened}");
s.execute("document.export", &json!({ "path": src.to_string_lossy(), "format": "eps" })).unwrap();
let written = std::fs::read(&src).unwrap();
assert_ne!(written, original.as_bytes(), "the export wrote over the file");
let mut again = Session::new();
again.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
let doc = &again.doc().unwrap().doc;
assert!(doc.layers.iter().any(|l| l.children().is_some_and(|c| !c.is_empty())), "the square is in the file written");
std::fs::remove_dir_all(d).ok();
}
+3 -1
View File
@@ -209,7 +209,9 @@ fn preflight_resource_font_finding_locates_its_instance() {
s.execute("symbol.new", &json!({ "name": "Label" })).unwrap();
let r = check(&mut s);
let f = r["findings"].as_array().unwrap().iter().find(|f| f["code"] == "missingFont").unwrap();
assert!(f["ids"].as_array().unwrap().iter().all(|id| s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).is_some()), "{r}");
let ids = f["ids"].as_array().unwrap();
assert!(!ids.is_empty(), "the finding names where the font is used: {r}");
assert!(ids.iter().all(|id| s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).is_some()), "{r}");
}
struct Folder(std::path::PathBuf);