-
Notifications
You must be signed in to change notification settings - Fork 15
Improvement suggestions #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cbc73ac
style: suppress a warning
KSXGitHub 5ef2d29
test: divide 1 test into 2
KSXGitHub 7e6f7cd
test: remove unnecessary assertion
KSXGitHub 7364d67
test: log
KSXGitHub 468a77c
test: add a case
KSXGitHub 7f72de6
test: add a case
KSXGitHub 30f1112
test: add a case
KSXGitHub ac3d664
test: add a case
KSXGitHub 6d4cdcc
docs: change comment wording
KSXGitHub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#![allow(non_camel_case_types)] | ||
use std::ffi::c_char; | ||
|
||
#[repr(C)] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,28 +575,51 @@ mod test { | |
("http://example.com/", "http://example.com/"), | ||
("HTTP://EXAMPLE.COM", "http://example.com/"), | ||
("http://user:[email protected]", "http://user:[email protected]/"), | ||
( | ||
"HTTP://EXAMPLE.COM/FOO/BAR?K1=V1&K2=V2", | ||
"http://example.com/FOO/BAR?K1=V1&K2=V2", | ||
), | ||
( | ||
"http://example.com/🦀/❤️/", | ||
"http://example.com/%F0%9F%A6%80/%E2%9D%A4%EF%B8%8F/", | ||
), | ||
( | ||
"https://example.org/hello world.html", | ||
"https://example.org/hello%20world.html", | ||
), | ||
( | ||
"https://三十六計.org/走為上策/", | ||
"https://xn--ehq95fdxbx86i.org/%E8%B5%B0%E7%82%BA%E4%B8%8A%E7%AD%96/", // weird, but this binding lib cannot change the implementation | ||
), | ||
]; | ||
for (value, expected) in tests { | ||
eprintln!("{value} -> {expected}"); | ||
let url = Url::parse(value, None).expect("Should have parsed url"); | ||
assert_eq!(format!("{}", url), expected); | ||
assert_eq!(url.to_string(), expected); | ||
} | ||
} | ||
|
||
#[test] | ||
fn should_parse_with_try_from() { | ||
let tests = [("http://example.com/", true), ("invalid url", false)]; | ||
for (value, should_parse) in tests { | ||
let url = Url::parse("http://example.com/", None).unwrap(); | ||
let parsed = Url::try_from(value); | ||
if should_parse { | ||
assert_eq!(parsed.is_ok(), should_parse); | ||
assert_eq!(url, parsed.unwrap()); | ||
} else { | ||
assert!(parsed.is_err()); | ||
} | ||
} | ||
fn try_from_ok() { | ||
let url = Url::try_from("http://example.com/foo/bar?k1=v1&k2=v2"); | ||
dbg!(&url); | ||
let url = url.unwrap(); | ||
assert_eq!(url.href(), "http://example.com/foo/bar?k1=v1&k2=v2"); | ||
assert_eq!( | ||
url, | ||
Url::parse("http://example.com/foo/bar?k1=v1&k2=v2", None).unwrap(), | ||
); | ||
} | ||
|
||
#[test] | ||
fn try_from_err() { | ||
let url = Url::try_from("this is not a url"); | ||
dbg!(&url); | ||
let error = url.unwrap_err(); | ||
assert_eq!(error.to_string(), r#"Invalid url: "this is not a url""#); | ||
assert!(matches!(error, Error::ParseUrl(_))); | ||
} | ||
|
||
#[test] | ||
fn should_compare_urls() { | ||
let tests = [ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.