use ansiconv::{ANSIColor, ANSIParser, ANSI2TeX};
use log::debug;
use std::error::Error;
use std::io::{BufReader, Cursor};

#[test]
fn test_err_files() -> Result<(), Box<dyn Error>> {

  // Enable logging display
  env_logger::Builder::new().filter_level(log::LevelFilter::Trace).init();

  for entry in glob::glob("tests/res/auto/err/*.txt")? {

    let ansi_file = entry?;

    // Create converter instance
    let mut cursor = Cursor::new(Vec::<u8>::new());
    let mut conv = ANSI2TeX::new(&mut cursor)
      .fg_default_color(ANSIColor::new(255,255,255));
    debug!("Converter created.");

    // Create parser instance
    let in_file = std::fs::OpenOptions::new().read(true).open(&ansi_file)?;
    let mut buf_reader = BufReader::new(in_file);
    let mut parser = ANSIParser::new(&mut buf_reader);
    debug!("Parser created.");

    // Parse
    assert!(parser.accept(&mut conv).is_err(), "No error on file {}",
      ansi_file.display());
  }

  Ok(())
}
