Skip to content

Commit

Permalink
fix(cmn): unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed May 13, 2023
1 parent c97b11e commit 629a262
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
/// that are used to serialize and deserialize the data.
extern crate serde;
use serde::{Deserialize, Serialize};
use serde_json;

/// The `macros` module contains functions for generating macros.
pub mod macros;
Expand All @@ -144,12 +145,17 @@ pub use words::Words;
/// * `constants`: A reference to the `Constants` structure.
/// * `words`: A reference to the `Words` structure.
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Common;
pub struct Common {
#[serde(flatten)]
fields: serde_json::Value,
}

impl Common {
/// Creates a new instance of the `Common` structure.
pub fn new() -> Self {
Self
Self {
fields: serde_json::Value::Null,
}
}
/// Returns the `Constants` instance.
pub fn constants(&self) -> Constants {
Expand Down
23 changes: 22 additions & 1 deletion tests/test_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ mod tests {
let constants = common.constants();

assert_eq!(constants.constants().len(), 16);
assert_eq!(constants.constants(), Constants::default().constants());
assert_eq!(
constants.constants(),
Constants::default().constants()
);
}

#[test]
Expand Down Expand Up @@ -83,4 +86,22 @@ mod tests {
assert_eq!(default_constants.len(), 16);
assert_eq!(default_constants, constants.constants());
}

#[test]
fn test_parse_valid_input() {
let input = r#"{"field1": "value1", "field2": "value2"}"#;
let result = Common::parse(input);
assert!(
result.is_ok(),
"Parsing should succeed: {:?}",
result.unwrap_err()
);
}

#[test]
fn test_parse_invalid_input() {
let input = "invalid input";
let result = Common::parse(input);
assert!(result.is_err(), "Parsing should fail");
}
}

0 comments on commit 629a262

Please sign in to comment.