1 #![allow(
2     clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/12257
3     clippy::items_after_statements,
4     clippy::uninlined_format_args,
5     clippy::unused_async
6 )]
7 
8 use cxx::{let_cxx_string, CxxString};
9 use std::fmt::Write as _;
10 
11 #[test]
test_async_cxx_string()12 fn test_async_cxx_string() {
13     async fn f() {
14         let_cxx_string!(s = "...");
15 
16         async fn g(_: &CxxString) {}
17         g(&s).await;
18     }
19 
20     // https://github.com/dtolnay/cxx/issues/693
21     fn assert_send(_: impl Send) {}
22     assert_send(f());
23 }
24 
25 #[test]
test_display()26 fn test_display() {
27     let_cxx_string!(s = b"w\"x\'y\xF1\x80\xF1\x80z");
28 
29     assert_eq!(format!("{}", s), "w\"x'y\u{fffd}\u{fffd}z");
30 }
31 
32 #[test]
test_debug()33 fn test_debug() {
34     let_cxx_string!(s = b"w\"x\'y\xF1\x80z");
35 
36     assert_eq!(format!("{:?}", s), r#""w\"x'y\xf1\x80z""#);
37 }
38 
39 #[test]
test_fmt_write()40 fn test_fmt_write() {
41     let_cxx_string!(s = "");
42 
43     let name = "world";
44     write!(s, "Hello, {name}!").unwrap();
45     assert_eq!(s.to_str(), Ok("Hello, world!"));
46 }
47 
48 #[test]
test_io_write()49 fn test_io_write() {
50     let_cxx_string!(s = "");
51     let mut reader: &[u8] = b"Hello, world!";
52 
53     std::io::copy(&mut reader, &mut s).unwrap();
54     assert_eq!(s.to_str(), Ok("Hello, world!"));
55 }
56