#[cfg(test)] mod tests { use std::{ fs::{self, File}, path::Path, }; use enum_iterator::all; use log::info; use power_utils::{rendering::RenderingFormat, tests::create_temporary_fixture_folder}; fn init() { let _global_logger = env_logger::builder().is_test(true).try_init(); } /// Given: /// - A valid module /// /// When: /// - That module is bound into all possible formats /// /// Then: /// - No error is thrown; and /// - The result is a valid book representation for each format #[test] fn bind_to_all_formats() { init(); let dir = create_temporary_fixture_folder("tests/fixtures/sample_module").unwrap(); assert!(dir.path().exists()); let module = power_flatten::flatten(dir.path().join("sample_module").as_path()).unwrap(); let output_file_path = dir.path().join("sample_module.json"); File::create(&output_file_path).unwrap(); let contents = serde_json::to_string_pretty(&module).unwrap(); info!("{}", contents); fs::write(&output_file_path, contents).unwrap(); for format in all::() { let actual = power_binder::bind(&output_file_path, format.clone()).unwrap(); let expected = fs::read_to_string(format!( "tests/fixtures/output/sample_module.{}", format.to_string() )) .unwrap(); assert_eq!( actual, expected, "rendering for format \"{}\" did not match", format ); } } }