Skip to content

Commit 45f2f9f

Browse files
chancedanonrig
authored andcommitted
adds test for TryFrom`
1 parent f67bdcc commit 45f2f9f

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,20 @@ mod test {
576576
assert_eq!(url.to_string(), expected);
577577
}
578578
}
579-
579+
#[test]
580+
fn should_parse_with_try_from() {
581+
let tests = [("http://example.com/", true), ("invalid url", false)];
582+
for (value, should_parse) in tests {
583+
let url = Url::parse("http://example.com/", None).unwrap();
584+
let parsed = Url::try_from(value);
585+
if should_parse {
586+
assert_eq!(parsed.is_ok(), should_parse);
587+
assert_eq!(url, parsed.unwrap());
588+
} else {
589+
assert!(parsed.is_err());
590+
}
591+
}
592+
}
580593
#[test]
581594
fn should_compare_urls() {
582595
let tests = [

0 commit comments

Comments
 (0)