test: Add assert messages in the assert_timeline_stream macro.

This patch improves the `assert_timeline_stream` macro by adding a bunch
of assert messages in case it fails.
This commit is contained in:
Ivan Enderlin
2025-05-05 17:32:11 +02:00
parent 581d54f65f
commit eef99b2679

View File

@@ -86,7 +86,8 @@ macro_rules! assert_timeline_stream {
**value,
matrix_sdk_ui::timeline::TimelineItemKind::Virtual(
matrix_sdk_ui::timeline::VirtualTimelineItem::DateDivider(_)
)
),
"`--- date divider ---` has failed",
);
}
);
@@ -110,8 +111,13 @@ macro_rules! assert_timeline_stream {
assert_matches!(
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => {
assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id);
}
assert_eq!(
event_timeline_item.event_id().unwrap().as_str(),
$event_id,
concat!("`append ", $event_id, "` has failed: event ID does not match"),
);
},
concat!("`append ", $event_id, "` has failed: timeline item kind does not match"),
);
}
);
@@ -136,7 +142,8 @@ macro_rules! assert_timeline_stream {
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Virtual(
matrix_sdk_ui::timeline::VirtualTimelineItem::DateDivider(_)
) => {}
),
"`prepend --- date divider ---` has failed",
);
}
);
@@ -162,7 +169,8 @@ macro_rules! assert_timeline_stream {
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Virtual(
matrix_sdk_ui::timeline::VirtualTimelineItem::TimelineStart
) => {}
),
"`prepend --- timeline start ---` has failed",
);
}
);
@@ -186,8 +194,13 @@ macro_rules! assert_timeline_stream {
assert_matches!(
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => {
assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id);
}
assert_eq!(
event_timeline_item.event_id().unwrap().as_str(),
$event_id,
concat!("`prepend ", $event_id, "` has failed: event ID does not match"),
);
},
concat!("`prepend ", $event_id, "` has failed: timeline item kind does not match"),
);
}
);
@@ -211,8 +224,13 @@ macro_rules! assert_timeline_stream {
assert_matches!(
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => {
assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id);
}
assert_eq!(
event_timeline_item.event_id().unwrap().as_str(),
$event_id,
concat!("`insert [", $index, "] ", $event_id, "` has failed: event ID does not match"),
);
},
concat!("`insert [", $index, "] ", $event_id, "` has failed: timeline item kind does not match"),
);
}
);
@@ -236,8 +254,13 @@ macro_rules! assert_timeline_stream {
assert_matches!(
&**value,
matrix_sdk_ui::timeline::TimelineItemKind::Event(event_timeline_item) => {
assert_eq!(event_timeline_item.event_id().unwrap().as_str(), $event_id);
}
assert_eq!(
event_timeline_item.event_id().unwrap().as_str(),
$event_id,
concat!("`update [", $index, "] ", $event_id, "` has failed: event ID does not match"),
);
},
concat!("`update [", $index, "] ", $event_id, "` has failed: timeline item kind does not match"),
);
}
);
@@ -257,7 +280,8 @@ macro_rules! assert_timeline_stream {
{
assert_matches!(
$iterator .next(),
Some(eyeball_im::VectorDiff::Remove { index: $index })
Some(eyeball_im::VectorDiff::Remove { index: $index }),
concat!("`remove [", $index, "]` has failed"),
);
}
]
@@ -275,7 +299,8 @@ macro_rules! assert_timeline_stream {
{
assert_matches!(
$iterator .next(),
Some(eyeball_im::VectorDiff::Clear)
Some(eyeball_im::VectorDiff::Clear),
"clear has failed",
);
}
]
@@ -285,7 +310,9 @@ macro_rules! assert_timeline_stream {
( @_ [ $iterator:ident ] [] [ $( $accumulator:tt )* ] ) => {
$( $accumulator )*
assert!($iterator .next().is_none(), concat!(stringify!($iterator), " has not been entirely read"));
let next = $iterator .next();
assert!(next.is_none(), "`{}` has not been entirely read; received `{:?}`", stringify!( $iterator ), next);
};
( [ $stream:ident ] $( $all:tt )* ) => {