-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(libmake): ✅ add new tests for
log_macros.rs
- Loading branch information
1 parent
ffe82fd
commit f3592c5
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use libmake::macro_log_info; | ||
|
||
struct DateTime { | ||
iso_8601: String, | ||
} | ||
|
||
impl DateTime { | ||
fn new() -> Self { | ||
DateTime { | ||
iso_8601: "2024-05-15T12:34:56Z".to_string(), | ||
} | ||
} | ||
} | ||
|
||
struct Random; | ||
|
||
impl Random { | ||
fn default() -> Self { | ||
Random | ||
} | ||
|
||
fn rand(&mut self) -> u64 { | ||
42 // Mock random number generator returns a fixed value | ||
} | ||
} | ||
|
||
struct Log { | ||
session_id: String, | ||
iso_8601: String, | ||
level: String, | ||
component: String, | ||
description: String, | ||
format: String, | ||
} | ||
|
||
impl Log { | ||
fn new( | ||
session_id: &str, | ||
iso_8601: &str, | ||
level: &str, | ||
component: &str, | ||
description: &str, | ||
format: &str, | ||
) -> Self { | ||
Log { | ||
session_id: session_id.to_string(), | ||
iso_8601: iso_8601.to_string(), | ||
level: level.to_string(), | ||
component: component.to_string(), | ||
description: description.to_string(), | ||
format: format.to_string(), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_macro_log_info() { | ||
let log = macro_log_info!( | ||
"INFO", | ||
"TestComponent", | ||
"This is a test log", | ||
"TestFormat" | ||
); | ||
|
||
assert_eq!(log.session_id, "42"); | ||
assert_eq!(log.iso_8601, "2024-05-15T12:34:56Z"); | ||
assert_eq!(log.level, "INFO"); | ||
assert_eq!(log.component, "TestComponent"); | ||
assert_eq!(log.description, "This is a test log"); | ||
assert_eq!(log.format, "TestFormat"); | ||
} | ||
} |