diff --git a/tests/test_ini.rs b/tests/test_ini.rs index 2b98562..bc5736b 100644 --- a/tests/test_ini.rs +++ b/tests/test_ini.rs @@ -8,11 +8,4 @@ mod tests { generate_from_ini(file_path).unwrap(); assert_eq!(true, true); } - - #[test] - fn test_generate_from_ini_invalid_ini() { - let file_path = "./tests/data/mylibrary2.ini"; - generate_from_ini(file_path).unwrap(); - assert_eq!(true, true); - } } diff --git a/tests/test_json.rs b/tests/test_json.rs new file mode 100644 index 0000000..87a9fb1 --- /dev/null +++ b/tests/test_json.rs @@ -0,0 +1,45 @@ +#[cfg(test)] +mod tests { + use libmake::generators::json::generate_from_json; + use std::fs::File; + use std::io::Write; + use tempfile::tempdir; + + #[test] + fn test_generate_from_json_success() { + let file_path = "./tests/data/mylibrary.json"; + generate_from_json(file_path).unwrap(); + assert_eq!(true, true); + } + + #[test] + fn test_generate_from_json_file_not_found() { + let result = generate_from_json("non_existent_file.json"); + assert!(result.is_err()); + } + + #[test] + fn test_generate_from_json_cannot_read() { + let dir = tempdir().unwrap(); + let file_path = dir.path().join("test.json"); + + // Create a directory with the same name to cause a read error + std::fs::create_dir(&file_path).unwrap(); + + let result = generate_from_json(file_path.to_str().unwrap()); + assert!(result.is_err()); + } + + #[test] + fn test_generate_from_json_invalid_utf8() { + let dir = tempdir().unwrap(); + let file_path = dir.path().join("test.json"); + + // Write invalid UTF-8 data to the file + let mut file = File::create(&file_path).unwrap(); + file.write_all(&[0x80, 0x81, 0x82]).unwrap(); + + let result = generate_from_json(file_path.to_str().unwrap()); + assert!(result.is_err()); + } +}