unit.rs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. // Copyright 2013-2014 The rust-url developers.
  2. //
  3. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  4. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  5. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  6. // option. This file may not be copied, modified, or distributed
  7. // except according to those terms.
  8. //! Unit tests
  9. #[macro_use]
  10. extern crate url;
  11. use std::borrow::Cow;
  12. use std::cell::{Cell, RefCell};
  13. use std::net::{Ipv4Addr, Ipv6Addr};
  14. use std::path::{Path, PathBuf};
  15. use url::{Host, HostAndPort, Url, form_urlencoded};
  16. #[test]
  17. fn size() {
  18. use std::mem::size_of;
  19. assert_eq!(size_of::<Url>(), size_of::<Option<Url>>());
  20. }
  21. macro_rules! assert_from_file_path {
  22. ($path: expr) => { assert_from_file_path!($path, $path) };
  23. ($path: expr, $url_path: expr) => {{
  24. let url = Url::from_file_path(Path::new($path)).unwrap();
  25. assert_eq!(url.host(), None);
  26. assert_eq!(url.path(), $url_path);
  27. assert_eq!(url.to_file_path(), Ok(PathBuf::from($path)));
  28. }};
  29. }
  30. #[test]
  31. fn new_file_paths() {
  32. if cfg!(unix) {
  33. assert_eq!(Url::from_file_path(Path::new("relative")), Err(()));
  34. assert_eq!(Url::from_file_path(Path::new("../relative")), Err(()));
  35. }
  36. if cfg!(windows) {
  37. assert_eq!(Url::from_file_path(Path::new("relative")), Err(()));
  38. assert_eq!(Url::from_file_path(Path::new(r"..\relative")), Err(()));
  39. assert_eq!(Url::from_file_path(Path::new(r"\drive-relative")), Err(()));
  40. assert_eq!(Url::from_file_path(Path::new(r"\\ucn\")), Err(()));
  41. }
  42. if cfg!(unix) {
  43. assert_from_file_path!("/foo/bar");
  44. assert_from_file_path!("/foo/ba\0r", "/foo/ba%00r");
  45. assert_from_file_path!("/foo/ba%00r", "/foo/ba%2500r");
  46. }
  47. }
  48. #[test]
  49. #[cfg(unix)]
  50. fn new_path_bad_utf8() {
  51. use std::ffi::OsStr;
  52. use std::os::unix::prelude::*;
  53. let url = Url::from_file_path(Path::new(OsStr::from_bytes(b"/foo/ba\x80r"))).unwrap();
  54. let os_str = OsStr::from_bytes(b"/foo/ba\x80r");
  55. assert_eq!(url.to_file_path(), Ok(PathBuf::from(os_str)));
  56. }
  57. #[test]
  58. fn new_path_windows_fun() {
  59. if cfg!(windows) {
  60. assert_from_file_path!(r"C:\foo\bar", "/C:/foo/bar");
  61. assert_from_file_path!("C:\\foo\\ba\0r", "/C:/foo/ba%00r");
  62. // Invalid UTF-8
  63. assert!(Url::parse("file:///C:/foo/ba%80r").unwrap().to_file_path().is_err());
  64. // test windows canonicalized path
  65. let path = PathBuf::from(r"\\?\C:\foo\bar");
  66. assert!(Url::from_file_path(path).is_ok());
  67. // Percent-encoded drive letter
  68. let url = Url::parse("file:///C%3A/foo/bar").unwrap();
  69. assert_eq!(url.to_file_path(), Ok(PathBuf::from(r"C:\foo\bar")));
  70. }
  71. }
  72. #[test]
  73. fn new_directory_paths() {
  74. if cfg!(unix) {
  75. assert_eq!(Url::from_directory_path(Path::new("relative")), Err(()));
  76. assert_eq!(Url::from_directory_path(Path::new("../relative")), Err(()));
  77. let url = Url::from_directory_path(Path::new("/foo/bar")).unwrap();
  78. assert_eq!(url.host(), None);
  79. assert_eq!(url.path(), "/foo/bar/");
  80. }
  81. if cfg!(windows) {
  82. assert_eq!(Url::from_directory_path(Path::new("relative")), Err(()));
  83. assert_eq!(Url::from_directory_path(Path::new(r"..\relative")), Err(()));
  84. assert_eq!(Url::from_directory_path(Path::new(r"\drive-relative")), Err(()));
  85. assert_eq!(Url::from_directory_path(Path::new(r"\\ucn\")), Err(()));
  86. let url = Url::from_directory_path(Path::new(r"C:\foo\bar")).unwrap();
  87. assert_eq!(url.host(), None);
  88. assert_eq!(url.path(), "/C:/foo/bar/");
  89. }
  90. }
  91. #[test]
  92. fn path_backslash_fun() {
  93. let mut special_url = "http://foobar.com".parse::<Url>().unwrap();
  94. special_url.path_segments_mut().unwrap().push("foo\\bar");
  95. assert_eq!(special_url.as_str(), "http://foobar.com/foo%5Cbar");
  96. let mut nonspecial_url = "thing://foobar.com".parse::<Url>().unwrap();
  97. nonspecial_url.path_segments_mut().unwrap().push("foo\\bar");
  98. assert_eq!(nonspecial_url.as_str(), "thing://foobar.com/foo\\bar");
  99. }
  100. #[test]
  101. fn from_str() {
  102. assert!("http://testing.com/this".parse::<Url>().is_ok());
  103. }
  104. #[test]
  105. fn parse_with_params() {
  106. let url = Url::parse_with_params("http://testing.com/this?dont=clobberme",
  107. &[("lang", "rust")]).unwrap();
  108. assert_eq!(url.as_str(), "http://testing.com/this?dont=clobberme&lang=rust");
  109. }
  110. #[test]
  111. fn issue_124() {
  112. let url: Url = "file:a".parse().unwrap();
  113. assert_eq!(url.path(), "/a");
  114. let url: Url = "file:...".parse().unwrap();
  115. assert_eq!(url.path(), "/...");
  116. let url: Url = "file:..".parse().unwrap();
  117. assert_eq!(url.path(), "/");
  118. }
  119. #[test]
  120. fn test_equality() {
  121. use std::hash::{Hash, Hasher};
  122. use std::collections::hash_map::DefaultHasher;
  123. fn check_eq(a: &Url, b: &Url) {
  124. assert_eq!(a, b);
  125. let mut h1 = DefaultHasher::new();
  126. a.hash(&mut h1);
  127. let mut h2 = DefaultHasher::new();
  128. b.hash(&mut h2);
  129. assert_eq!(h1.finish(), h2.finish());
  130. }
  131. fn url(s: &str) -> Url {
  132. let rv = s.parse().unwrap();
  133. check_eq(&rv, &rv);
  134. rv
  135. }
  136. // Doesn't care if default port is given.
  137. let a: Url = url("https://example.com/");
  138. let b: Url = url("https://example.com:443/");
  139. check_eq(&a, &b);
  140. // Different ports
  141. let a: Url = url("http://example.com/");
  142. let b: Url = url("http://example.com:8080/");
  143. assert!(a != b, "{:?} != {:?}", a, b);
  144. // Different scheme
  145. let a: Url = url("http://example.com/");
  146. let b: Url = url("https://example.com/");
  147. assert_ne!(a, b);
  148. // Different host
  149. let a: Url = url("http://foo.com/");
  150. let b: Url = url("http://bar.com/");
  151. assert_ne!(a, b);
  152. // Missing path, automatically substituted. Semantically the same.
  153. let a: Url = url("http://foo.com");
  154. let b: Url = url("http://foo.com/");
  155. check_eq(&a, &b);
  156. }
  157. #[test]
  158. fn host() {
  159. fn assert_host(input: &str, host: Host<&str>) {
  160. assert_eq!(Url::parse(input).unwrap().host(), Some(host));
  161. }
  162. assert_host("http://www.mozilla.org", Host::Domain("www.mozilla.org"));
  163. assert_host("http://1.35.33.49", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  164. assert_host("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", Host::Ipv6(Ipv6Addr::new(
  165. 0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344)));
  166. assert_host("http://1.35.+33.49", Host::Domain("1.35.+33.49"));
  167. assert_host("http://[::]", Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)));
  168. assert_host("http://[::1]", Host::Ipv6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)));
  169. assert_host("http://0x1.0X23.0x21.061", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  170. assert_host("http://0x1232131", Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)));
  171. assert_host("http://111", Host::Ipv4(Ipv4Addr::new(0, 0, 0, 111)));
  172. assert_host("http://2..2.3", Host::Domain("2..2.3"));
  173. assert!(Url::parse("http://42.0x1232131").is_err());
  174. assert!(Url::parse("http://192.168.0.257").is_err());
  175. }
  176. #[test]
  177. fn host_serialization() {
  178. // libstd’s `Display for Ipv6Addr` serializes 0:0:0:0:0:0:_:_ and 0:0:0:0:0:ffff:_:_
  179. // using IPv4-like syntax, as suggested in https://tools.ietf.org/html/rfc5952#section-4
  180. // but https://url.spec.whatwg.org/#concept-ipv6-serializer specifies not to.
  181. // Not [::0.0.0.2] / [::ffff:0.0.0.2]
  182. assert_eq!(Url::parse("http://[0::2]").unwrap().host_str(), Some("[::2]"));
  183. assert_eq!(Url::parse("http://[0::ffff:0:2]").unwrap().host_str(), Some("[::ffff:0:2]"));
  184. }
  185. #[test]
  186. fn test_idna() {
  187. assert!("http://goșu.ro".parse::<Url>().is_ok());
  188. assert_eq!(Url::parse("http://☃.net/").unwrap().host(), Some(Host::Domain("xn--n3h.net")));
  189. assert!("https://r2---sn-huoa-cvhl.googlevideo.com/crossdomain.xml".parse::<Url>().is_ok());
  190. }
  191. #[test]
  192. fn test_serialization() {
  193. let data = [
  194. ("http://example.com/", "http://example.com/"),
  195. ("http://addslash.com", "http://addslash.com/"),
  196. ("http://@emptyuser.com/", "http://emptyuser.com/"),
  197. ("http://:@emptypass.com/", "http://emptypass.com/"),
  198. ("http://user@user.com/", "http://user@user.com/"),
  199. ("http://user:pass@userpass.com/", "http://user:pass@userpass.com/"),
  200. ("http://slashquery.com/path/?q=something", "http://slashquery.com/path/?q=something"),
  201. ("http://noslashquery.com/path?q=something", "http://noslashquery.com/path?q=something")
  202. ];
  203. for &(input, result) in &data {
  204. let url = Url::parse(input).unwrap();
  205. assert_eq!(url.as_str(), result);
  206. }
  207. }
  208. #[test]
  209. fn test_form_urlencoded() {
  210. let pairs: &[(Cow<str>, Cow<str>)] = &[
  211. ("foo".into(), "é&".into()),
  212. ("bar".into(), "".into()),
  213. ("foo".into(), "#".into())
  214. ];
  215. let encoded = form_urlencoded::Serializer::new(String::new()).extend_pairs(pairs).finish();
  216. assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
  217. assert_eq!(form_urlencoded::parse(encoded.as_bytes()).collect::<Vec<_>>(), pairs.to_vec());
  218. }
  219. #[test]
  220. fn test_form_serialize() {
  221. let encoded = form_urlencoded::Serializer::new(String::new())
  222. .append_pair("foo", "é&")
  223. .append_pair("bar", "")
  224. .append_pair("foo", "#")
  225. .finish();
  226. assert_eq!(encoded, "foo=%C3%A9%26&bar=&foo=%23");
  227. }
  228. #[test]
  229. fn form_urlencoded_custom_encoding_override() {
  230. let encoded = form_urlencoded::Serializer::new(String::new())
  231. .custom_encoding_override(|s| s.as_bytes().to_ascii_uppercase().into())
  232. .append_pair("foo", "bar")
  233. .finish();
  234. assert_eq!(encoded, "FOO=BAR");
  235. }
  236. #[test]
  237. fn host_and_port_display() {
  238. assert_eq!(
  239. format!(
  240. "{}",
  241. HostAndPort{ host: Host::Domain("www.mozilla.org"), port: 80}
  242. ),
  243. "www.mozilla.org:80"
  244. );
  245. assert_eq!(
  246. format!(
  247. "{}",
  248. HostAndPort::<String>{ host: Host::Ipv4(Ipv4Addr::new(1, 35, 33, 49)), port: 65535 }
  249. ),
  250. "1.35.33.49:65535"
  251. );
  252. assert_eq!(
  253. format!(
  254. "{}",
  255. HostAndPort::<String>{
  256. host: Host::Ipv6(Ipv6Addr::new(
  257. 0x2001, 0x0db8, 0x85a3, 0x08d3, 0x1319, 0x8a2e, 0x0370, 0x7344
  258. )),
  259. port: 1337
  260. })
  261. ,
  262. "[2001:db8:85a3:8d3:1319:8a2e:370:7344]:1337"
  263. )
  264. }
  265. #[test]
  266. /// https://github.com/servo/rust-url/issues/61
  267. fn issue_61() {
  268. let mut url = Url::parse("http://mozilla.org").unwrap();
  269. url.set_scheme("https").unwrap();
  270. assert_eq!(url.port(), None);
  271. assert_eq!(url.port_or_known_default(), Some(443));
  272. url.check_invariants().unwrap();
  273. }
  274. #[test]
  275. #[cfg(not(windows))]
  276. /// https://github.com/servo/rust-url/issues/197
  277. fn issue_197() {
  278. let mut url = Url::from_file_path("/").expect("Failed to parse path");
  279. url.check_invariants().unwrap();
  280. assert_eq!(url, Url::parse("file:///").expect("Failed to parse path + protocol"));
  281. url.path_segments_mut().expect("path_segments_mut").pop_if_empty();
  282. }
  283. #[test]
  284. fn issue_241() {
  285. Url::parse("mailto:").unwrap().cannot_be_a_base();
  286. }
  287. #[test]
  288. /// https://github.com/servo/rust-url/issues/222
  289. fn append_trailing_slash() {
  290. let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap();
  291. url.check_invariants().unwrap();
  292. url.path_segments_mut().unwrap().push("");
  293. url.check_invariants().unwrap();
  294. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/?a=b");
  295. }
  296. #[test]
  297. /// https://github.com/servo/rust-url/issues/227
  298. fn extend_query_pairs_then_mutate() {
  299. let mut url: Url = "http://localhost:6767/foo/bar".parse().unwrap();
  300. url.query_pairs_mut().extend_pairs(vec![ ("auth", "my-token") ].into_iter());
  301. url.check_invariants().unwrap();
  302. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?auth=my-token");
  303. url.path_segments_mut().unwrap().push("some_other_path");
  304. url.check_invariants().unwrap();
  305. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar/some_other_path?auth=my-token");
  306. }
  307. #[test]
  308. /// https://github.com/servo/rust-url/issues/222
  309. fn append_empty_segment_then_mutate() {
  310. let mut url: Url = "http://localhost:6767/foo/bar?a=b".parse().unwrap();
  311. url.check_invariants().unwrap();
  312. url.path_segments_mut().unwrap().push("").pop();
  313. url.check_invariants().unwrap();
  314. assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?a=b");
  315. }
  316. #[test]
  317. /// https://github.com/servo/rust-url/issues/243
  318. fn test_set_host() {
  319. let mut url = Url::parse("https://example.net/hello").unwrap();
  320. url.set_host(Some("foo.com")).unwrap();
  321. assert_eq!(url.as_str(), "https://foo.com/hello");
  322. assert!(url.set_host(None).is_err());
  323. assert_eq!(url.as_str(), "https://foo.com/hello");
  324. assert!(url.set_host(Some("")).is_err());
  325. assert_eq!(url.as_str(), "https://foo.com/hello");
  326. let mut url = Url::parse("foobar://example.net/hello").unwrap();
  327. url.set_host(None).unwrap();
  328. assert_eq!(url.as_str(), "foobar:/hello");
  329. let mut url = Url::parse("foo://ș").unwrap();
  330. assert_eq!(url.as_str(), "foo://%C8%99/");
  331. url.set_host(Some("goșu.ro")).unwrap();
  332. assert_eq!(url.as_str(), "foo://go%C8%99u.ro/");
  333. }
  334. #[test]
  335. // https://github.com/servo/rust-url/issues/166
  336. fn test_leading_dots() {
  337. assert_eq!(Host::parse(".org").unwrap(), Host::Domain(".org".to_owned()));
  338. assert_eq!(Url::parse("file://./foo").unwrap().domain(), Some("."));
  339. }
  340. // This is testing that the macro produces buildable code when invoked
  341. // inside both a module and a function
  342. #[test]
  343. fn define_encode_set_scopes() {
  344. use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
  345. define_encode_set! {
  346. /// This encode set is used in the URL parser for query strings.
  347. pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
  348. }
  349. assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
  350. mod m {
  351. use url::percent_encoding::{utf8_percent_encode, SIMPLE_ENCODE_SET};
  352. define_encode_set! {
  353. /// This encode set is used in the URL parser for query strings.
  354. pub QUERY_ENCODE_SET = [SIMPLE_ENCODE_SET] | {' ', '"', '#', '<', '>'}
  355. }
  356. pub fn test() {
  357. assert_eq!(utf8_percent_encode("foo bar", QUERY_ENCODE_SET).collect::<String>(), "foo%20bar");
  358. }
  359. }
  360. m::test();
  361. }
  362. #[test]
  363. /// https://github.com/servo/rust-url/issues/302
  364. fn test_origin_hash() {
  365. use std::hash::{Hash,Hasher};
  366. use std::collections::hash_map::DefaultHasher;
  367. fn hash<T: Hash>(value: &T) -> u64 {
  368. let mut hasher = DefaultHasher::new();
  369. value.hash(&mut hasher);
  370. hasher.finish()
  371. }
  372. let origin = &Url::parse("http://example.net/").unwrap().origin();
  373. let origins_to_compare = [
  374. Url::parse("http://example.net:80/").unwrap().origin(),
  375. Url::parse("http://example.net:81/").unwrap().origin(),
  376. Url::parse("http://example.net").unwrap().origin(),
  377. Url::parse("http://example.net/hello").unwrap().origin(),
  378. Url::parse("https://example.net").unwrap().origin(),
  379. Url::parse("ftp://example.net").unwrap().origin(),
  380. Url::parse("file://example.net").unwrap().origin(),
  381. Url::parse("http://user@example.net/").unwrap().origin(),
  382. Url::parse("http://user:pass@example.net/").unwrap().origin(),
  383. ];
  384. for origin_to_compare in &origins_to_compare {
  385. if origin == origin_to_compare {
  386. assert_eq!(hash(origin), hash(origin_to_compare));
  387. } else {
  388. assert_ne!(hash(origin), hash(origin_to_compare));
  389. }
  390. }
  391. let opaque_origin = Url::parse("file://example.net").unwrap().origin();
  392. let same_opaque_origin = Url::parse("file://example.net").unwrap().origin();
  393. let other_opaque_origin = Url::parse("file://other").unwrap().origin();
  394. assert_ne!(hash(&opaque_origin), hash(&same_opaque_origin));
  395. assert_ne!(hash(&opaque_origin), hash(&other_opaque_origin));
  396. }
  397. #[test]
  398. fn test_windows_unc_path() {
  399. if !cfg!(windows) {
  400. return
  401. }
  402. let url = Url::from_file_path(Path::new(r"\\host\share\path\file.txt")).unwrap();
  403. assert_eq!(url.as_str(), "file://host/share/path/file.txt");
  404. let url = Url::from_file_path(Path::new(r"\\höst\share\path\file.txt")).unwrap();
  405. assert_eq!(url.as_str(), "file://xn--hst-sna/share/path/file.txt");
  406. let url = Url::from_file_path(Path::new(r"\\192.168.0.1\share\path\file.txt")).unwrap();
  407. assert_eq!(url.host(), Some(Host::Ipv4(Ipv4Addr::new(192, 168, 0, 1))));
  408. let path = url.to_file_path().unwrap();
  409. assert_eq!(path.to_str(), Some(r"\\192.168.0.1\share\path\file.txt"));
  410. // Another way to write these:
  411. let url = Url::from_file_path(Path::new(r"\\?\UNC\host\share\path\file.txt")).unwrap();
  412. assert_eq!(url.as_str(), "file://host/share/path/file.txt");
  413. // Paths starting with "\\.\" (Local Device Paths) are intentionally not supported.
  414. let url = Url::from_file_path(Path::new(r"\\.\some\path\file.txt"));
  415. assert!(url.is_err());
  416. }
  417. #[test]
  418. fn test_syntax_violation_callback() {
  419. use url::SyntaxViolation::*;
  420. let violation = Cell::new(None);
  421. let url = Url::options()
  422. .syntax_violation_callback(Some(&|v| violation.set(Some(v))))
  423. .parse("http:////mozilla.org:42").unwrap();
  424. assert_eq!(url.port(), Some(42));
  425. let v = violation.take().unwrap();
  426. assert_eq!(v, ExpectedDoubleSlash);
  427. assert_eq!(v.description(), "expected //");
  428. }
  429. #[test]
  430. fn test_syntax_violation_callback_lifetimes() {
  431. use url::SyntaxViolation::*;
  432. let violation = Cell::new(None);
  433. let vfn = |s| violation.set(Some(s));
  434. let url = Url::options()
  435. .syntax_violation_callback(Some(&vfn))
  436. .parse("http:////mozilla.org:42").unwrap();
  437. assert_eq!(url.port(), Some(42));
  438. assert_eq!(violation.take(), Some(ExpectedDoubleSlash));
  439. let url = Url::options()
  440. .syntax_violation_callback(Some(&vfn))
  441. .parse("http://mozilla.org\\path").unwrap();
  442. assert_eq!(url.path(), "/path");
  443. assert_eq!(violation.take(), Some(Backslash));
  444. }
  445. #[test]
  446. fn test_options_reuse() {
  447. use url::SyntaxViolation::*;
  448. let violations = RefCell::new(Vec::new());
  449. let vfn = |v| violations.borrow_mut().push(v);
  450. let options = Url::options()
  451. .syntax_violation_callback(Some(&vfn));
  452. let url = options.parse("http:////mozilla.org").unwrap();
  453. let options = options.base_url(Some(&url));
  454. let url = options.parse("/sub\\path").unwrap();
  455. assert_eq!(url.as_str(), "http://mozilla.org/sub/path");
  456. assert_eq!(*violations.borrow(),
  457. vec!(ExpectedDoubleSlash, Backslash));
  458. }