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