From 3d8b58202d031d5995d6f323c146be417e996ae4 Mon Sep 17 00:00:00 2001 From: annieversary Date: Wed, 17 Nov 2021 16:39:51 +0000 Subject: [PATCH] add test --- src/lenses/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lenses/mod.rs b/src/lenses/mod.rs index 42742b5..fa0308e 100644 --- a/src/lenses/mod.rs +++ b/src/lenses/mod.rs @@ -186,6 +186,20 @@ mod tests { assert_eq!(l(hello, |v| v + 1), Hello { hey: 9 }); } + #[test] + fn can_make_lens_with_ref_for_field() { + // making a lens + let l = crate::field_lens_with_ref!(Hello, hey); + + let hello = Hello { hey: 8 }; + // as ref + assert_eq!(l(&hello), 8); + // as move + assert_eq!(l(hello.clone()), 8); + + assert_eq!(l(hello, |v| v + 1), Hello { hey: 9 }); + } + #[test] fn can_make_lens_out_of_funcs() { // making a lens