Update annotation tests after SaveOptions, Style, LinkAction, and Shape changes

#2523's tests were written against earlier field lists. Later work added
id_entropy, border and opacity style fields, a zoom on page links, and a
line on custom stamps, so cargo xtask ci now fails at clippy on main.

The tests keep the same intent: page links still use Fit Page, the view they
had before they carried a zoom, and the extra style and stamp fields take
their defaults.
This commit is contained in:
FredApps committed 2026-11-18 16:55:06 +07:00
1 parent 894904616d
commit ae30592466
4 files changed
+39 -18

No files matched your search

+16 -8
View File
@@ -382,7 +382,8 @@ fn a_link_area_that_is_too_small_or_broken_is_refused_before_it_is_written() {
];
for (label, rect, want_in_message) in cases {
let mut doc = blank(2);
let e = links::add(&mut doc, 0, rect, &links::LinkAction::Page(1), &links::LinkStyle::default()).err();
let e =
links::add(&mut doc, 0, rect, &links::LinkAction::Page { page: 1, zoom: links::LinkZoom::FitPage }, &links::LinkStyle::default()).err();
let msg = match &e {
Some(AnnotError::Invalid(m)) => m.clone(),
other => panic!("{label}: expected Invalid, got {other:?}"),
@@ -440,10 +441,10 @@ fn non_finite_builder_input_is_refused_and_leaves_the_document_untouched() {
}
for (label, style) in [
("nan opacity", Style { color: [0.0, 0.0, 0.0], opacity: f64::NAN, width: 1.0, fill: None }),
("infinite opacity", Style { color: [0.0, 0.0, 0.0], opacity: f64::INFINITY, width: 1.0, fill: None }),
("nan colour", Style { color: [f64::NAN, 0.0, 0.0], opacity: 1.0, width: 1.0, fill: None }),
("nan width", Style { color: [0.0, 0.0, 0.0], opacity: 1.0, width: f64::NAN, fill: None }),
("nan opacity", Style { color: [0.0, 0.0, 0.0], opacity: f64::NAN, width: 1.0, fill: None, ..Style::default() }),
("infinite opacity", Style { color: [0.0, 0.0, 0.0], opacity: f64::INFINITY, width: 1.0, fill: None, ..Style::default() }),
("nan colour", Style { color: [f64::NAN, 0.0, 0.0], opacity: 1.0, width: 1.0, fill: None, ..Style::default() }),
("nan width", Style { color: [0.0, 0.0, 0.0], opacity: 1.0, width: f64::NAN, fill: None, ..Style::default() }),
] {
let mut doc = blank(1);
let e = add_annotation(
@@ -593,7 +594,14 @@ fn unvalidated_stamp_size_and_signature_contours_are_rewritten_silently_in_the_f
&mut doc,
&NewAnnotation {
page: 0,
shape: Shape::CustomStamp { rect: [10.0, 20.0, 60.0, 50.0], name: "Sig".into(), picture, image: true, size: (1e300, f64::NAN) },
shape: Shape::CustomStamp {
rect: [10.0, 20.0, 60.0, 50.0],
name: "Sig".into(),
picture,
image: true,
size: (1e300, f64::NAN),
line: None,
},
style: Style::default(),
contents: String::new(),
author: "A".into(),
@@ -656,7 +664,7 @@ fn a_nan_fill_is_accepted_on_create_and_refused_on_edit() {
&NewAnnotation {
page: 0,
shape: Shape::Rectangle { rect: [10.0, 20.0, 60.0, 40.0] },
style: Style { color: [0.9, 0.1, 0.1], opacity: 1.0, width: 2.0, fill: Some(nan) },
style: Style { color: [0.9, 0.1, 0.1], opacity: 1.0, width: 2.0, fill: Some(nan), ..Style::default() },
contents: String::new(),
author: "A".into(),
},
@@ -842,7 +850,7 @@ fn the_same_huge_fill_is_accepted_on_create_and_refused_on_edit() {
&NewAnnotation {
page: 0,
shape: Shape::Rectangle { rect: [10.0, 20.0, 60.0, 40.0] },
style: Style { color: [0.9, 0.1, 0.1], opacity: 1.0, width: 2.0, fill: Some(probe) },
style: Style { color: [0.9, 0.1, 0.1], opacity: 1.0, width: 2.0, fill: Some(probe), ..Style::default() },
contents: String::new(),
author: "A".into(),
},
+4 -4
View File
@@ -165,7 +165,7 @@ proptest! {
#[test]
fn opacity_and_flags_follow_their_rules(opacity in any::<f64>()) {
let mut doc = blank(1);
let added = add_annotation(&mut doc, &comment(0, Shape::Rectangle { rect: [10.0, 10.0, 60.0, 40.0] }, Style { color: [0.5, 0.25, 0.75], opacity, width: 1.0, fill: None }, String::new(), "Ada".into()), &meta("c".into()));
let added = add_annotation(&mut doc, &comment(0, Shape::Rectangle { rect: [10.0, 10.0, 60.0, 40.0] }, Style { color: [0.5, 0.25, 0.75], opacity, width: 1.0, fill: None, ..Style::default() }, String::new(), "Ada".into()), &meta("c".into()));
if !opacity.is_finite() {
prop_assert!(added.is_err(), "a non-finite opacity ({:?}) must be refused, not written", opacity);
return Ok(());
@@ -243,7 +243,7 @@ proptest! {
2 => -0.5,
_ => 0.0,
};
add_annotation(&mut doc, &comment(0, Shape::Rectangle { rect: *r }, Style { color: [0.9, 0.1, 0.1], opacity, width: 2.0, fill: None }, format!("c{i}"), "Ada".into()), &meta(format!("k{i}")))
add_annotation(&mut doc, &comment(0, Shape::Rectangle { rect: *r }, Style { color: [0.9, 0.1, 0.1], opacity, width: 2.0, fill: None, ..Style::default() }, format!("c{i}"), "Ada".into()), &meta(format!("k{i}")))
.expect("adds");
want_rects.push(norm(*r));
}
@@ -333,7 +333,7 @@ proptest! {
#[test]
fn width_and_fill_are_written_as_they_were_given(width in -4.0f64..12.0, fill in prop::option::of(prop::array::uniform3(0.0f64..1.0))) {
let mut doc = blank(1);
add_annotation(&mut doc, &comment(0, Shape::Oval { rect: [5.0, 5.0, 65.0, 35.0] }, Style { color: [1.0, 0.0, 0.0], opacity: 1.0, width, fill }, String::new(), "Ada".into()), &meta("f".into()))
add_annotation(&mut doc, &comment(0, Shape::Oval { rect: [5.0, 5.0, 65.0, 35.0] }, Style { color: [1.0, 0.0, 0.0], opacity: 1.0, width, fill, ..Style::default() }, String::new(), "Ada".into()), &meta("f".into()))
.expect("adds");
for path in [Save::Incremental, Save::FullTable] {
let (file, reopened) = save_and_reopen(&doc, path);
@@ -360,7 +360,7 @@ proptest! {
fn a_line_keeps_its_endpoints_and_its_rectangle_spans_them(from in prop::array::uniform2(coord()), dx in 1.0f64..300.0, dy in -300.0f64..300.0, width in 0.5f64..8.0) {
let to = [(from[0] + dx).min(450.0), from[1] + dy];
let mut doc = blank(1);
add_annotation(&mut doc, &comment(0, Shape::Line { from, to, start: LineEnding::None, end: LineEnding::OpenArrow }, Style { color: [0.0, 0.0, 0.0], opacity: 1.0, width, fill: None }, String::new(), "Ada".into()), &meta("l".into()))
add_annotation(&mut doc, &comment(0, Shape::Line { from, to, start: LineEnding::None, end: LineEnding::OpenArrow }, Style { color: [0.0, 0.0, 0.0], opacity: 1.0, width, fill: None, ..Style::default() }, String::new(), "Ada".into()), &meta("l".into()))
.expect("adds");
let span = bounds_of(&[from, to]);
for path in [Save::Incremental, Save::FullTable, Save::FullStreams] {
+12 -5
View File
@@ -48,7 +48,7 @@ fn ann(page: usize, shape: Shape, contents: &str) -> NewAnnotation {
}
fn styled(page: usize, shape: Shape, contents: &str, color: [f64; 3], opacity: f64, width: f64, fill: Option<[f64; 3]>) -> NewAnnotation {
NewAnnotation { page, shape, style: Style { color, opacity, width, fill }, contents: contents.into(), author: "Ada".into() }
NewAnnotation { page, shape, style: Style { color, opacity, width, fill, ..Style::default() }, contents: contents.into(), author: "Ada".into() }
}
/// The dictionary of the `k`-th `/Annots` entry of a page.
@@ -714,7 +714,7 @@ fn links_keep_page_targets_uri_and_dash_structure_across_renumbering() {
&mut doc,
0,
[120.0, 700.0, 240.0, 720.0],
&links::LinkAction::Page(2),
&links::LinkAction::Page { page: 2, zoom: links::LinkZoom::FitPage },
&links::LinkStyle { visible: true, width: 2.0, dashed: true, ..Default::default() },
)
.expect("links to page 3");
@@ -735,7 +735,7 @@ fn links_keep_page_targets_uri_and_dash_structure_across_renumbering() {
.into_iter()
.map(|l| {
let a = match l.action {
links::LinkAction::Page(p) => format!("page {p}"),
links::LinkAction::Page { page: p, zoom: _ } => format!("page {p}"),
links::LinkAction::Uri(u) => u,
links::LinkAction::Other(o) => format!("other:{o}"),
};
@@ -770,7 +770,14 @@ fn links_keep_page_targets_uri_and_dash_structure_across_renumbering() {
fn removing_all_links_keeps_comments() {
let mut doc = blank(2);
add_annotation(&mut doc, &ann(0, Shape::Note { at: [50.0, 700.0], icon: NoteIcon::Help }, "note"), &meta("n")).expect("adds");
links::add(&mut doc, 0, [200.0, 700.0, 300.0, 715.0], &links::LinkAction::Page(0), &links::LinkStyle::default()).expect("links");
links::add(
&mut doc,
0,
[200.0, 700.0, 300.0, 715.0],
&links::LinkAction::Page { page: 0, zoom: links::LinkZoom::FitPage },
&links::LinkStyle::default(),
)
.expect("links");
let removed = links::remove_all(&mut doc, None).expect("removes all links");
assert_eq!(removed, 1);
@@ -980,7 +987,7 @@ fn a_full_rewrite_into_object_streams_describes_the_same_comments_as_a_plain_tab
assert_eq!(summaries(&plain).len(), summaries(&packed).len());
// The plain-table output is bigger here: object streams compress, which is the point of them.
let opts = SaveOptions { mod_date: None, id_seed: 0x5052_494E_5443_5241, object_streams: true, drop_unlinked: false };
let opts = SaveOptions { mod_date: None, id_seed: 0x5052_494E_5443_5241, object_streams: true, drop_unlinked: false, id_entropy: None };
let packed_bytes = pdfcraft_cos::write_full(&doc, &opts).expect("writes");
assert!(
packed_bytes.len() < pdfcraft_cos::write_full(&doc, &SaveOptions { object_streams: false, ..opts }).expect("writes").len(),
+7 -1
View File
@@ -118,7 +118,13 @@ pub fn save_and_reopen(doc: &Document, path: Save) -> (Vec<u8>, Document) {
/// Save with the path's options. `/Info /ModDate` is left unset so a full save adds nothing that
/// would make byte comparisons depend on the clock.
pub fn save(doc: &Document, path: Save) -> Vec<u8> {
let opts = SaveOptions { mod_date: None, id_seed: 0x5052_494E_5443_5241, object_streams: path == Save::FullStreams, drop_unlinked: false };
let opts = SaveOptions {
mod_date: None,
id_seed: 0x5052_494E_5443_5241,
object_streams: path == Save::FullStreams,
drop_unlinked: false,
id_entropy: None,
};
match path {
Save::Incremental => write_incremental(doc, &opts),
Save::FullTable | Save::FullStreams => write_full(doc, &opts),