| 10 | |
| 11 | #[test] |
| 12 | fn test_arg() { |
| 13 | use rustix::cstr; |
| 14 | use std::borrow::Borrow; |
| 15 | |
| 16 | let t: &str = "hello"; |
| 17 | assert_eq!("hello", Arg::as_str(&t).unwrap()); |
| 18 | assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); |
| 19 | assert_eq!( |
| 20 | cstr!("hello"), |
| 21 | Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap()) |
| 22 | ); |
| 23 | assert_eq!( |
| 24 | cstr!("hello"), |
| 25 | Borrow::<CStr>::borrow(&t.into_c_str().unwrap()) |
| 26 | ); |
| 27 | |
| 28 | let t: String = "hello".to_owned(); |
| 29 | assert_eq!("hello", Arg::as_str(&t).unwrap()); |
| 30 | assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); |
| 31 | assert_eq!( |
| 32 | cstr!("hello"), |
| 33 | Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap()) |
| 34 | ); |
| 35 | assert_eq!( |
| 36 | cstr!("hello"), |
| 37 | Borrow::<CStr>::borrow(&t.into_c_str().unwrap()) |
| 38 | ); |
| 39 | |
| 40 | let t: &OsStr = OsStr::new("hello"); |
| 41 | assert_eq!("hello", t.as_str().unwrap()); |
| 42 | assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); |
| 43 | assert_eq!( |
| 44 | cstr!("hello"), |
| 45 | Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap()) |
| 46 | ); |
| 47 | assert_eq!( |
| 48 | cstr!("hello"), |
| 49 | Borrow::<CStr>::borrow(&t.into_c_str().unwrap()) |
| 50 | ); |
| 51 | |
| 52 | let t: OsString = OsString::from("hello".to_owned()); |
| 53 | assert_eq!("hello", t.as_str().unwrap()); |
| 54 | assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); |
| 55 | assert_eq!( |
| 56 | cstr!("hello"), |
| 57 | Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap()) |
| 58 | ); |
| 59 | assert_eq!( |
| 60 | cstr!("hello"), |
| 61 | Borrow::<CStr>::borrow(&t.into_c_str().unwrap()) |
| 62 | ); |
| 63 | |
| 64 | let t: &Path = Path::new("hello"); |
| 65 | assert_eq!("hello", t.as_str().unwrap()); |
| 66 | assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t)); |
| 67 | assert_eq!( |
| 68 | cstr!("hello"), |
| 69 | Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap()) |