Skip to content
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

Add tests for SyntaxViolation callback types #708

Merged
merged 3 commits into from
May 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions url/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,38 @@ fn test_syntax_violation_callback_lifetimes() {
assert_eq!(violation.take(), Some(Backslash));
}

#[test]
fn test_syntax_violation_callback_types() {
use url::SyntaxViolation::*;

let data = [
("http://mozilla.org/\\foo", Backslash, "backslash"),
(" http://mozilla.org", C0SpaceIgnored, "leading or trailing control or space character are ignored in URLs"),
("http://user:pass@mozilla.org", EmbeddedCredentials, "embedding authentication information (username or password) in an URL is not recommended"),
("http:///mozilla.org", ExpectedDoubleSlash, "expected //"),
("file:/foo.txt", ExpectedFileDoubleSlash, "expected // after file:"),
("file://mozilla.org/c:/file.txt", FileWithHostAndWindowsDrive, "file: with host and Windows drive letter"),
("http://mozilla.org/^", NonUrlCodePoint, "non-URL code point"),
("http://mozilla.org/#\00", NullInFragment, "NULL characters are ignored in URL fragment identifiers"),
("http://mozilla.org/%1", PercentDecode, "expected 2 hex digits after %"),
("http://mozilla.org\t/foo", TabOrNewlineIgnored, "tabs or newlines are ignored in URLs"),
("http://user@:pass@mozilla.org", UnencodedAtSign, "unencoded @ sign in username or password")
];

for test_case in &data {
let violation = Cell::new(None);
Url::options()
.syntax_violation_callback(Some(&|v| violation.set(Some(v))))
.parse(test_case.0)
.unwrap();

let v = violation.take();
assert_eq!(v, Some(test_case.1));
assert_eq!(v.unwrap().description(), test_case.2);
assert_eq!(v.unwrap().to_string(), test_case.2);
}
}

#[test]
fn test_options_reuse() {
use url::SyntaxViolation::*;
Expand Down