]>
git.proxmox.com Git - rustc.git/blob - library/std/src/ffi/os_str/tests.rs
2 use crate::sys_common
::{AsInner, IntoInner}
;
8 fn test_os_string_with_capacity() {
9 let os_string
= OsString
::with_capacity(0);
10 assert_eq
!(0, os_string
.inner
.into_inner().capacity());
12 let os_string
= OsString
::with_capacity(10);
13 assert_eq
!(10, os_string
.inner
.into_inner().capacity());
15 let mut os_string
= OsString
::with_capacity(0);
16 os_string
.push("abc");
17 assert
!(os_string
.inner
.into_inner().capacity() >= 3);
21 fn test_os_string_clear() {
22 let mut os_string
= OsString
::from("abc");
23 assert_eq
!(3, os_string
.inner
.as_inner().len());
26 assert_eq
!(&os_string
, "");
27 assert_eq
!(0, os_string
.inner
.as_inner().len());
31 fn test_os_string_capacity() {
32 let os_string
= OsString
::with_capacity(0);
33 assert_eq
!(0, os_string
.capacity());
35 let os_string
= OsString
::with_capacity(10);
36 assert_eq
!(10, os_string
.capacity());
38 let mut os_string
= OsString
::with_capacity(0);
39 os_string
.push("abc");
40 assert
!(os_string
.capacity() >= 3);
44 fn test_os_string_reserve() {
45 let mut os_string
= OsString
::new();
46 assert_eq
!(os_string
.capacity(), 0);
49 assert
!(os_string
.capacity() >= 2);
55 assert
!(os_string
.capacity() >= 16);
56 os_string
.reserve(16);
57 assert
!(os_string
.capacity() >= 32);
61 os_string
.reserve(16);
62 assert
!(os_string
.capacity() >= 33)
66 fn test_os_string_reserve_exact() {
67 let mut os_string
= OsString
::new();
68 assert_eq
!(os_string
.capacity(), 0);
70 os_string
.reserve_exact(2);
71 assert
!(os_string
.capacity() >= 2);
77 assert
!(os_string
.capacity() >= 16);
78 os_string
.reserve_exact(16);
79 assert
!(os_string
.capacity() >= 32);
83 os_string
.reserve_exact(16);
84 assert
!(os_string
.capacity() >= 33)
88 fn test_os_string_default() {
89 let os_string
: OsString
= Default
::default();
90 assert_eq
!("", &os_string
);
94 fn test_os_str_is_empty() {
95 let mut os_string
= OsString
::new();
96 assert
!(os_string
.is_empty());
98 os_string
.push("abc");
99 assert
!(!os_string
.is_empty());
102 assert
!(os_string
.is_empty());
106 fn test_os_str_len() {
107 let mut os_string
= OsString
::new();
108 assert_eq
!(0, os_string
.len());
110 os_string
.push("abc");
111 assert_eq
!(3, os_string
.len());
114 assert_eq
!(0, os_string
.len());
118 fn test_os_str_default() {
119 let os_str
: &OsStr
= Default
::default();
120 assert_eq
!("", os_str
);
125 let orig
= "Hello, world!";
126 let os_str
= OsStr
::new(orig
);
127 let boxed
: Box
<OsStr
> = Box
::from(os_str
);
128 let os_string
= os_str
.to_owned().into_boxed_os_str().into_os_string();
129 assert_eq
!(os_str
, &*boxed
);
130 assert_eq
!(&*boxed
, &*os_string
);
131 assert_eq
!(&*os_string
, os_str
);
136 let boxed
= <Box
<OsStr
>>::default();
137 assert
!(boxed
.is_empty());
141 fn test_os_str_clone_into() {
142 let mut os_string
= OsString
::with_capacity(123);
143 os_string
.push("hello");
144 let os_str
= OsStr
::new("bonjour");
145 os_str
.clone_into(&mut os_string
);
146 assert_eq
!(os_str
, os_string
);
147 assert
!(os_string
.capacity() >= 123);
152 let orig
= "Hello, world!";
153 let os_str
= OsStr
::new(orig
);
154 let rc
: Rc
<OsStr
> = Rc
::from(os_str
);
155 let arc
: Arc
<OsStr
> = Arc
::from(os_str
);
157 assert_eq
!(&*rc
, os_str
);
158 assert_eq
!(&*arc
, os_str
);
160 let rc2
: Rc
<OsStr
> = Rc
::from(os_str
.to_owned());
161 let arc2
: Arc
<OsStr
> = Arc
::from(os_str
.to_owned());
163 assert_eq
!(&*rc2
, os_str
);
164 assert_eq
!(&*arc2
, os_str
);