Skip to content

Commit 3118b46

Browse files
committed
fix testdata runner
1 parent fc76310 commit 3118b46

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

url/tests/data.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn urltestdata() {
3030
"http://GOO\u{200b}\u{2060}\u{feff}goo.com",
3131
];
3232

33-
// Copied form https://github.com/w3c/web-platform-tests/blob/master/url/
33+
// Copied from https://github.com/web-platform-tests/wpt/blob/master/url/
3434
let mut json = Value::from_str(include_str!("urltestdata.json"))
3535
.expect("JSON parse error in urltestdata.json");
3636

@@ -40,7 +40,10 @@ fn urltestdata() {
4040
continue; // ignore comments
4141
}
4242

43-
let base = entry.take_string("base");
43+
let maybe_base = entry
44+
.take_key("base")
45+
.expect("missing base key")
46+
.maybe_string();
4447
let input = entry.take_string("input");
4548
let failure = entry.take_key("failure").is_some();
4649

@@ -51,21 +54,26 @@ fn urltestdata() {
5154
}
5255
}
5356

54-
let base = match Url::parse(&base) {
55-
Ok(base) => base,
56-
Err(_) if failure => continue,
57-
Err(message) => {
58-
eprint_failure(
59-
format!(" failed: error parsing base {:?}: {}", base, message),
60-
&format!("parse base for {:?}", input),
61-
None,
62-
);
63-
passed = false;
64-
continue;
65-
}
57+
let res = if let Some(base) = maybe_base {
58+
let base = match Url::parse(&base) {
59+
Ok(base) => base,
60+
Err(_) if failure => continue,
61+
Err(message) => {
62+
eprint_failure(
63+
format!(" failed: error parsing base {:?}: {}", base, message),
64+
&format!("parse base for {:?}", input),
65+
None,
66+
);
67+
passed = false;
68+
continue;
69+
}
70+
};
71+
base.join(&input)
72+
} else {
73+
Url::parse(&input)
6674
};
6775

68-
let url = match (base.join(&input), failure) {
76+
let url = match (res, failure) {
6977
(Ok(url), false) => url,
7078
(Err(_), true) => continue,
7179
(Err(message), false) => {
@@ -182,6 +190,7 @@ fn check_invariants(url: &Url, name: &str, comment: Option<&str>) -> bool {
182190
trait JsonExt {
183191
fn take_key(&mut self, key: &str) -> Option<Value>;
184192
fn string(self) -> String;
193+
fn maybe_string(self) -> Option<String>;
185194
fn take_string(&mut self, key: &str) -> String;
186195
}
187196

@@ -191,10 +200,14 @@ impl JsonExt for Value {
191200
}
192201

193202
fn string(self) -> String {
194-
if let Value::String(s) = self {
195-
s
196-
} else {
197-
panic!("Not a Value::String")
203+
self.maybe_string().expect("")
204+
}
205+
206+
fn maybe_string(self) -> Option<String> {
207+
match self {
208+
Value::String(s) => Some(s),
209+
Value::Null => None,
210+
_ => panic!("Not a Value::String or Value::Null"),
198211
}
199212
}
200213

url/tests/urltestdata.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7688,5 +7688,16 @@
76887688
"protocol": "abc:",
76897689
"search": "",
76907690
"username": ""
7691+
},
7692+
"Empty query and fragment with blank should throw an error",
7693+
{
7694+
"input": "#",
7695+
"base": null,
7696+
"failure": true
7697+
},
7698+
{
7699+
"input": "?",
7700+
"base": null,
7701+
"failure": true
76917702
}
76927703
]

0 commit comments

Comments
 (0)