Skip to content

Commit c58678a

Browse files
committed
Run the doctests
- add `run().unwrap()` to all result-guarded doctests
1 parent fb71349 commit c58678a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ assert!(issue_list_url.fragment() == None);
4747
assert!(!issue_list_url.cannot_be_a_base());
4848
# Ok(())
4949
# }
50+
# run().unwrap();
5051
```
5152
5253
Some URLs are said to be *cannot-be-a-base*:
@@ -68,6 +69,7 @@ assert!(data_url.query() == Some("World"));
6869
assert!(data_url.fragment() == Some(""));
6970
# Ok(())
7071
# }
72+
# run().unwrap();
7173
```
7274
7375
@@ -99,6 +101,7 @@ let css_url = this_document.join("../main.css")?;
99101
assert_eq!(css_url.as_str(), "http://servo.github.io/rust-url/main.css");
100102
# Ok(())
101103
# }
104+
# run().unwrap();
102105
*/
103106

104107
#[cfg(feature="rustc-serialize")] extern crate rustc_serialize;
@@ -235,6 +238,7 @@ impl Url {
235238
/// let url = Url::parse("https://example.net")?;
236239
/// # Ok(())
237240
/// # }
241+
/// # run().unwrap();
238242
/// ```
239243
#[inline]
240244
pub fn parse(input: &str) -> Result<Url, ::ParseError> {
@@ -256,6 +260,7 @@ impl Url {
256260
/// &[("lang", "rust"), ("browser", "servo")])?;
257261
/// # Ok(())
258262
/// # }
263+
/// # run().unwrap();
259264
/// ```
260265
#[inline]
261266
pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Url, ::ParseError>
@@ -295,6 +300,7 @@ impl Url {
295300
/// assert_eq!(url.as_str(), "https://example.net/a/b/c.png");
296301
/// # Ok(())
297302
/// # }
303+
/// # run().unwrap();
298304
/// ```
299305
#[inline]
300306
pub fn join(&self, input: &str) -> Result<Url, ::ParseError> {
@@ -326,6 +332,7 @@ impl Url {
326332
/// assert_eq!(url.as_str(), url_str);
327333
/// # Ok(())
328334
/// # }
335+
/// # run().unwrap();
329336
/// ```
330337
#[inline]
331338
pub fn as_str(&self) -> &str {
@@ -348,6 +355,7 @@ impl Url {
348355
/// assert_eq!(url.into_string(), url_str);
349356
/// # Ok(())
350357
/// # }
358+
/// # run().unwrap();
351359
/// ```
352360
#[inline]
353361
pub fn into_string(self) -> String {
@@ -483,6 +491,7 @@ impl Url {
483491
/// 21));
484492
/// # Ok(())
485493
/// # }
494+
/// # run().unwrap();
486495
/// ```
487496
///
488497
/// URL with `blob` scheme:
@@ -499,6 +508,7 @@ impl Url {
499508
/// 443));
500509
/// # Ok(())
501510
/// # }
511+
/// # run().unwrap();
502512
/// ```
503513
///
504514
/// URL with `file` scheme:
@@ -515,6 +525,7 @@ impl Url {
515525
/// assert!(url.origin() != other_url.origin());
516526
/// # Ok(())
517527
/// # }
528+
/// # run().unwrap();
518529
/// ```
519530
///
520531
/// URL with other scheme:
@@ -528,6 +539,7 @@ impl Url {
528539
/// assert!(!url.origin().is_tuple());
529540
/// # Ok(())
530541
/// # }
542+
/// # run().unwrap();
531543
/// ```
532544
#[inline]
533545
pub fn origin(&self) -> Origin {
@@ -547,6 +559,7 @@ impl Url {
547559
/// assert_eq!(url.scheme(), "file");
548560
/// # Ok(())
549561
/// # }
562+
/// # run().unwrap();
550563
/// ```
551564
#[inline]
552565
pub fn scheme(&self) -> &str {
@@ -576,6 +589,7 @@ impl Url {
576589
/// assert!(!url.has_authority());
577590
/// # Ok(())
578591
/// # }
592+
/// # run().unwrap();
579593
/// ```
580594
#[inline]
581595
pub fn has_authority(&self) -> bool {
@@ -606,6 +620,7 @@ impl Url {
606620
/// assert!(url.cannot_be_a_base());
607621
/// # Ok(())
608622
/// # }
623+
/// # run().unwrap();
609624
/// ```
610625
#[inline]
611626
pub fn cannot_be_a_base(&self) -> bool {
@@ -632,6 +647,7 @@ impl Url {
632647
/// assert_eq!(url.username(), "");
633648
/// # Ok(())
634649
/// # }
650+
/// # run().unwrap();
635651
/// ```
636652
pub fn username(&self) -> &str {
637653
if self.has_authority() {
@@ -663,6 +679,7 @@ impl Url {
663679
/// assert_eq!(url.password(), None);
664680
/// # Ok(())
665681
/// # }
682+
/// # run().unwrap();
666683
/// ```
667684
pub fn password(&self) -> Option<&str> {
668685
// This ':' is not the one marking a port number since a host can not be empty.
@@ -694,6 +711,7 @@ impl Url {
694711
/// assert!(!url.has_host());
695712
/// # Ok(())
696713
/// # }
714+
/// # run().unwrap();
697715
/// ```
698716
pub fn has_host(&self) -> bool {
699717
!matches!(self.host, HostInternal::None)
@@ -729,6 +747,7 @@ impl Url {
729747
/// assert_eq!(url.host_str(), None);
730748
/// # Ok(())
731749
/// # }
750+
/// # run().unwrap();
732751
/// ```
733752
pub fn host_str(&self) -> Option<&str> {
734753
if self.has_host() {
@@ -766,6 +785,7 @@ impl Url {
766785
/// assert!(url.host().is_none());
767786
/// # Ok(())
768787
/// # }
788+
/// # run().unwrap();
769789
/// ```
770790
pub fn host(&self) -> Option<Host<&str>> {
771791
match self.host {
@@ -795,6 +815,7 @@ impl Url {
795815
/// assert_eq!(url.domain(), Some("example.com"));
796816
/// # Ok(())
797817
/// # }
818+
/// # run().unwrap();
798819
/// ```
799820
pub fn domain(&self) -> Option<&str> {
800821
match self.host {
@@ -819,6 +840,7 @@ impl Url {
819840
/// assert_eq!(url.port(), Some(22));
820841
/// # Ok(())
821842
/// # }
843+
/// # run().unwrap();
822844
/// ```
823845
#[inline]
824846
pub fn port(&self) -> Option<u16> {
@@ -850,6 +872,7 @@ impl Url {
850872
/// assert_eq!(url.port_or_known_default(), Some(443));
851873
/// # Ok(())
852874
/// # }
875+
/// # run().unwrap();
853876
/// ```
854877
#[inline]
855878
pub fn port_or_known_default(&self) -> Option<u16> {
@@ -942,6 +965,7 @@ impl Url {
942965
/// assert!(url.path_segments().is_none());
943966
/// # Ok(())
944967
/// # }
968+
/// # run().unwrap();
945969
/// ```
946970
pub fn path_segments(&self) -> Option<str::Split<char>> {
947971
let path = self.path();
@@ -1072,6 +1096,7 @@ impl Url {
10721096
/// "https://example.net/?foo=bar+%26+baz&saisons=%C3%89t%C3%A9%2Bhiver#nav");
10731097
/// # Ok(())
10741098
/// # }
1099+
/// # run().unwrap();
10751100
/// ```
10761101
///
10771102
/// Note: `url.query_pairs_mut().clear();` is equivalent to `url.set_query(Some(""))`,
@@ -1171,6 +1196,7 @@ impl Url {
11711196
/// assert_eq!(url.as_str(), "ssh://example.net/");
11721197
/// # Ok(())
11731198
/// # }
1199+
/// # run().unwrap();
11741200
/// ```
11751201
///
11761202
/// Cannot set port for cannot-be-a-base URLs:
@@ -1189,6 +1215,7 @@ impl Url {
11891215
/// assert!(result.is_err());
11901216
/// # Ok(())
11911217
/// # }
1218+
/// # run().unwrap();
11921219
/// ```
11931220
pub fn set_port(&mut self, mut port: Option<u16>) -> Result<(), ()> {
11941221
if !self.has_host() || self.scheme() == "file" {
@@ -1254,6 +1281,7 @@ impl Url {
12541281
/// assert_eq!(url.as_str(), "https://rust-lang.org/");
12551282
/// # Ok(())
12561283
/// # }
1284+
/// # run().unwrap();
12571285
/// ```
12581286
///
12591287
/// Remove host:
@@ -1269,6 +1297,7 @@ impl Url {
12691297
/// assert_eq!(url.as_str(), "foo:/");
12701298
/// # Ok(())
12711299
/// # }
1300+
/// # run().unwrap();
12721301
/// ```
12731302
///
12741303
/// Cannot remove host for 'special' schemes (e.g. `http`):
@@ -1284,6 +1313,7 @@ impl Url {
12841313
/// assert_eq!(url.as_str(), "https://example.net/");
12851314
/// # Ok(())
12861315
/// # }
1316+
/// # run().unwrap();
12871317
/// ```
12881318
///
12891319
/// Cannot change or remove host for cannot-be-a-base URLs:
@@ -1304,6 +1334,7 @@ impl Url {
13041334
/// assert_eq!(url.as_str(), "mailto:[email protected]");
13051335
/// # Ok(())
13061336
/// # }
1337+
/// # run().unwrap();
13071338
/// ```
13081339
pub fn set_host(&mut self, host: Option<&str>) -> Result<(), ParseError> {
13091340
if self.cannot_be_a_base() {
@@ -1507,6 +1538,7 @@ impl Url {
15071538
/// assert!(result.is_ok());
15081539
/// # Ok(())
15091540
/// # }
1541+
/// # run().unwrap();
15101542
/// ```
15111543
///
15121544
///
@@ -1523,6 +1555,7 @@ impl Url {
15231555
/// assert!(result.is_err());
15241556
/// # Ok(())
15251557
/// # }
1558+
/// # run().unwrap();
15261559
/// ```
15271560
///
15281561
/// Cannot change URL’s scheme from `mailto` (cannot-be-a-base) to `https`:
@@ -1538,6 +1571,7 @@ impl Url {
15381571
/// assert!(result.is_err());
15391572
/// # Ok(())
15401573
/// # }
1574+
/// # run().unwrap();
15411575
/// ```
15421576
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()> {
15431577
let mut parser = Parser::for_setter(String::new());
@@ -1590,6 +1624,7 @@ impl Url {
15901624
/// assert!(url.is_err());
15911625
/// # Ok(())
15921626
/// # }
1627+
/// # run().unwrap();
15931628
/// # }
15941629
/// ```
15951630
pub fn from_file_path<P: AsRef<Path>>(path: P) -> Result<Url, ()> {

src/path_segments.rs

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use Url;
3131
/// assert_eq!(url.as_str(), "http://example.net/foo/img/2%2F100%25.png");
3232
/// # Ok(())
3333
/// # }
34+
/// # run().unwrap();
3435
/// ```
3536
pub struct PathSegmentsMut<'a> {
3637
url: &'a mut Url,
@@ -76,6 +77,7 @@ impl<'a> PathSegmentsMut<'a> {
7677
/// assert_eq!(url.as_str(), "https://github.com/logout");
7778
/// # Ok(())
7879
/// # }
80+
/// # run().unwrap();
7981
/// ```
8082
pub fn clear(&mut self) -> &mut Self {
8183
self.url.serialization.truncate(self.after_first_slash);
@@ -108,6 +110,7 @@ impl<'a> PathSegmentsMut<'a> {
108110
/// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/pulls");
109111
/// # Ok(())
110112
/// # }
113+
/// # run().unwrap();
111114
/// ```
112115
pub fn pop_if_empty(&mut self) -> &mut Self {
113116
if self.url.serialization[self.after_first_slash..].ends_with('/') {
@@ -170,6 +173,7 @@ impl<'a> PathSegmentsMut<'a> {
170173
/// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/issues/188");
171174
/// # Ok(())
172175
/// # }
176+
/// # run().unwrap();
173177
/// ```
174178
///
175179
/// In order to make sure that parsing the serialization of an URL gives the same URL,
@@ -186,6 +190,7 @@ impl<'a> PathSegmentsMut<'a> {
186190
/// assert_eq!(url.as_str(), "https://github.com/servo/rust-url/pulls");
187191
/// # Ok(())
188192
/// # }
193+
/// # run().unwrap();
189194
/// ```
190195
pub fn extend<I>(&mut self, segments: I) -> &mut Self
191196
where I: IntoIterator, I::Item: AsRef<str> {

0 commit comments

Comments
 (0)