checkpointkit 0.1.2

Crash-resume checkpoint persistence with atomic writes and progress tracking
Documentation
//! Extreme scale tests for checkpointkit.

use checkpointkit::{load, save};

#[test]
fn save_load_empty_string() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("empty.json");
    save(&path, &String::new()).unwrap();
    let loaded: Option<String> = load(&path).unwrap();
    assert_eq!(loaded, Some(String::new()));
}

#[test]
fn save_load_1mb_string() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("big.json");
    let big = "x".repeat(1_000_000);
    save(&path, &big).unwrap();
    let loaded: Option<String> = load(&path).unwrap();
    assert_eq!(loaded.unwrap().len(), 1_000_000);
}

#[test]
fn save_load_nested_structure() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("nested.json");
    let data: Vec<Vec<u32>> = (0..100)
        .map(|i| (0..100).map(|j| i * 100 + j).collect())
        .collect();
    save(&path, &data).unwrap();
    let loaded: Option<Vec<Vec<u32>>> = load(&path).unwrap();
    assert_eq!(loaded.unwrap().len(), 100);
}

#[test]
fn load_corrupted_returns_error() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("corrupt.json");
    std::fs::write(&path, b"this is not json {{{").unwrap();
    let result: std::result::Result<Option<String>, _> = load(&path);
    assert!(result.is_err());
}

#[test]
fn save_overwrite_existing() {
    let dir = tempfile::tempdir().unwrap();
    let path = dir.path().join("overwrite.json");
    save(&path, &"first").unwrap();
    save(&path, &"second").unwrap();
    let loaded: Option<String> = load(&path).unwrap();
    assert_eq!(loaded.unwrap(), "second");
}