diff options
| author | Andreas Grois <andi@grois.info> | 2023-03-20 23:27:45 +0100 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2023-03-20 23:27:45 +0100 |
| commit | 22154f14dd11f45230491cf0e93038ccfee8c85a (patch) | |
| tree | 76bc88f2afd4736d4d4d8f50174dd05acd3b9822 /tests | |
| parent | bb7719d6d050d7bf957f0df7a78e6c74b1c9615b (diff) | |
Partial support for multiple generic parameters.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/multiple_generics.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/multiple_generics.rs b/tests/multiple_generics.rs new file mode 100644 index 0000000..ce13414 --- /dev/null +++ b/tests/multiple_generics.rs @@ -0,0 +1,65 @@ +//! Tests if multiple generic parameters work, for the case that lifetimes are independent of mapping functions. +//! For simplicity, it just creates a FreeResult + +use higher_free_macro::free; +use higher::{Functor, Bind, Apply}; + +free!(FreeResult<O,E>, Result<FreeResult<O,E>,E>); + +#[test] +fn test_multiple_generics(){ + let m : FreeResult<_, String> = FreeResult::lift_f(Ok(37u32)); + let m = m.fmap(|x| x*2); + let m = m.bind(|x| FreeResult::Free(Box::new(Ok(FreeResult::Pure(x))))); + let f = FreeResult::Pure((|x| x*3).into()); + let m = m.apply(f); + match m { + FreeResult::Free(b) => { + match *b { + Ok(f) => { + match f { + FreeResult::Free(b) => { + match *b { + Ok(f) => { + match f{ + FreeResult::Pure(x) => assert_eq!(x, 37*6), + _ => unreachable!() + } + } + _ => unreachable!() + } + }, + _ => unreachable!() + } + } + _ => unreachable!() + } + } + _ => unreachable!() + } +} + +#[test] +fn test_multiple_generics2(){ + let m : FreeResult<_, String> = FreeResult::lift_f(Ok(37u32)); + let m = m.bind(|_| FreeResult::<u32, _>::lift_f(Err("An early out.".to_owned()))); + match m{ + FreeResult::Free(m) => { + match &*m { + Ok(m) => { + match m{ + FreeResult::Free(m) => { + match &**m { + Err(e) => assert_eq!(e, "An early out."), + _ => unreachable!() + } + } + _ => unreachable!() + } + }, + _ => unreachable!() + } + }, + _ => unreachable!() + } +}
\ No newline at end of file |
