use checkpointkit::{load, save, CheckpointError};
use tempfile::tempdir;
#[test]
fn test_save_massive_file() {
let dir = tempdir().unwrap();
let path = dir.path().join("massive.json");
let state = "A".repeat(10 * 1024 * 1024);
assert!(save(&path, &state).is_ok(), "saving large file should succeed");
let loaded: Option<String> = load(&path).unwrap();
assert_eq!(loaded.unwrap().len(), 10 * 1024 * 1024, "loaded string length should match");
}
#[test]
fn test_save_unicode_path() {
let dir = tempdir().unwrap();
let path = dir.path().join("😈.json");
let state = 42;
assert!(save(&path, &state).is_ok(), "saving to unicode path should succeed");
let loaded: Option<i32> = load(&path).unwrap();
assert_eq!(loaded, Some(42), "loaded state should match");
}
#[test]
fn test_save_deeply_nested_path() {
let dir = tempdir().unwrap();
let mut path = dir.path().to_path_buf();
for i in 0..100 {
path.push(format!("dir_{i}"));
}
path.push("test.json");
let state = 42;
assert!(save(&path, &state).is_ok(), "saving to deeply nested path should succeed");
let loaded: Option<i32> = load(&path).unwrap();
assert_eq!(loaded, Some(42), "loaded state should match");
}
#[test]
fn test_load_malformed_json() {
let dir = tempdir().unwrap();
let path = dir.path().join("malformed.json");
std::fs::write(&path, "{malformed_json}").unwrap();
let result: Result<Option<i32>, _> = load(&path);
assert!(
matches!(result, Err(CheckpointError::Serialize(_))),
"Expected Serialize error, got {result:?}"
);
}
#[test]
fn test_load_wrong_type() {
let dir = tempdir().unwrap();
let path = dir.path().join("wrong_type.json");
let state = "a string";
save(&path, &state).unwrap();
let result: Result<Option<i32>, _> = load(&path);
assert!(
matches!(result, Err(CheckpointError::Serialize(_))),
"Expected Serialize error due to wrong type, got {result:?}"
);
}
mod test_depth_adversarial;