Skip to content

Commit

Permalink
Relocate comparator parse testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 22, 2023
1 parent 2d34e8f commit 83abc7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 43 deletions.
42 changes: 0 additions & 42 deletions tests/test_identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,8 @@ fn test_eq() {
assert_ne!(build_metadata("1"), build_metadata("001"));
}

#[test]
fn test_comparator() {
let parsed = comparator("1.2.3-alpha");
assert_to_string(parsed, "^1.2.3-alpha");

let parsed = comparator("2.X");
assert_to_string(parsed, "2.*");

let parsed = comparator("2");
assert_to_string(parsed, "^2");

let parsed = comparator("2.x.x");
assert_to_string(parsed, "2.*");
}

#[test]
fn test_prerelease() {
let err = prerelease_err("1.b\0");
assert_to_string(err, "unexpected character in pre-release identifier");
}

#[test]
fn test_comparator_err() {
let err = comparator_err("1.2.3-01");
assert_to_string(err, "invalid leading zero in pre-release identifier");

let err = comparator_err("1.2.3+4.");
assert_to_string(err, "empty identifier segment in build metadata");

let err = comparator_err(">");
assert_to_string(
err,
"unexpected end of input while parsing major version number",
);

let err = comparator_err("1.");
assert_to_string(
err,
"unexpected end of input while parsing minor version number",
);

let err = comparator_err("1.*.");
assert_to_string(err, "unexpected character after wildcard in version req");

let err = comparator_err("1.2.3+4ÿ");
assert_to_string(err, "unexpected character 'ÿ' after build metadata");
}
41 changes: 40 additions & 1 deletion tests/test_version_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ pub fn test_pre() {
}

#[test]
pub fn test_parse_errors() {
pub fn test_parse() {
let err = req_err("\0");
assert_to_string(
err,
Expand Down Expand Up @@ -370,6 +370,45 @@ pub fn test_parse_errors() {
);
}

#[test]
fn test_comparator_parse() {
let parsed = comparator("1.2.3-alpha");
assert_to_string(parsed, "^1.2.3-alpha");

let parsed = comparator("2.X");
assert_to_string(parsed, "2.*");

let parsed = comparator("2");
assert_to_string(parsed, "^2");

let parsed = comparator("2.x.x");
assert_to_string(parsed, "2.*");

let err = comparator_err("1.2.3-01");
assert_to_string(err, "invalid leading zero in pre-release identifier");

let err = comparator_err("1.2.3+4.");
assert_to_string(err, "empty identifier segment in build metadata");

let err = comparator_err(">");
assert_to_string(
err,
"unexpected end of input while parsing major version number",
);

let err = comparator_err("1.");
assert_to_string(
err,
"unexpected end of input while parsing minor version number",
);

let err = comparator_err("1.*.");
assert_to_string(err, "unexpected character after wildcard in version req");

let err = comparator_err("1.2.3+4ÿ");
assert_to_string(err, "unexpected character 'ÿ' after build metadata");
}

#[test]
fn test_cargo3202() {
let ref r = req("0.*.*");
Expand Down

0 comments on commit 83abc7f

Please sign in to comment.