aoc-toolkit 0.1.0-alpha.2

A toolkit for solving Advent of Code problems
Documentation
use super::*;

use tempfile::tempdir;

#[test]
fn generates_expected_input_path() {
    let directory = tempdir().unwrap();
    let store = InputStore::new(directory.path());

    assert_eq!(
        store.input_path(2026, 1),
        directory.path().join("2026/1.txt"),
    );
}

#[test]
fn returns_cached_input_without_http_client() {
    let directory = tempdir().unwrap();
    let mut store = InputStore::new(directory.path());

    let path = store.input_path(2026, 1);

    InputStore::store(&path, "cached-input\n").unwrap();

    let input = store.get(2026, 1).unwrap();

    assert_eq!(input, "cached-input\n");
    assert!(store.http.is_none());
}

#[test]
fn returns_cache_miss_for_missing_file() {
    let directory = tempdir().unwrap();

    let cached = InputStore::read_cached(&directory.path().join("missing.txt")).unwrap();

    assert_eq!(cached, None);
}

#[test]
fn returns_cache_miss_for_empty_file() {
    let directory = tempdir().unwrap();
    let path = directory.path().join("empty.txt");

    fs::write(&path, "").unwrap();

    assert_eq!(InputStore::read_cached(&path).unwrap(), None,);
}

#[test]
fn creates_cache_directories() {
    let directory = tempdir().unwrap();
    let store = InputStore::new(directory.path());

    let path = store.input_path(2026, 5);

    InputStore::store(&path, "input").unwrap();

    assert_eq!(fs::read_to_string(path).unwrap(), "input",);
}

#[test]
fn reports_invalid_cached_content() {
    let directory = tempdir().unwrap();
    let path = directory.path().join("invalid.txt");

    fs::write(&path, [0xff]).unwrap();

    assert!(matches!(
        InputStore::read_cached(&path),
        Err(ClientError::Io { .. })
    ));
}