use littlefs2::{
    consts,
    fs::{File, Filesystem},
    io::{Error, Result},
    ram_storage, driver,
};

ram_storage!(
    name=OtherRamStorage,
    backend=OtherRam,
    trait=driver::Storage,
    erase_value=0xff,
    read_size=1,
    write_size=32,
    cache_size_ty=consts::U32,
    block_size=256,
    block_count=512,
    lookaheadwords_size_ty=consts::U1,
    filename_max_plus_one_ty=consts::U256,
    path_max_plus_one_ty=consts::U256,
    result=Result,
);

ram_storage!(
    name=RamStorage,
    backend=Ram,
    trait=driver::Storage,
    erase_value=0xff,
    read_size=20*5,
    write_size=20*7,
    cache_size_ty=consts::U700,
    block_size=20*35,
    block_count=32,
    lookaheadwords_size_ty=consts::U1,
    filename_max_plus_one_ty=consts::U256,
    path_max_plus_one_ty=consts::U256,
    result=Result,
);

fn main() {
    let mut other_ram = OtherRam::default();
    let mut other_storage = OtherRamStorage::new(&mut other_ram);
    let mut alloc = Filesystem::allocate();
    assert!(Filesystem::format(&mut other_storage).is_ok());
    let other_fs = Filesystem::mount(&mut alloc, &mut other_storage).unwrap();

    let mut ram = Ram::default();
    let mut storage = RamStorage::new(&mut ram);
    let mut alloc = Filesystem::allocate();
    Filesystem::format(&mut storage).unwrap();
    let mut fs = Filesystem::mount(&mut alloc, &mut storage).unwrap();

    let mut alloc = File::allocate();
    // file does not exist yet, can't open for reading
    assert_eq!(
        File::open("/test_open.txt", &mut alloc, &mut fs, &mut storage)
            .map(drop)
            .unwrap_err(), // "real" contains_err is experimental
        Error::NoSuchEntry
    );

    // won't work: "expected struct `tests::RamStorage`, found struct
    // `tests::RamStorageNormal`.
    fs.create_dir("/tmp", &mut other_storage).unwrap();
}
