|
7 | 7 | // except according to those terms. |
8 | 8 |
|
9 | 9 | //! Unit tests |
| 10 | +#![no_std] |
| 11 | +#![cfg_attr( |
| 12 | + all( |
| 13 | + not(feature = "std"), |
| 14 | + not(feature = "no_std_net"), |
| 15 | + feature = "unstable" |
| 16 | + ), |
| 17 | + feature(ip_in_core) |
| 18 | +)] |
| 19 | +#![cfg_attr( |
| 20 | + all(not(feature = "std"), feature = "unstable"), |
| 21 | + feature(error_in_core) |
| 22 | +)] |
10 | 23 |
|
| 24 | +#[cfg(feature = "std")] |
| 25 | +extern crate std; |
| 26 | + |
| 27 | +#[macro_use] |
| 28 | +extern crate alloc; |
| 29 | + |
| 30 | +#[cfg(not(feature = "alloc"))] |
| 31 | +compile_error!("the `alloc` feature must be enabled"); |
| 32 | + |
| 33 | +#[cfg(not(any(feature = "no_std_net", feature = "std", feature = "unstable")))] |
| 34 | +compile_error!( |
| 35 | + "Either the `no_std_net`, `std` or, on nightly, the `unstable` feature, must be enabled" |
| 36 | +); |
| 37 | + |
| 38 | +use alloc::borrow::Cow; |
| 39 | +use alloc::borrow::ToOwned; |
| 40 | +use alloc::string::{String, ToString}; |
| 41 | +use alloc::vec::Vec; |
11 | 42 | use core::cell::{Cell, RefCell}; |
12 | | -use no_std_net::{Ipv4Addr, Ipv6Addr}; |
13 | | -use std::borrow::Cow; |
14 | 43 | #[cfg(feature = "std")] |
15 | 44 | use std::path::{Path, PathBuf}; |
16 | 45 | use url::{form_urlencoded, Host, Origin, Url}; |
17 | 46 |
|
| 47 | +/// `std` version of `net` |
| 48 | +#[cfg(feature = "std")] |
| 49 | +pub(crate) mod net { |
| 50 | + pub use std::net::*; |
| 51 | +} |
| 52 | +/// `no_std` non-nightly of `net` |
| 53 | +#[cfg(all(not(feature = "std"), feature = "no_std_net"))] |
| 54 | +pub(crate) mod net { |
| 55 | + pub use no_std_net::*; |
| 56 | +} |
| 57 | +/// `no_std` nightly version of `net` |
| 58 | +#[cfg(all(not(feature = "std"), not(feature = "no_std_net")))] |
| 59 | +pub(crate) mod net { |
| 60 | + pub use core::net::*; |
| 61 | +} |
| 62 | + |
| 63 | +use crate::net::{Ipv4Addr, Ipv6Addr}; |
| 64 | + |
18 | 65 | #[test] |
19 | 66 | fn size() { |
20 | | - use std::mem::size_of; |
| 67 | + use core::mem::size_of; |
21 | 68 | assert_eq!(size_of::<Url>(), size_of::<Option<Url>>()); |
22 | 69 | } |
23 | 70 |
|
@@ -262,6 +309,7 @@ fn issue_124() { |
262 | 309 | } |
263 | 310 |
|
264 | 311 | #[test] |
| 312 | +#[cfg(feature = "std")] |
265 | 313 | fn test_equality() { |
266 | 314 | use std::collections::hash_map::DefaultHasher; |
267 | 315 | use std::hash::{Hash, Hasher}; |
@@ -542,6 +590,7 @@ fn test_leading_dots() { |
542 | 590 | } |
543 | 591 |
|
544 | 592 | #[test] |
| 593 | +#[cfg(feature = "std")] |
545 | 594 | /// https://github.com/servo/rust-url/issues/302 |
546 | 595 | fn test_origin_hash() { |
547 | 596 | use std::collections::hash_map::DefaultHasher; |
|
0 commit comments