#![allow(unused_parens)] use functor_derive::Functor; use std::any::{Any, TypeId}; #[test] fn mutual_recursion() { #[derive(Functor)] struct TypeA { b: Option>>, v: T, } #[derive(Functor)] struct TypeB { a: Option>>, } let x = TypeA { b: Some(Box::new(TypeB { a: Some(Box::new(TypeA { b: None, v: 42usize, })), })), v: 42usize, }; assert_eq!(x.fmap(|x| x as u64).type_id(), TypeId::of::>()); } #[test] fn single_recursion() { #[derive(Functor)] struct TypeA { b: Option>>, v: T, } let x = TypeA { b: Some(Box::new(TypeA { b: Some(Box::new(TypeA { b: None, v: 42usize, })), v: 42usize, })), v: 42usize, }; assert_eq!(x.fmap(|x| x as u64).type_id(), TypeId::of::>()); } #[test] fn recursion_swap() { #[derive(Functor)] struct TypeA { b: Option>>, v1: S, v2: T, } let x = TypeA { b: Some(Box::new(TypeA { b: None, v1: 40usize, v2: 41usize, })), v1: 42usize, v2: 43usize, }; assert_eq!( x.fmap(|x| x as u64).type_id(), TypeId::of::>() ); } #[test] fn recursion_swap_mutual() { #[derive(Functor)] struct TypeA { b: Option>>, v1: S, v2: T, } #[derive(Functor)] struct TypeB { b: Option>>, v1: S, v2: T, } let x = TypeA { b: Some(Box::new(TypeB { b: None, v1: 40usize, v2: 41usize, })), v1: 42usize, v2: 43usize, }; assert_eq!( x.fmap(|x| x as u64).type_id(), TypeId::of::>() ); }