spreadsheet-column 0.1.0

Convert between spreadsheet column numbers and letters (1 <-> A, 27 <-> AA). A faithful port of the spreadsheet-column npm package. Zero deps, no_std.
Documentation
//! Integration tests exercising the public API of `spreadsheet-column`.

use spreadsheet_column::{from_int, from_str, Error, SpreadsheetColumn};

#[test]
fn known_columns() {
    assert_eq!(from_int(1).unwrap(), "A");
    assert_eq!(from_int(28).unwrap(), "AB");
    assert_eq!(from_int(703).unwrap(), "AAA");
    assert_eq!(from_str("ABC").unwrap(), 731);
    assert_eq!(from_str("xfd").unwrap(), 16384);
}

#[test]
fn round_trip_to_excel_max() {
    for n in (1..=16384).step_by(7) {
        let letters = from_int(n).unwrap();
        assert_eq!(from_str(&letters).unwrap(), n);
    }
}

#[test]
fn zero_based_mode() {
    let sc = SpreadsheetColumn::zero_based();
    assert_eq!(sc.from_int(0).unwrap(), "A");
    assert_eq!(sc.from_int(701).unwrap(), "ZZ");
    assert_eq!(sc.from_str("ZZ").unwrap(), 701);
}

#[test]
fn error_cases() {
    assert_eq!(from_int(0), Err(Error::ZeroNotAllowed));
    assert_eq!(from_int(-5), Err(Error::Negative));
    assert_eq!(from_str("A1"), Err(Error::InvalidString));
    assert_eq!(from_str(""), Err(Error::InvalidString));
}