fast-fs 0.2.1

High-speed async file system traversal library with batteries-included file browser component
Documentation
// <FILE>crates/fast-fs/tests/reader/test_reader_functions.rs</FILE> - <DESC>Basic reader function tests</DESC>
// <VERS>VERSION: 0.2.0</VERS>
// <WCTX>Implementing enhanced read_dir_recursive with TraversalOptions</WCTX>
// <CLOG>Updated read_dir_recursive tests to use TraversalOptions API</CLOG>

use fast_fs::{read_dir, read_dir_recursive, read_dir_visible, Error, TraversalOptions};
use std::fs::File;
use tempfile::tempdir;

#[tokio::test]
async fn test_read_dir() {
    let dir = tempdir().unwrap();
    File::create(dir.path().join("file1.txt")).unwrap();
    File::create(dir.path().join("file2.txt")).unwrap();
    std::fs::create_dir(dir.path().join("subdir")).unwrap();
    let entries = read_dir(dir.path()).await.unwrap();
    assert_eq!(entries.len(), 3);
}

#[tokio::test]
async fn test_read_dir_visible() {
    let dir = tempdir().unwrap();
    File::create(dir.path().join("visible.txt")).unwrap();
    File::create(dir.path().join(".hidden")).unwrap();
    let entries = read_dir_visible(dir.path()).await.unwrap();
    assert_eq!(entries.len(), 1);
    assert_eq!(entries[0].name, "visible.txt");
}

#[tokio::test]
async fn test_not_found() {
    let result = read_dir("/nonexistent/path").await;
    assert!(matches!(result, Err(Error::NotFound(_))));
}

#[tokio::test]
async fn test_not_directory() {
    let dir = tempdir().unwrap();
    let file_path = dir.path().join("file.txt");
    File::create(&file_path).unwrap();
    let result = read_dir(&file_path).await;
    assert!(matches!(result, Err(Error::NotDirectory(_))));
}

#[tokio::test]
async fn test_read_dir_recursive_basic() {
    let dir = tempdir().unwrap();
    File::create(dir.path().join("root.txt")).unwrap();
    std::fs::create_dir(dir.path().join("level1")).unwrap();
    File::create(dir.path().join("level1/nested.txt")).unwrap();
    std::fs::create_dir(dir.path().join("level1/level2")).unwrap();
    File::create(dir.path().join("level1/level2/deep.txt")).unwrap();

    // Depth 0 = only root
    let options = TraversalOptions::default()
        .with_max_depth(0)
        .with_gitignore(false);
    let entries = read_dir_recursive(dir.path(), options).await.unwrap();
    assert_eq!(entries.len(), 2); // root.txt + level1/

    // Depth 1 = root + level1 contents
    let options = TraversalOptions::default()
        .with_max_depth(1)
        .with_gitignore(false);
    let entries = read_dir_recursive(dir.path(), options).await.unwrap();
    assert_eq!(entries.len(), 4); // root.txt, level1/, level1/nested.txt, level1/level2/

    // Depth 2 = all files
    let options = TraversalOptions::default()
        .with_max_depth(2)
        .with_gitignore(false);
    let entries = read_dir_recursive(dir.path(), options).await.unwrap();
    assert_eq!(entries.len(), 5);
}

// <FILE>crates/fast-fs/tests/reader/test_reader_functions.rs</FILE>
// <VERS>END OF VERSION: 0.2.0</VERS>