Skip to content

Commit 159986b

Browse files
committed
Add some tests
1 parent c0c0e3d commit 159986b

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/content.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,4 +1735,45 @@ mod tests {
17351735
b"/F1 12 Tf\nBT\n[] TJ\n[(AB) 2 (CD)] TJ\nET"
17361736
);
17371737
}
1738+
1739+
#[test]
1740+
fn test_content_array_no_pretty() {
1741+
let mut content = Content::new_with(WriteSettings { pretty: false });
1742+
1743+
content.set_font(Name(b"F1"), 12.0);
1744+
content.begin_text();
1745+
content.show_positioned().items();
1746+
content
1747+
.show_positioned()
1748+
.items()
1749+
.show(Str(b"AB"))
1750+
.adjust(2.0)
1751+
.show(Str(b"CD"))
1752+
.adjust(4.0)
1753+
.show(Str(b"EF"));
1754+
content.end_text();
1755+
1756+
assert_eq!(
1757+
content.finish().into_vec(),
1758+
b"/F1 12 Tf\nBT\n[] TJ\n[(AB)2(CD)4(EF)] TJ\nET"
1759+
);
1760+
}
1761+
1762+
// TODO: Dont' write newlines between operations if not necessary?
1763+
1764+
#[test]
1765+
fn test_content_dict_no_pretty() {
1766+
let mut content = Content::new_with(WriteSettings { pretty: false });
1767+
1768+
let mut mc = content.begin_marked_content_with_properties(Name(b"Test"));
1769+
let mut properties = mc.properties();
1770+
properties.actual_text(TextStr("Actual")).identify(1);
1771+
properties.artifact().kind(ArtifactType::Background);
1772+
mc.finish();
1773+
1774+
assert_eq!(
1775+
content.finish().into_vec(),
1776+
b"/Test<</ActualText(Actual)/MCID 1/Type/Background>> BDC"
1777+
);
1778+
}
17381779
}

src/object.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ fn is_regular_character(byte: u8) -> bool {
356356
)
357357
}
358358

359+
#[inline]
360+
fn is_delimiter_character(byte: u8) -> bool {
361+
matches!(byte, b'(' | b')' | b'<' | b'>' | b'[' | b']' | b'/' | b'%')
362+
}
363+
359364
/// The null object.
360365
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
361366
pub struct Null;
@@ -646,7 +651,9 @@ impl<'a> Obj<'a> {
646651
/// Write a primitive object.
647652
#[inline]
648653
pub fn primitive<T: Primitive>(self, value: T) {
649-
if self.needs_padding && !T::HAS_DELIMITER {
654+
let ends_with_delimiter = self.buf.last().copied().is_some_and(is_delimiter_character);
655+
656+
if self.needs_padding && !T::HAS_DELIMITER && !ends_with_delimiter {
650657
self.buf.extend(b" ");
651658
}
652659

0 commit comments

Comments
 (0)