Skip to content

Commit

Permalink
Update tests and documentation for crate version features
Browse files Browse the repository at this point in the history
  • Loading branch information
antis81 committed Dec 18, 2023
1 parent 4d4ecdd commit 6a5a935
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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::<u32>().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::<u32>().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::<u32>().unwrap());
}
}

0 comments on commit 6a5a935

Please sign in to comment.