Skip to content

Commit 473209f

Browse files
authored
Merge pull request #299 from CXWorks/master
Adding missed unit test cases
2 parents cb07901 + 2d50313 commit 473209f

File tree

4 files changed

+79
-1
lines changed

4 files changed

+79
-1
lines changed

tests/test_identifier.rs

+48
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,51 @@ fn test_eq() {
4343
assert_ne!(prerelease("aaaaaaaaa"), prerelease("bbbbbbbbb"));
4444
assert_ne!(build_metadata("1"), build_metadata("001"));
4545
}
46+
47+
#[test]
48+
fn test_comparator() {
49+
let compatator = comparator("4.4.5-44");
50+
assert_to_string(compatator, "^4.4.5-44");
51+
52+
let compatator = comparator("2.X");
53+
assert_to_string(compatator, "2.*");
54+
55+
let compatator = comparator("2");
56+
assert_to_string(compatator, "^2");
57+
58+
let compatator = comparator("5.x.x");
59+
assert_to_string(compatator, "5.*");
60+
}
61+
62+
#[test]
63+
fn test_prerelease() {
64+
let err = prerelease_err("88.6688.b.rrrrrrr8.b.6bbbbbbb66.66\0");
65+
assert_to_string(err, "unexpected character in pre-release identifier");
66+
}
67+
68+
#[test]
69+
fn test_comparator_err() {
70+
let err = comparator_err("4.4.4-012");
71+
assert_to_string(err, "invalid leading zero in pre-release identifier");
72+
73+
let err = comparator_err("5.4.4+4.");
74+
assert_to_string(err, "empty identifier segment in build metadata");
75+
76+
let err = comparator_err(">");
77+
assert_to_string(
78+
err,
79+
"unexpected end of input while parsing major version number",
80+
);
81+
82+
let err = comparator_err("4.");
83+
assert_to_string(
84+
err,
85+
"unexpected end of input while parsing minor version number",
86+
);
87+
88+
let err = comparator_err("4.*.");
89+
assert_to_string(err, "unexpected character after wildcard in version req");
90+
91+
let err = comparator_err("55444.4.45-6+6.4.5.45-5644ÿ");
92+
assert_to_string(err, "unexpected character 'ÿ' after build metadata");
93+
}

tests/test_version.rs

+12
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ fn test_parse() {
4747
let err = version_err("1.2.3-01");
4848
assert_to_string(err, "invalid leading zero in pre-release identifier");
4949

50+
let err = version_err("5.1.5++");
51+
assert_to_string(err, "empty identifier segment in build metadata");
52+
53+
let err = version_err("07");
54+
assert_to_string(err, "invalid leading zero in major version number");
55+
56+
let err = version_err("75774777777757777757");
57+
assert_to_string(err, "value of major version number exceeds u64::MAX");
58+
59+
let err = version_err("8\0");
60+
assert_to_string(err, "unexpected character '\\0' after major version number");
61+
5062
let parsed = version("1.2.3");
5163
let expected = Version::new(1, 2, 3);
5264
assert_eq!(parsed, expected);

tests/test_version_req.rs

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ pub fn test_multiple() {
168168
// https://github.com/steveklabnik/semver/issues/56
169169
let err = req_err("1.2.3 - 2.3.4");
170170
assert_to_string(err, "expected comma after patch version number, found '-'");
171+
172+
let err = req_err(">=2,22002222022222222,2,21,222,2,2,2,222,2,221,222,2,2,2,21,222,2,2,2,2,2,222,2222,2,2,2,222,2,222,2,222,'6");
173+
assert_to_string(err, "excessive number of version comparators");
171174
}
172175

173176
#[test]

tests/util/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code)]
22

3-
use semver::{BuildMetadata, Error, Prerelease, Version, VersionReq};
3+
use semver::{BuildMetadata, Comparator, Error, Prerelease, Version, VersionReq};
44
use std::fmt::Display;
55

66
#[cfg_attr(not(no_track_caller), track_caller)]
@@ -28,6 +28,11 @@ pub(super) fn prerelease(text: &str) -> Prerelease {
2828
Prerelease::new(text).unwrap()
2929
}
3030

31+
#[cfg_attr(not(no_track_caller), track_caller)]
32+
pub(super) fn prerelease_err(text: &str) -> Error {
33+
Prerelease::new(text).unwrap_err()
34+
}
35+
3136
#[cfg_attr(not(no_track_caller), track_caller)]
3237
pub(super) fn build_metadata(text: &str) -> BuildMetadata {
3338
BuildMetadata::new(text).unwrap()
@@ -37,3 +42,13 @@ pub(super) fn build_metadata(text: &str) -> BuildMetadata {
3742
pub(super) fn assert_to_string(value: impl Display, expected: &str) {
3843
assert_eq!(value.to_string(), expected);
3944
}
45+
46+
#[cfg_attr(not(no_track_caller), track_caller)]
47+
pub(super) fn comparator(text: &str) -> Comparator {
48+
Comparator::parse(text).unwrap()
49+
}
50+
51+
#[cfg_attr(not(no_track_caller), track_caller)]
52+
pub(super) fn comparator_err(text: &str) -> Error {
53+
Comparator::parse(text).unwrap_err()
54+
}

0 commit comments

Comments
 (0)