27
27
//! # Examples
28
28
//!
29
29
//! ```
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};
32
31
//!
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");
37
33
//! ```
38
34
39
35
use encoding;
@@ -168,16 +164,10 @@ define_encode_set! {
168
164
/// # Examples
169
165
///
170
166
/// ```
171
- /// extern crate url;
172
167
/// use url::percent_encoding::percent_encode_byte;
173
168
///
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");
181
171
/// ```
182
172
pub fn percent_encode_byte ( byte : u8 ) -> & ' static str {
183
173
let index = usize:: from ( byte) * 3 ;
@@ -216,13 +206,9 @@ pub fn percent_encode_byte(byte: u8) -> &'static str {
216
206
/// # Examples
217
207
///
218
208
/// ```
219
- /// extern crate url;
220
209
/// use url::percent_encoding::{percent_encode, DEFAULT_ENCODE_SET};
221
210
///
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");
226
212
/// ```
227
213
#[ inline]
228
214
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
239
225
/// # Examples
240
226
///
241
227
/// ```
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};
244
229
///
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");
249
231
/// ```
250
232
#[ inline]
251
233
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> {
335
317
/// # Examples
336
318
///
337
319
/// ```
338
- /// extern crate url;
339
320
/// use url::percent_encoding::percent_decode;
340
321
///
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?");
349
323
/// ```
350
324
#[ inline]
351
325
pub fn percent_decode ( input : & [ u8 ] ) -> PercentDecode {
0 commit comments