]> git.proxmox.com Git - rustc.git/blob - vendor/packed_simd_2/src/api/fmt/debug.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / vendor / packed_simd_2 / src / api / fmt / debug.rs
1 //! Implement debug formatting
2
3 macro_rules! impl_fmt_debug_tests {
4 ([$elem_ty:ty; $elem_count:expr]: $id:ident | $test_tt:tt) => {
5 test_if! {
6 $test_tt:
7 paste::item! {
8 pub mod [<$id _fmt_debug>] {
9 use super::*;
10 #[cfg_attr(not(target_arch = "wasm32"), test)]
11 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
12 fn debug() {
13 use arrayvec::{ArrayString,ArrayVec};
14 type TinyString = ArrayString<[u8; 512]>;
15
16 use crate::fmt::Write;
17 let v = $id::default();
18 let mut s = TinyString::new();
19 write!(&mut s, "{:?}", v).unwrap();
20
21 let mut beg = TinyString::new();
22 write!(&mut beg, "{}(", stringify!($id)).unwrap();
23 assert!(s.starts_with(beg.as_str()));
24 assert!(s.ends_with(")"));
25 let s: ArrayVec<[TinyString; 64]>
26 = s.replace(beg.as_str(), "")
27 .replace(")", "").split(",")
28 .map(|v| TinyString::from(v.trim()).unwrap())
29 .collect();
30 assert_eq!(s.len(), $id::lanes());
31 for (index, ss) in s.into_iter().enumerate() {
32 let mut e = TinyString::new();
33 write!(&mut e, "{:?}", v.extract(index)).unwrap();
34 assert_eq!(ss, e);
35 }
36 }
37 }
38 }
39 }
40 };
41 }
42
43 macro_rules! impl_fmt_debug {
44 ([$elem_ty:ty; $elem_count:expr]: $id:ident | $test_tt:tt) => {
45 impl crate::fmt::Debug for $id {
46 #[allow(clippy::missing_inline_in_public_items)]
47 fn fmt(
48 &self, f: &mut crate::fmt::Formatter<'_>,
49 ) -> crate::fmt::Result {
50 write!(f, "{}(", stringify!($id))?;
51 for i in 0..$elem_count {
52 if i > 0 {
53 write!(f, ", ")?;
54 }
55 self.extract(i).fmt(f)?;
56 }
57 write!(f, ")")
58 }
59 }
60 impl_fmt_debug_tests!([$elem_ty; $elem_count]: $id | $test_tt);
61 };
62 }