]> git.proxmox.com Git - rustc.git/blob - vendor/camino/src/tests.rs
New upstream version 1.71.1+dfsg1
[rustc.git] / vendor / camino / src / tests.rs
1 // Copyright (c) The camino Contributors
2 // SPDX-License-Identifier: MIT OR Apache-2.0
3
4 // Test that all required impls exist.
5
6 use crate::{Utf8Path, Utf8PathBuf};
7 use std::{
8 borrow::Cow,
9 path::{Path, PathBuf},
10 rc::Rc,
11 sync::Arc,
12 };
13
14 macro_rules! all_into {
15 ($t:ty, $x:ident) => {
16 test_into::<$t, Utf8PathBuf>($x.clone());
17 test_into::<$t, Box<Utf8Path>>($x.clone());
18 test_into::<$t, Arc<Utf8Path>>($x.clone());
19 test_into::<$t, Rc<Utf8Path>>($x.clone());
20 test_into::<$t, Cow<'_, Utf8Path>>($x.clone());
21 test_into::<$t, PathBuf>($x.clone());
22 test_into::<$t, Box<Path>>($x.clone());
23 test_into::<$t, Arc<Path>>($x.clone());
24 test_into::<$t, Rc<Path>>($x.clone());
25 test_into::<$t, Cow<'_, Path>>($x.clone());
26 };
27 }
28
29 #[test]
30 fn test_borrowed_into() {
31 let utf8_path = Utf8Path::new("test/path");
32 all_into!(&Utf8Path, utf8_path);
33 }
34
35 #[test]
36 fn test_owned_into() {
37 let utf8_path_buf = Utf8PathBuf::from("test/path");
38 all_into!(Utf8PathBuf, utf8_path_buf);
39 }
40
41 fn test_into<T, U>(orig: T)
42 where
43 T: Into<U>,
44 {
45 let _ = orig.into();
46 }
47
48 #[cfg(path_buf_deref_mut)]
49 #[test]
50 fn test_deref_mut() {
51 // This test is mostly for miri.
52 let mut path_buf = Utf8PathBuf::from("foobar");
53 let _: &mut Utf8Path = &mut path_buf;
54 }