-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for SyntaxViolation callback types
New test coverage: || src/parser.rs: 697/848 +1.7688679245283057%
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -784,6 +784,37 @@ 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:[email protected]", 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@:[email protected]", 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); | ||
|
||
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::*; | ||
|