summaryrefslogtreecommitdiffstats
path: root/vendor/cxx/tests/cxx_string.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/cxx/tests/cxx_string.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/cxx/tests/cxx_string.rs')
-rw-r--r--vendor/cxx/tests/cxx_string.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/cxx/tests/cxx_string.rs b/vendor/cxx/tests/cxx_string.rs
new file mode 100644
index 000000000..349a4e1f1
--- /dev/null
+++ b/vendor/cxx/tests/cxx_string.rs
@@ -0,0 +1,41 @@
+use cxx::{let_cxx_string, CxxString};
+use std::fmt::Write as _;
+
+#[test]
+fn test_async_cxx_string() {
+ async fn f() {
+ let_cxx_string!(s = "...");
+
+ async fn g(_: &CxxString) {}
+ g(&s).await;
+ }
+
+ // https://github.com/dtolnay/cxx/issues/693
+ fn assert_send(_: impl Send) {}
+ assert_send(f());
+}
+
+#[test]
+fn test_debug() {
+ let_cxx_string!(s = "x\"y\'z");
+
+ assert_eq!(format!("{:?}", s), r#""x\"y'z""#);
+}
+
+#[test]
+fn test_fmt_write() {
+ let_cxx_string!(s = "");
+
+ let name = "world";
+ write!(s, "Hello, {name}!").unwrap();
+ assert_eq!(s.to_str(), Ok("Hello, world!"));
+}
+
+#[test]
+fn test_io_write() {
+ let_cxx_string!(s = "");
+ let mut reader: &[u8] = b"Hello, world!";
+
+ std::io::copy(&mut reader, &mut s).unwrap();
+ assert_eq!(s.to_str(), Ok("Hello, world!"));
+}