Skip to content

Commit c12f6ee

Browse files
KSXGitHubanonrig
authored andcommitted
test: divide 1 test into 2
1 parent b377d82 commit c12f6ee

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/lib.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,26 @@ mod test {
584584
}
585585

586586
#[test]
587-
fn should_parse_with_try_from() {
588-
let tests = [("http://example.com/", true), ("invalid url", false)];
589-
for (value, should_parse) in tests {
590-
let url = Url::parse("http://example.com/", None).unwrap();
591-
let parsed = Url::try_from(value);
592-
if should_parse {
593-
assert_eq!(parsed.is_ok(), should_parse);
594-
assert_eq!(url, parsed.unwrap());
595-
} else {
596-
assert!(parsed.is_err());
597-
}
598-
}
587+
fn try_from_ok() {
588+
let url = Url::try_from("http://example.com/foo/bar?k1=v1&k2=v2");
589+
dbg!(&url);
590+
let url = url.unwrap();
591+
assert_eq!(url.href(), "http://example.com/foo/bar?k1=v1&k2=v2");
592+
assert_eq!(
593+
url,
594+
Url::parse("http://example.com/foo/bar?k1=v1&k2=v2", None).unwrap(),
595+
);
599596
}
597+
598+
#[test]
599+
fn try_from_err() {
600+
let url = Url::try_from("this is not a url");
601+
dbg!(&url);
602+
let error = url.unwrap_err();
603+
assert_eq!(error.to_string(), r#"Invalid url: "this is not a url""#);
604+
assert!(matches!(error, Error::ParseUrl(_)));
605+
}
606+
600607
#[test]
601608
fn should_compare_urls() {
602609
let tests = [

0 commit comments

Comments
 (0)