From 825592175a98701f23834177284e716925bd06c0 Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Fri, 5 Jan 2024 19:13:08 -0500 Subject: [PATCH] Add tests for SemVer parsing --- src/semver.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/semver.rs b/src/semver.rs index c39809f..9c30acb 100644 --- a/src/semver.rs +++ b/src/semver.rs @@ -85,3 +85,34 @@ impl PartialOrd for SemVer { Some(self.cmp(other)) } } + +#[cfg(test)] +mod tests { + use std::num::NonZeroU16; + + use super::*; + + #[test] + fn from_str() { + let mut s: SemVer = "1.2.3".parse().unwrap(); + assert_eq!( + s, + SemVer { + major: 1, + minor: 2, + patch: 3, + pre: PreRelease::None, + } + ); + s = "0.3.0_alpha4".parse().unwrap(); + assert_eq!( + s, + SemVer { + major: 0, + minor: 3, + patch: 0, + pre: PreRelease::Alpha(Some(NonZeroU16::new(4).unwrap())), + } + ) + } +}