//! Tests for debug pretty printing. use core::fmt; use indextree::{Arena, NodeId}; #[derive(Clone)] struct Label(Vec); impl fmt::Debug for Label { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Use `Vec`'s debug formatting. self.0.fmt(f) } } impl fmt::Display for Label { // `1/2/3` for normal formatting, and `1 -> 2 -> 3` for alternate formatting. #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut iter = self.0.iter(); match iter.next() { Some(v) => write!(f, "{}", v)?, None => return write!(f, "root"), } if f.alternate() { iter.try_for_each(|v| write!(f, " -> {}", v)) } else { iter.try_for_each(|v| write!(f, "/{}", v)) } } } macro_rules! label { ($($tt:tt)*) => { Label(vec![$($tt)*]) } } /// Returns the sample tree and the root node ID. fn sample_tree() -> (Arena