Skip to content

Commit

Permalink
!fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Sep 13, 2023
1 parent cb20192 commit fd39adf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eyeball-im-util/src/vector/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
50 changes: 50 additions & 0 deletions eyeball-im-util/tests/it/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,53 @@ fn pop_front() {
drop(ob);
assert_closed!(sub);
}

#[test]
fn pop_back() {
let mut ob = ObservableVector::<usize>::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);
}

0 comments on commit fd39adf

Please sign in to comment.