From fd39adf1b48c82b11f06d32676a002bf9f2b58c5 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 13 Sep 2023 21:33:00 +0200 Subject: [PATCH] !fixup --- eyeball-im-util/src/vector/limit.rs | 2 +- eyeball-im-util/tests/it/limit.rs | 50 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/eyeball-im-util/src/vector/limit.rs b/eyeball-im-util/src/vector/limit.rs index 3476746..4f842ed 100644 --- a/eyeball-im-util/src/vector/limit.rs +++ b/eyeball-im-util/src/vector/limit.rs @@ -184,7 +184,7 @@ where } } VectorDiff::PopBack => { - if is_full { + if length > limit { // Let's ignore the diff. } else { self.push_ready_value(VectorDiff::PopBack); diff --git a/eyeball-im-util/tests/it/limit.rs b/eyeball-im-util/tests/it/limit.rs index e7a26b6..b96203f 100644 --- a/eyeball-im-util/tests/it/limit.rs +++ b/eyeball-im-util/tests/it/limit.rs @@ -417,3 +417,53 @@ fn pop_front() { drop(ob); assert_closed!(sub); } + +#[test] +fn pop_back() { + let mut ob = ObservableVector::::new(); + let mut limit = Observable::new(0); + let mut sub = + DynamicLimit::new(ob.clone(), ob.subscribe().into_stream(), Observable::subscribe(&limit)); + + // Add 4 values. + ob.append(vector![10, 11, 12, 13]); + + // Set limit to 2. + Observable::set(&mut limit, 3); + + // Observe 2 values. + assert_next_eq!(sub, VectorDiff::Append { values: vector![10, 11, 12] }); + + // Remove 1 value. + ob.pop_back(); + + // Observe nothing. + assert_pending!(sub); + + // Remove 1 value. + ob.pop_back(); + + // Observe nothing. + assert_next_eq!(sub, VectorDiff::PopBack); + + // Remove 1 value. + ob.pop_back(); + + // Observe nothing. + assert_next_eq!(sub, VectorDiff::PopBack); + + // Check the content of the vector. + { + let expected = vector![10]; + assert_eq!(*ob, expected); + + Observable::set(&mut limit, 0); + assert_next_eq!(sub, VectorDiff::Truncate { length: 0 }); + + Observable::set(&mut limit, 42); + assert_next_eq!(sub, VectorDiff::Append { values: expected }); + } + + drop(ob); + assert_closed!(sub); +}