Add tests for SemVer parsing

This commit is contained in:
Nathan Fisher 2024-01-05 19:13:08 -05:00
parent 8009575765
commit 825592175a

View File

@ -85,3 +85,34 @@ impl PartialOrd for SemVer {
Some(self.cmp(other)) 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())),
}
)
}
}