From b21fbf09f12db5002a00bc065df62eaa700d665f Mon Sep 17 00:00:00 2001 From: Will Kennedy Date: Wed, 14 Aug 2024 23:39:46 -0400 Subject: [PATCH] Add tests for ExpectationError messages This commit introduces unit tests for the `ExpectationError` enum to ensure that error messages are formatted correctly. Additionally, it updates the package versions in `Cargo.toml` for both `borsh-serde-adapter` and `borsh-schema-writer`. --- borsh-schema-writer/Cargo.toml | 2 +- borsh-serde-adapter/Cargo.toml | 2 +- borsh-serde-adapter/src/errors.rs | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/borsh-schema-writer/Cargo.toml b/borsh-schema-writer/Cargo.toml index 1d85d32..290b596 100644 --- a/borsh-schema-writer/Cargo.toml +++ b/borsh-schema-writer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "borsh-schema-writer" -version = "1.0.1" +version = "1.0.2" edition = "2021" authors = ["Will Kennedy"] description = "Write a BorshSchemaContainer to a binary file" diff --git a/borsh-serde-adapter/Cargo.toml b/borsh-serde-adapter/Cargo.toml index 5d4ed6d..7b63845 100644 --- a/borsh-serde-adapter/Cargo.toml +++ b/borsh-serde-adapter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "borsh-serde-adapter" -version = "1.0.2" +version = "1.0.3" edition = "2021" authors = ["Will Kennedy"] description = "Adapter to go from borsh to serde and vice versa" diff --git a/borsh-serde-adapter/src/errors.rs b/borsh-serde-adapter/src/errors.rs index bd083b8..98598b5 100644 --- a/borsh-serde-adapter/src/errors.rs +++ b/borsh-serde-adapter/src/errors.rs @@ -22,4 +22,20 @@ pub enum ExpectationError { #[error("Expected object")] Object +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_error_messages() { + assert_eq!(format!("{}", ExpectationError::Null), "Expected null"); + assert_eq!(format!("{}", ExpectationError::Array), "Expected array"); + assert_eq!(format!("{}", ExpectationError::ArrayOfLength(5)), "Expected array of length 5"); + assert_eq!(format!("{}", ExpectationError::Number), "Expected number"); + assert_eq!(format!("{}", ExpectationError::String), "Expected string"); + assert_eq!(format!("{}", ExpectationError::Boolean), "Expected boolean"); + assert_eq!(format!("{}", ExpectationError::Object), "Expected object"); + } } \ No newline at end of file