use sheets_diff::core::utils::{cell_pos_to_address, col_to_label};
#[test]
fn col_labels_cover_excel_width() {
let cases: &[(usize, &str)] = &[
(1, "A"),
(2, "B"),
(26, "Z"),
(27, "AA"),
(52, "AZ"),
(53, "BA"),
(255, "IU"),
(256, "IV"),
(257, "IW"),
(702, "ZZ"),
(703, "AAA"),
(704, "AAB"),
(16384, "XFD"),
];
for &(col, expected) in cases {
assert_eq!(col_to_label(col), expected, "col_to_label({col})");
}
}
#[test]
fn cell_addresses_are_correct() {
assert_eq!(cell_pos_to_address(1, 1), "A1");
assert_eq!(cell_pos_to_address(25, 27), "AA25");
assert_eq!(cell_pos_to_address(1048576, 16384), "XFD1048576");
}
#[test]
fn column_256_and_257_are_correct() {
assert_eq!(cell_pos_to_address(1, 256), "IV1");
assert_eq!(cell_pos_to_address(1, 257), "IW1");
}
#[test]
fn cell_sort_order_is_numeric() {
use sheets_diff::core::diff::{CellDiff, CellDiffKind};
let mut cells: Vec<CellDiff> = vec![
CellDiff {
row: 10,
col: 1,
addr: "A10".into(),
kind: CellDiffKind::Value,
old: Some("x".into()),
new: None,
},
CellDiff {
row: 2,
col: 1,
addr: "A2".into(),
kind: CellDiffKind::Value,
old: Some("y".into()),
new: None,
},
CellDiff {
row: 1,
col: 1,
addr: "A1".into(),
kind: CellDiffKind::Value,
old: Some("z".into()),
new: None,
},
];
cells.sort_by(|a, b| {
a.row
.cmp(&b.row)
.then_with(|| a.col.cmp(&b.col))
.then_with(|| a.kind.cmp(&b.kind))
});
let rows: Vec<usize> = cells.iter().map(|c| c.row).collect();
assert_eq!(rows, vec![1, 2, 10]);
}