use crate::funcmap::{T1, T2}; use core::marker::PhantomData; use functor_derive::Functor; use std::cell::{Cell, RefCell, UnsafeCell}; use std::ops::ControlFlow; #[test] fn field_of_array_type_is_mapped() { #[derive(Functor, Debug, PartialEq)] struct Test([T; 2]); let src = Test([T1, T1]); let dst = src.fmap(|_| T2); assert_eq!(dst, Test([T2, T2])); } // todo: not implemented // #[test] // fn field_of_bound_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(Bound); // // let src = Test(Bound::Included(T1)); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(Bound::Included(T2))); // } #[test] fn field_of_cell_type_is_mapped() { #[derive(Functor, Debug, PartialEq)] struct Test(Cell); let src = Test(Cell::new(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(Cell::new(T2))); } #[test] fn field_of_control_flow_type_is_mapped_over_break() { #[derive(Functor, Debug, PartialEq)] struct Test(ControlFlow); let src = Test(ControlFlow::Break(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(ControlFlow::Break(T2))); } #[test] fn field_of_control_flow_type_is_mapped_over_continue() { #[derive(Functor, Debug, PartialEq)] struct Test(ControlFlow<(), T>); let src = Test(ControlFlow::Continue(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(ControlFlow::Continue(T2))); } #[test] fn field_of_option_type_is_mapped() { #[derive(Functor, Debug, PartialEq)] struct Test(Option); let src = Test(Some(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(Some(T2))); } // todo: not implemented // #[test] // fn field_of_option_into_iter_type_is_mapped() { // #[derive(Functor, Debug)] // struct Test(option::IntoIter); // // let src = Test(Some(T1).into_iter()); // let dst = src.fmap(|_| T2); // // assert_eq!(dst.0.collect::>(), vec![T2]); // } #[test] fn field_of_phantom_data_type_is_mapped() { #[derive(Functor, Debug, PartialEq)] struct Test(PhantomData); let src = Test(PhantomData::); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(PhantomData::)); } // todo: not implemented // #[test] // fn field_of_poll_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(Poll); // // let src = Test(Poll::Ready(T1)); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(Poll::Ready(T2))); // } // todo: not implemented // #[test] // fn field_of_range_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(Range); // // let src = Test(T1..T1); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(T2..T2)); // } // todo: not implemented // #[test] // fn field_of_range_from_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(RangeFrom); // // let src = Test(T1..); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(T2..)); // } // todo: not implemented // #[test] // fn field_of_range_inclusive_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(RangeInclusive); // // let src = Test(T1..=T1); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(T2..=T2)); // } // todo: not implemented // #[test] // fn field_of_range_to_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(RangeTo); // // let src = Test(..T1); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(..T2)); // } // todo: not implemented // #[test] // fn field_of_range_to_inclusive_type_is_mapped() { // #[derive(Functor, Debug, PartialEq)] // struct Test(RangeToInclusive); // // let src = Test(..=T1); // let dst = src.fmap(|_| T2); // // assert_eq!(dst, Test(..=T2)); // } #[test] fn field_of_ref_cell_type_is_mapped() { #[derive(Functor, Debug, PartialEq)] struct Test(RefCell); let src = Test(RefCell::new(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(RefCell::new(T2))); } #[test] fn field_of_result_type_is_mapped_over_value() { #[derive(Functor, Debug, PartialEq)] struct Test(Result); let src = Test(Ok(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(Ok(T2))); } #[test] fn field_of_result_type_is_mapped_over_error() { #[derive(Functor, Debug, PartialEq)] struct Test(Result<(), T>); let src = Test(Err(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst, Test(Err(T2))); } // todo: not implemented // #[test] // fn field_of_result_into_iter_type_is_mapped_over_value() { // #[derive(Functor, Debug)] // struct Test(result::IntoIter); // // let src = Test(Result::<_, ()>::Ok(T1).into_iter()); // let dst = src.fmap(|_| T2); // // assert_eq!(dst.0.collect::>(), vec![T2]); // } #[test] fn field_of_unsafe_cell_type_is_mapped() { #[derive(Functor, Debug)] struct Test(UnsafeCell); let src = Test(UnsafeCell::new(T1)); let dst = src.fmap(|_| T2); assert_eq!(dst.0.into_inner(), T2); }