Skip to content

Commit

Permalink
test(libmake): ✅ add new tests and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed May 15, 2024
1 parent a926ce1 commit 6463816
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 26 additions & 0 deletions tests/generators/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 6 additions & 2 deletions tests/macros/test_ascii_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!("🦀");
}
Expand Down
23 changes: 16 additions & 7 deletions tests/macros/test_utility_macros.rs
Original file line number Diff line number Diff line change
@@ -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<F, R>(file_path: &Path, f: F) -> Result<R, Box<dyn std::error::Error>>
fn read_file<F, R>(
file_path: &Path,
f: F,
) -> Result<R, Box<dyn std::error::Error>>
where
F: FnOnce(File) -> Result<R, Box<dyn std::error::Error>>,
{
Expand All @@ -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");
}

Expand All @@ -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]
Expand Down

0 comments on commit 6463816

Please sign in to comment.