From 6a5a935ccdd3b4af19e4dd5054f692c24fb94602 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 18 Dec 2023 12:45:07 +0100 Subject: [PATCH] Update tests and documentation for crate version features --- tox/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tox/src/lib.rs b/tox/src/lib.rs index c508111e..c1469443 100644 --- a/tox/src/lib.rs +++ b/tox/src/lib.rs @@ -5,15 +5,19 @@ pub use tox_crypto as crypto; pub use tox_encryptsave as encryptsave; pub use tox_packet as packet; +/// The tox crate version string in the form "major.minor.patch" (e.g. "1.2.3") pub fn crate_version() -> String { env!("CARGO_PKG_VERSION").to_string() } +/// The tox crate major version represented as unsigned integer pub fn crate_version_major() -> u32 { env!("CARGO_PKG_VERSION_MAJOR").parse().expect("Invalid major version") } +/// The tox crate minor version represented as unsigned integer pub fn crate_version_minor() -> u32 { env!("CARGO_PKG_VERSION_MINOR").parse().expect("Invalid minor version") } +/// The tox crate patch version represented as unsigned integer pub fn crate_version_patch() -> u32 { env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") } @@ -27,16 +31,19 @@ mod tests { #[test] fn crate_version_major() { - crate::crate_version_major(); + let v = crate::crate_version_major(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap()); } #[test] fn crate_version_minor() { - crate::crate_version_minor(); + let v = crate::crate_version_minor(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap()); } #[test] fn crate_version_patch() { - crate::crate_version_patch(); + let v = crate::crate_version_patch(); + assert_eq!(v, env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap()); } }