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_join() {
89 let strings = [OsStr::new("hello"), OsStr::new("dear"), OsStr::new("world")];
90 assert_eq!("hello", strings[..1].join(OsStr::new(" ")));
91 assert_eq!("hello dear world", strings.join(OsStr::new(" ")));
92 assert_eq!("hellodearworld", strings.join(OsStr::new("")));
93 assert_eq!("hello.\n dear.\n world", strings.join(OsStr::new(".\n ")));
95 assert_eq!("dear world", strings[1..].join(&OsString::from(" ")));
97 let strings_abc = [OsString::from("a"), OsString::from("b"), OsString::from("c")];
98 assert_eq!("a b c", strings_abc.join(OsStr::new(" ")));
102 fn test_os_string_default() {
103 let os_string: OsString = Default::default();
104 assert_eq!("", &os_string);
108 fn test_os_str_is_empty() {
109 let mut os_string = OsString::new();
110 assert!(os_string.is_empty());
112 os_string.push("abc");
113 assert!(!os_string.is_empty());
116 assert!(os_string.is_empty());
120 fn test_os_str_len() {
121 let mut os_string = OsString::new();
122 assert_eq!(0, os_string.len());
124 os_string.push("abc");
125 assert_eq!(3, os_string.len());
128 assert_eq!(0, os_string.len());
132 fn test_os_str_default() {
133 let os_str: &OsStr = Default::default();
134 assert_eq!("", os_str);
139 let orig = "Hello, world!";
140 let os_str = OsStr::new(orig);
141 let boxed: Box<OsStr> = Box::from(os_str);
142 let os_string = os_str.to_owned().into_boxed_os_str().into_os_string();
143 assert_eq!(os_str, &*boxed);
144 assert_eq!(&*boxed, &*os_string);
145 assert_eq!(&*os_string, os_str);
150 let boxed = <Box<OsStr>>::default();
151 assert!(boxed.is_empty());
155 fn test_os_str_clone_into() {
156 let mut os_string = OsString::with_capacity(123);
157 os_string.push("hello");
158 let os_str = OsStr::new("bonjour");
159 os_str.clone_into(&mut os_string);
160 assert_eq!(os_str, os_string);
161 assert!(os_string.capacity() >= 123);
166 let orig = "Hello, world!";
167 let os_str = OsStr::new(orig);
168 let rc: Rc<OsStr> = Rc::from(os_str);
169 let arc: Arc<OsStr> = Arc::from(os_str);
171 assert_eq!(&*rc, os_str);
172 assert_eq!(&*arc, os_str);
174 let rc2: Rc<OsStr> = Rc::from(os_str.to_owned());
175 let arc2: Arc<OsStr> = Arc::from(os_str.to_owned());
177 assert_eq!(&*rc2, os_str);
178 assert_eq!(&*arc2, os_str);