/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright © 2024 Mike Robeson [dijksterhuis]
*/

mod helpers;

use helpers::*;
use ot_tools_io::{BankFile, OctatrackFileIO};
use std::env::temp_dir;
use std::fs::create_dir_all;

fn test_helper(fname: &str) -> BankFile {
    let fpath = get_bank_dirpath().join(fname);
    let r = BankFile::from_data_file(&fpath);
    println!("result: {r:?}");
    assert!(r.is_ok());
    r.unwrap()
}
#[test]
fn default() -> RBoxErr<()> {
    let bank = test_helper("default.work");
    let valid = BankFile::default();
    assert_eq!(bank, valid);
    Ok(())
}

#[test]
fn write_default_then_read() -> RBoxErr<()> {
    let path = temp_dir()
        .join(CRATE_NAME)
        .join("read_bank_files")
        .join("write_read_default.work");
    let dirpath = path.parent().unwrap();
    if !dirpath.exists() {
        create_dir_all(dirpath)?;
    }
    BankFile::default().to_data_file(&path)?;
    assert_eq!(BankFile::default(), BankFile::from_data_file(&path)?);

    Ok(())
}
