Skip to content

Commit

Permalink
test: add test for accepting serialize as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Oct 12, 2023
1 parent 8040db8 commit 02e56d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ is-terminal = "0.4.4"
serde = "1"
serde_json = "1"
yansi = "0.5"

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
24 changes: 24 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,27 @@ fn test_styler_compact() -> Result<(), Box<dyn Error>> {

return Ok(());
}

#[test]
fn test_serializes() -> Result<(), Box<dyn Error>> {
#[cfg(windows)]
let _res = enable_ansi_support();

#[derive(serde::Serialize)]
struct Data<'a> {
name: &'a str,
age: usize,
phones: &'a [&'a str],
}

let data = Data {
name: "John Doe",
age: 43,
phones: &["+44 1234567", "+44 2345678"],
};

let s = to_colored_json_auto(&data)?;
println!("\n{}", s);

return Ok(());
}

0 comments on commit 02e56d3

Please sign in to comment.