Skip to content

Commit 25c5674

Browse files
sbosnickseanmonstar
authored andcommitted
Add tests for directly parsing a Scheme
The tests include an [u8] that is invalid UTF-8.
1 parent dc865ff commit 25c5674

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/uri/scheme.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,28 @@ impl From<Scheme2> for Scheme {
324324
Scheme { inner: src }
325325
}
326326
}
327+
328+
#[cfg(test)]
329+
mod test {
330+
use super::*;
331+
332+
#[test]
333+
fn scheme_eq_to_str() {
334+
assert_eq!(&scheme("http"), "http");
335+
assert_eq!(&scheme("https"), "https");
336+
assert_eq!(&scheme("ftp"), "ftp");
337+
assert_eq!(&scheme("my+funky+scheme"), "my+funky+scheme");
338+
}
339+
340+
#[test]
341+
fn invalid_scheme_is_error() {
342+
Scheme::try_from("my_funky_scheme").expect_err("Unexpectly valid Scheme");
343+
344+
// Invalid UTF-8
345+
Scheme::try_from([0xC0].as_ref()).expect_err("Unexpectly valid Scheme");
346+
}
347+
348+
fn scheme(s: &str) -> Scheme {
349+
s.parse().expect(&format!("Invalid scheme: {}", s))
350+
}
351+
}

0 commit comments

Comments
 (0)