diff --git a/crates/xlsx/src/lib.rs b/crates/xlsx/src/lib.rs
index 3d2853972..14d1a9f3c 100644
--- a/crates/xlsx/src/lib.rs
+++ b/crates/xlsx/src/lib.rs
@@ -35,7 +35,7 @@
//!
//! ```
//! # fn main() -> Result<(), craft_xlsx::Error> {
-//! # let bytes = craft_xlsx::testing::workbook(&[("Prices", r#"02.5
"#)], &["Tea"]);
+//! # let bytes = craft_xlsx::testing::workbook(&[("Prices", r#"02.5
"#)], &["Tea"])?;
//! let mut package = craft_xlsx::Package::open(&bytes, &craft_xlsx::Limits::default())?;
//! let workbook = package.workbook()?;
//! let strings = package.shared_strings()?;
diff --git a/crates/xlsx/src/testing.rs b/crates/xlsx/src/testing.rs
index 43920f42d..3f425f7ee 100644
--- a/crates/xlsx/src/testing.rs
+++ b/crates/xlsx/src/testing.rs
@@ -6,8 +6,9 @@ const MAIN_NS: &str = "http://schemas.openxmlformats.org/spreadsheetml/2006/main
const R_NS: &str = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
/// An `.xlsx` with the given sheets, each `(name, the rows inside )`, and shared
-/// strings. Names and strings are written as given: escape them first if they need it.
-pub fn workbook(sheets: &[(&str, &str)], strings: &[&str]) -> Vec {
+/// strings. Names and strings are written as given: escape them first if they need it. An
+/// archive that cannot be written returns the writer's error.
+pub fn workbook(sheets: &[(&str, &str)], strings: &[&str]) -> Result, craft_opc::Error> {
let mut out = PackageOut::default();
let mut root = RelsOut::default();
root.add("officeDocument", "xl/workbook.xml", false);
@@ -40,11 +41,13 @@ pub fn workbook(sheets: &[(&str, &str)], strings: &[&str]) -> Vec {
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
format!(r#"{list}"#).into_bytes(),
);
- out.finish().unwrap_or_default()
+ out.finish()
}
-/// A ZIP archive of the given entries, stored as named (no content types are added).
-pub fn zip(entries: &[(&str, &[u8])]) -> Vec {
+/// A ZIP archive of the given entries, stored as named (no content types are added). An entry
+/// the archive cannot hold, such as a second entry under the same name, returns the writer's
+/// error.
+pub fn zip(entries: &[(&str, &[u8])]) -> Result, craft_opc::Error> {
let entries: Vec<(String, Vec)> = entries.iter().map(|(n, b)| (n.to_string(), b.to_vec())).collect();
- craft_opc::zip_entries(&entries).unwrap_or_default()
+ craft_opc::zip_entries(&entries)
}
diff --git a/crates/xlsx/tests/pivot.rs b/crates/xlsx/tests/pivot.rs
index 4d2fd00d5..efcd76e29 100644
--- a/crates/xlsx/tests/pivot.rs
+++ b/crates/xlsx/tests/pivot.rs
@@ -60,6 +60,7 @@ fn with_pivots() -> Vec {
("xl/pivotCache/pivotCacheRecords1.xml", RECORDS.as_bytes()),
("xl/pivotCache/pivotCacheDefinition2.xml", OLAP.as_bytes()),
])
+ .unwrap()
}
#[test]
@@ -160,7 +161,7 @@ fn pivots_round_trip() {
#[test]
fn a_new_pivot_table() {
- let mut doc = read(&craft_xlsx::testing::workbook(&[("Data", r#"1
"#), ("Report", "")], &[]));
+ let mut doc = read(&craft_xlsx::testing::workbook(&[("Data", r#"1
"#), ("Report", "")], &[]).unwrap());
let values = [CacheValue::Number(1.0), CacheValue::Number(2.0)];
let definition = PivotCacheDefinition {
refresh_on_load: Some(true),
diff --git a/crates/xlsx/tests/richdata.rs b/crates/xlsx/tests/richdata.rs
index a5879dcf5..4a265e290 100644
--- a/crates/xlsx/tests/richdata.rs
+++ b/crates/xlsx/tests/richdata.rs
@@ -12,7 +12,7 @@ fn png(w: u32, h: u32, tag: u8) -> Vec {
}
fn new_doc() -> Document {
- Document::read(&workbook(&[("S", r#"#VALUE!
"#)], &[]), &Limits::default()).unwrap()
+ Document::read(&workbook(&[("S", r#"#VALUE!
"#)], &[]).unwrap(), &Limits::default()).unwrap()
}
fn part(doc: &Document, name: &str) -> String {
diff --git a/crates/xlsx/tests/write.rs b/crates/xlsx/tests/write.rs
index bb7cc683b..c080e7e96 100644
--- a/crates/xlsx/tests/write.rs
+++ b/crates/xlsx/tests/write.rs
@@ -75,6 +75,7 @@ fn excel_like() -> Vec {
("xl/drawings/vmlDrawing1.vml", VML.as_bytes()),
("xl/vbaProject.bin", &[0xD0, 0xCF, 0x11, 0xE0, 1, 2, 3]),
])
+ .unwrap()
}
const COMMENTS: &str = "AnnAnn:\nnote";
diff --git a/crates/xlsx/tests/xlsb.rs b/crates/xlsx/tests/xlsb.rs
index a7253df22..3611cafbb 100644
--- a/crates/xlsx/tests/xlsb.rs
+++ b/crates/xlsx/tests/xlsb.rs
@@ -114,6 +114,7 @@ fn package(book: &[u8], sheet: &[u8], strings: &[u8], roots: &str, rels: &str, t
("data/two.bin", &worksheet(&[], &[])),
("text/strings.bin", strings),
])
+ .unwrap()
}
fn file(sheet: &[u8]) -> Vec {
package(&book(false), sheet, &sst(), ROOT, RELS, TYPES)
@@ -346,6 +347,7 @@ fn two_sheets(one: &[u8], two: &[u8]) -> Vec {
("data/two.bin", two),
("text/strings.bin", &sst()),
])
+ .unwrap()
}
#[test]
diff --git a/crates/xlsx/tests/xlsx.rs b/crates/xlsx/tests/xlsx.rs
index ef932026e..b5ebdf2c7 100644
--- a/crates/xlsx/tests/xlsx.rs
+++ b/crates/xlsx/tests/xlsx.rs
@@ -42,6 +42,7 @@ fn strict() -> Vec {
.as_bytes(),
),
])
+ .unwrap()
}
#[test]
@@ -101,7 +102,8 @@ fn a_strict_workbook_with_prefixes() {
#[test]
fn a_damaged_sheet_keeps_the_rows_before_the_damage() {
- let bytes = workbook(&[("S", r#"1
2