1 use cxx::{let_cxx_string, CxxString};
2 use std::fmt::Write as _;
3
4 #[test]
test_async_cxx_string()5 fn test_async_cxx_string() {
6 async fn f() {
7 let_cxx_string!(s = "...");
8
9 async fn g(_: &CxxString) {}
10 g(&s).await;
11 }
12
13 // https://github.com/dtolnay/cxx/issues/693
14 fn assert_send(_: impl Send) {}
15 assert_send(f());
16 }
17
18 #[test]
test_debug()19 fn test_debug() {
20 let_cxx_string!(s = "x\"y\'z");
21
22 assert_eq!(format!("{:?}", s), r#""x\"y'z""#);
23 }
24
25 #[test]
test_fmt_write()26 fn test_fmt_write() {
27 let_cxx_string!(s = "");
28
29 let name = "world";
30 write!(s, "Hello, {name}!").unwrap();
31 assert_eq!(s.to_str(), Ok("Hello, world!"));
32 }
33
34 #[test]
test_io_write()35 fn test_io_write() {
36 let_cxx_string!(s = "");
37 let mut reader: &[u8] = b"Hello, world!";
38
39 std::io::copy(&mut reader, &mut s).unwrap();
40 assert_eq!(s.to_str(), Ok("Hello, world!"));
41 }
42