From 6463816fd982347025826a66a8bcd112bc962255 Mon Sep 17 00:00:00 2001 From: Sebastien Rousseau Date: Thu, 16 May 2024 00:31:39 +0100 Subject: [PATCH] test(libmake): :white_check_mark: add new tests and refactoring --- Cargo.toml | 6 +++--- tests/generators/mod.rs | 26 ++++++++++++++++++++++++++ tests/{ => generators}/test_args.rs | 0 tests/{ => generators}/test_ascii.rs | 0 tests/{ => generators}/test_csv.rs | 0 tests/{ => generators}/test_ini.rs | 0 tests/{ => generators}/test_json.rs | 0 tests/{ => generators}/test_toml.rs | 0 tests/{ => generators}/test_yaml.rs | 0 tests/macros/test_ascii_macros.rs | 8 ++++++-- tests/macros/test_utility_macros.rs | 23 ++++++++++++++++------- 11 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 tests/generators/mod.rs rename tests/{ => generators}/test_args.rs (100%) rename tests/{ => generators}/test_ascii.rs (100%) rename tests/{ => generators}/test_csv.rs (100%) rename tests/{ => generators}/test_ini.rs (100%) rename tests/{ => generators}/test_json.rs (100%) rename tests/{ => generators}/test_toml.rs (100%) rename tests/{ => generators}/test_yaml.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 280ff78..00b3f6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,12 +71,12 @@ log = {version="0.4.21", features = ["std"] } regex = "1.10.4" reqwest = { version = "0.12.4", features = ["blocking"] } rlg = "0.0.4" -serde = { version = "1.0.201", features = ["derive"] } +serde = { version = "1.0.202", features = ["derive"] } serde_ini = "0.2.0" serde_json = "1.0.117" -serde_yml = "0.0.5" +serde_yml = "0.0.7" tempfile = "3.10.1" -toml = "0.8.12" +toml = "0.8.13" uuid = { version = "1.8.0", features = ["v4"] } vrd = "0.0.7" diff --git a/tests/generators/mod.rs b/tests/generators/mod.rs new file mode 100644 index 0000000..d907212 --- /dev/null +++ b/tests/generators/mod.rs @@ -0,0 +1,26 @@ +// Copyright notice and licensing information. +// These lines indicate the copyright of the software and its licensing terms. +// SPDX-License-Identifier: Apache-2.0 OR MIT indicates dual licensing under Apache 2.0 or MIT licenses. +// Copyright © 2023-2024 LibMake. All rights reserved. + +/// The `test_ascii` module contains functionality for generating ASCII art from +/// text using the FIGlet library. +pub mod test_ascii; + +/// The `test_args` module contains functionality for parsing command-line arguments. +pub mod test_args; + +/// The `test_csv` module contains functionality for parsing CSV files. +pub mod test_csv; + +/// The `test_ini` module contains functionality for parsing INI files. +pub mod test_ini; + +/// The `test_json` module contains functionality for parsing JSON files. +pub mod test_json; + +/// The `test_toml` module contains functionality for parsing TOML files. +pub mod test_toml; + +/// The `test_yaml` module contains functionality for parsing YAML files. +pub mod test_yaml; diff --git a/tests/test_args.rs b/tests/generators/test_args.rs similarity index 100% rename from tests/test_args.rs rename to tests/generators/test_args.rs diff --git a/tests/test_ascii.rs b/tests/generators/test_ascii.rs similarity index 100% rename from tests/test_ascii.rs rename to tests/generators/test_ascii.rs diff --git a/tests/test_csv.rs b/tests/generators/test_csv.rs similarity index 100% rename from tests/test_csv.rs rename to tests/generators/test_csv.rs diff --git a/tests/test_ini.rs b/tests/generators/test_ini.rs similarity index 100% rename from tests/test_ini.rs rename to tests/generators/test_ini.rs diff --git a/tests/test_json.rs b/tests/generators/test_json.rs similarity index 100% rename from tests/test_json.rs rename to tests/generators/test_json.rs diff --git a/tests/test_toml.rs b/tests/generators/test_toml.rs similarity index 100% rename from tests/test_toml.rs rename to tests/generators/test_toml.rs diff --git a/tests/test_yaml.rs b/tests/generators/test_yaml.rs similarity index 100% rename from tests/test_yaml.rs rename to tests/generators/test_yaml.rs diff --git a/tests/macros/test_ascii_macros.rs b/tests/macros/test_ascii_macros.rs index 5b69238..de9a5fb 100644 --- a/tests/macros/test_ascii_macros.rs +++ b/tests/macros/test_ascii_macros.rs @@ -9,13 +9,17 @@ mod tests { } #[test] - #[should_panic(expected = "Failed to generate ASCII art: Failed to convert text to ASCII art")] + #[should_panic( + expected = "Failed to generate ASCII art: Failed to convert text to ASCII art" + )] fn test_macro_ascii_empty_input() { let _art = macro_ascii!(""); } #[test] - #[should_panic(expected = "Failed to generate ASCII art: Failed to convert text to ASCII art")] + #[should_panic( + expected = "Failed to generate ASCII art: Failed to convert text to ASCII art" + )] fn test_macro_ascii_invalid_input() { let _art = macro_ascii!("🦀"); } diff --git a/tests/macros/test_utility_macros.rs b/tests/macros/test_utility_macros.rs index 8faa0a5..67f9562 100644 --- a/tests/macros/test_utility_macros.rs +++ b/tests/macros/test_utility_macros.rs @@ -1,14 +1,17 @@ #[cfg(test)] mod tests { use libmake::macro_get_field; + use serde_json::from_reader; use std::env; - use std::path::Path; use std::fs::File; use std::io::Write; + use std::path::Path; use tempfile::tempdir; - use serde_json::from_reader; - fn read_file(file_path: &Path, f: F) -> Result> + fn read_file( + file_path: &Path, + f: F, + ) -> Result> where F: FnOnce(File) -> Result>, { @@ -33,10 +36,12 @@ mod tests { let mut file = File::create(&file_path).unwrap(); file.write_all(json_data.as_bytes()).unwrap(); - let result = get_field(Some(file_path.to_str().unwrap()), "name"); + let result = + get_field(Some(file_path.to_str().unwrap()), "name"); assert_eq!(result.unwrap(), "Alice"); - let result = get_field(Some(file_path.to_str().unwrap()), "age"); + let result = + get_field(Some(file_path.to_str().unwrap()), "age"); assert_eq!(result.unwrap(), "30"); } @@ -55,9 +60,13 @@ mod tests { let mut file = File::create(&file_path).unwrap(); file.write_all(json_data.as_bytes()).unwrap(); - let result = get_field(Some(file_path.to_str().unwrap()), "address"); + let result = + get_field(Some(file_path.to_str().unwrap()), "address"); assert!(result.is_err()); - assert_eq!(result.unwrap_err().to_string(), "Field 'address' not found"); + assert_eq!( + result.unwrap_err().to_string(), + "Field 'address' not found" + ); } #[test]