Skip to content

Commit 4c3ff9c

Browse files
committed
test(dist): add simple tests for PartialVersion
1 parent eee65db commit 4c3ff9c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/dist/mod.rs

+50
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,8 @@ fn date_from_manifest_date(date_str: &str) -> Option<NaiveDate> {
12051205

12061206
#[cfg(test)]
12071207
mod tests {
1208+
use proptest::prelude::*;
1209+
12081210
use super::*;
12091211

12101212
#[test]
@@ -1316,6 +1318,54 @@ mod tests {
13161318
}
13171319
}
13181320

1321+
#[test]
1322+
fn partial_version_from_str() -> Result<()> {
1323+
assert_eq!(
1324+
PartialVersion::from_str("0.12")?,
1325+
PartialVersion {
1326+
major: 0,
1327+
minor: Some(12),
1328+
patch: None,
1329+
pre: semver::Prerelease::EMPTY,
1330+
},
1331+
);
1332+
assert_eq!(
1333+
PartialVersion::from_str("1.23-beta")?,
1334+
PartialVersion {
1335+
major: 1,
1336+
minor: Some(23),
1337+
patch: None,
1338+
pre: semver::Prerelease::new("beta").unwrap(),
1339+
},
1340+
);
1341+
assert_eq!(
1342+
PartialVersion::from_str("1.23.0-beta.4")?,
1343+
PartialVersion {
1344+
major: 1,
1345+
minor: Some(23),
1346+
patch: Some(0),
1347+
pre: semver::Prerelease::new("beta.4").unwrap(),
1348+
},
1349+
);
1350+
1351+
assert!(PartialVersion::from_str("1.01").is_err()); // no leading zeros
1352+
assert!(PartialVersion::from_str("^1.23").is_err()); // no comparing operators
1353+
assert!(PartialVersion::from_str(">=1").is_err());
1354+
assert!(PartialVersion::from_str("*").is_err());
1355+
assert!(PartialVersion::from_str("stable").is_err());
1356+
1357+
Ok(())
1358+
}
1359+
1360+
proptest! {
1361+
#[test]
1362+
fn partial_version_from_str_to_str(
1363+
ver in r"[0-9]{1}(\.(0|[1-9][0-9]{0,2}))(\.(0|[1-9][0-9]{0,1}))?(-beta(\.(0|[1-9][1-9]{0,1}))?)?"
1364+
) {
1365+
prop_assert_eq!(PartialVersion::from_str(&ver).unwrap().to_string(), ver);
1366+
}
1367+
}
1368+
13191369
#[test]
13201370
fn compatible_host_triples() {
13211371
static CASES: &[(&str, &[&str], &[&str])] = &[

0 commit comments

Comments
 (0)