Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl<T: CellType> Cell<T> {
/// A `Range` contains a vector of cells of of generic type `T` which implement
/// the [`CellType`] trait. The values are stored in a row-major order.
///
#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Range<T> {
start: (u32, u32),
end: (u32, u32),
Expand Down Expand Up @@ -691,12 +691,7 @@ impl<T: CellType> Range<T> {
///
/// # Parameters
///
/// - `cells`: A vector of non-empty [`Cell`] elements, sorted by row. The
/// first and last cells define the start and end positions of the range.
///
/// # Panics
///
/// Panics when a `Cell` row is less than the first `Cell` row.
/// - `cells`: A vector of [`Cell`] elements.
///
/// # Examples
///
Expand All @@ -723,15 +718,18 @@ impl<T: CellType> Range<T> {
/// ```
///
pub fn from_sparse(cells: Vec<Cell<T>>) -> Range<T> {
let (row_start, row_end) = match &cells[..] {
[] => return Range::empty(),
[first] => (first.pos.0, first.pos.0),
[first, .., last] => (first.pos.0, last.pos.0),
};
if cells.is_empty() {
return Range::empty();
}
// cells do not always appear in (row, col) order
// search bounds
let mut row_start = u32::MAX;
let mut row_end = 0;
let mut col_start = u32::MAX;
let mut col_end = 0;
for c in cells.iter().map(|c| c.pos.1) {
for (r, c) in cells.iter().map(|c| c.pos) {
row_start = min(r, row_start);
row_end = max(r, row_end);
col_start = min(c, col_start);
col_end = max(c, col_end);
}
Expand Down
2 changes: 1 addition & 1 deletion src/xls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ struct Bof {
}

/// <https://www.loc.gov/preservation/digital/formats/fdd/fdd000510.shtml#notes>
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum Biff {
Biff2,
Biff3,
Expand Down
Binary file added tests/OOM_alloc.xls
Binary file not shown.
13 changes: 8 additions & 5 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,8 +1280,8 @@ fn issue_271() -> Result<(), calamine::Error> {
loop {
let mut workbook: Xls<_> = wb("issue_271.xls");
let v = workbook.worksheets();
let (_sheetname, range) = v.first().expect("bad format");
dbg!(_sheetname);
let (sheetname, range) = v.first().expect("bad format");
assert_eq!(sheetname, "sheet1");
let value = range.get((0, 1)).map(|s| s.to_string());
values.push(value);
count += 1;
Expand All @@ -1290,12 +1290,10 @@ fn issue_271() -> Result<(), calamine::Error> {
}
}

dbg!(&values);

values.sort_unstable();
values.dedup();

assert_eq!(values.len(), 1);
assert_eq!(&values, &[Some("yyy_name".to_string())]);

Ok(())
}
Expand Down Expand Up @@ -2142,3 +2140,8 @@ fn test_string_ref() {
fn test_malformed_format() {
let _xls: Xls<_> = wb("malformed_format.xls");
}

#[test]
fn test_oom_allocation() {
let _xls: Xls<_> = wb("OOM_alloc.xls");
}