Skip to content

Commit ea2f97f

Browse files
committed
Use assert_eq instead of println in doctests. Fix said doctests.
1 parent d02b1c3 commit ea2f97f

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

src/percent_encoding.rs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@
2727
//! # Examples
2828
//!
2929
//! ```
30-
//! extern crate url;
31-
//! use url::percent_encoding::{utf8_percent_encode, QUERY_ENCODE_SET};
30+
//! use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
3231
//!
33-
//! //prints "foo%20bar%3F"
34-
//! # fn main() {
35-
//! println!("{}", utf8_percent_encode("foo bar?", QUERY_ENCODE_SET).collect::<String>());
36-
//! # }
32+
//! assert_eq!(utf8_percent_encode("foo bar?", DEFAULT_ENCODE_SET).to_string(), "foo%20bar%3F");
3733
//! ```
3834
3935
use encoding;
@@ -168,16 +164,10 @@ define_encode_set! {
168164
/// # Examples
169165
///
170166
/// ```
171-
/// extern crate url;
172167
/// use url::percent_encoding::percent_encode_byte;
173168
///
174-
/// //prints %66%6F%6F%20%62%61%72
175-
/// # fn main() {
176-
/// let sample = b"foo bar";
177-
/// for character in sample {
178-
/// print!("{}", percent_encode_byte(*character));
179-
/// }
180-
/// # }
169+
/// assert_eq!("foo bar".bytes().map(percent_encode_byte).collect::<String>(),
170+
/// "%66%6F%6F%20%62%61%72");
181171
/// ```
182172
pub fn percent_encode_byte(byte: u8) -> &'static str {
183173
let index = usize::from(byte) * 3;
@@ -216,13 +206,9 @@ pub fn percent_encode_byte(byte: u8) -> &'static str {
216206
/// # Examples
217207
///
218208
/// ```
219-
/// extern crate url;
220209
/// use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
221210
///
222-
/// //prints foo%20bar%3F
223-
/// # fn main() {
224-
/// println!("{}", percent_encode(b"foo bar?", DEFAULT_ENCODE_SET).collect::<String>());
225-
/// # }
211+
/// assert_eq!(percent_encode(b"foo bar?", DEFAULT_ENCODE_SET).to_string(), "foo%20bar%3F");
226212
/// ```
227213
#[inline]
228214
pub fn percent_encode<E: EncodeSet>(input: &[u8], encode_set: E) -> PercentEncode<E> {
@@ -239,13 +225,9 @@ pub fn percent_encode<E: EncodeSet>(input: &[u8], encode_set: E) -> PercentEncod
239225
/// # Examples
240226
///
241227
/// ```
242-
/// extern crate url;
243-
/// use url::percent_encoding::{utf8_percent_encode, QUERY_ENCODE_SET};
228+
/// use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
244229
///
245-
/// //prints "foo%20bar%3F"
246-
/// # fn main() {
247-
/// println!("{}", utf8_percent_encode("foo bar?", QUERY_ENCODE_SET).collect::<String>());
248-
/// # }
230+
/// assert_eq!(utf8_percent_encode("foo bar?", DEFAULT_ENCODE_SET).to_string(), "foo%20bar%3F");
249231
/// ```
250232
#[inline]
251233
pub fn utf8_percent_encode<E: EncodeSet>(input: &str, encode_set: E) -> PercentEncode<E> {
@@ -335,17 +317,9 @@ impl<'a, E: EncodeSet> From<PercentEncode<'a, E>> for Cow<'a, str> {
335317
/// # Examples
336318
///
337319
/// ```
338-
/// extern crate url;
339320
/// use url::percent_encoding::percent_decode;
340321
///
341-
/// //prints "foo bar?"
342-
/// # fn run() -> Result<(), std::str::Utf8Error> {
343-
/// println!("{}", percent_decode(b"foo%20bar%3F").decode_utf8()?);
344-
/// # Ok( () )
345-
/// # }
346-
/// # fn main() {
347-
/// # run().unwrap();
348-
/// # }
322+
/// assert_eq!(percent_decode(b"foo%20bar%3F").decode_utf8().unwrap(), "foo bar?");
349323
/// ```
350324
#[inline]
351325
pub fn percent_decode(input: &[u8]) -> PercentDecode {

0 commit comments

Comments
 (0)