Skip to content

Commit 991e438

Browse files
authored
Merge pull request #708 from BramBonne/test-syntax-violations
Add tests for SyntaxViolation callback types
2 parents c6f60fe + 744b763 commit 991e438

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

url/tests/unit.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,38 @@ fn test_syntax_violation_callback_lifetimes() {
784784
assert_eq!(violation.take(), Some(Backslash));
785785
}
786786

787+
#[test]
788+
fn test_syntax_violation_callback_types() {
789+
use url::SyntaxViolation::*;
790+
791+
let data = [
792+
("http://mozilla.org/\\foo", Backslash, "backslash"),
793+
(" http://mozilla.org", C0SpaceIgnored, "leading or trailing control or space character are ignored in URLs"),
794+
("http://user:[email protected]", EmbeddedCredentials, "embedding authentication information (username or password) in an URL is not recommended"),
795+
("http:///mozilla.org", ExpectedDoubleSlash, "expected //"),
796+
("file:/foo.txt", ExpectedFileDoubleSlash, "expected // after file:"),
797+
("file://mozilla.org/c:/file.txt", FileWithHostAndWindowsDrive, "file: with host and Windows drive letter"),
798+
("http://mozilla.org/^", NonUrlCodePoint, "non-URL code point"),
799+
("http://mozilla.org/#\00", NullInFragment, "NULL characters are ignored in URL fragment identifiers"),
800+
("http://mozilla.org/%1", PercentDecode, "expected 2 hex digits after %"),
801+
("http://mozilla.org\t/foo", TabOrNewlineIgnored, "tabs or newlines are ignored in URLs"),
802+
("http://user@:[email protected]", UnencodedAtSign, "unencoded @ sign in username or password")
803+
];
804+
805+
for test_case in &data {
806+
let violation = Cell::new(None);
807+
Url::options()
808+
.syntax_violation_callback(Some(&|v| violation.set(Some(v))))
809+
.parse(test_case.0)
810+
.unwrap();
811+
812+
let v = violation.take();
813+
assert_eq!(v, Some(test_case.1));
814+
assert_eq!(v.unwrap().description(), test_case.2);
815+
assert_eq!(v.unwrap().to_string(), test_case.2);
816+
}
817+
}
818+
787819
#[test]
788820
fn test_options_reuse() {
789821
use url::SyntaxViolation::*;

0 commit comments

Comments
 (0)