From f86deef5b6059b9a0a76d9f0dafb95ced85f7449 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Fri, 6 Apr 2018 15:02:21 +0200 Subject: Add Cell::update --- src/libcore/tests/cell.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libcore/tests') diff --git a/src/libcore/tests/cell.rs b/src/libcore/tests/cell.rs index cc0ef6a6f17..962fb2f0e02 100644 --- a/src/libcore/tests/cell.rs +++ b/src/libcore/tests/cell.rs @@ -26,6 +26,17 @@ fn smoketest_cell() { assert!(y.get() == (30, 40)); } +#[test] +fn cell_update() { + let x = Cell::new(10); + + assert_eq!(x.update(|x| x + 5), 15); + assert_eq!(x.get(), 15); + + assert_eq!(x.update(|x| x / 3), 5); + assert_eq!(x.get(), 5); +} + #[test] fn cell_has_sensible_show() { let x = Cell::new("foo bar"); -- cgit 1.4.1-3-g733a5