Skip to content

Commit 22b729a

Browse files
test(interpreter): Improve focus of most of the snapshot tests
1 parent 4b5b6af commit 22b729a

24 files changed

+582
-980
lines changed

src/image/mod.rs

+47-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl From<u32> for Px {
4545
}
4646
}
4747

48-
#[derive(Debug, Clone, Copy)]
48+
#[derive(Debug, Clone, Copy, PartialEq)]
4949
pub enum ImageSize {
5050
PxWidth(Px),
5151
PxHeight(Px),
@@ -61,7 +61,7 @@ impl ImageSize {
6161
}
6262
}
6363

64-
#[derive(SmartDebug, Default, Clone)]
64+
#[derive(SmartDebug, Default, Clone, PartialEq)]
6565
pub struct ImageData {
6666
#[debug(wrapper = DebugBytesPrefix)]
6767
lz4_blob: Vec<u8>,
@@ -113,6 +113,8 @@ impl ImageData {
113113

114114
#[derive(SmartDebug, Default)]
115115
pub struct Image {
116+
// TODO: Instead of sharing a mutex with the image loading thread change this to hold a oneshot
117+
// channel that stores the image?
116118
#[debug(skip_fn = debug_ignore_image_data)]
117119
pub image_data: Arc<Mutex<Option<ImageData>>>,
118120
#[debug(skip_fn = Option::is_none, wrapper = DebugInline)]
@@ -127,6 +129,49 @@ pub struct Image {
127129
pub hidpi_scale: f32,
128130
}
129131

132+
// NOTE: Internally performs some expensive operations. Avoid calling often
133+
// TODO: can we deprecate this and then `allow` specific usages of it due to ^^?
134+
impl PartialEq for Image {
135+
fn eq(&self, other: &Self) -> bool {
136+
let Self {
137+
image_data,
138+
is_aligned,
139+
size,
140+
bind_group,
141+
is_link,
142+
hidpi_scale,
143+
} = self;
144+
let Self {
145+
image_data: other_image_data,
146+
is_aligned: other_is_aligned,
147+
size: other_size,
148+
bind_group: other_bind_group,
149+
is_link: other_is_link,
150+
hidpi_scale: other_hidpi_scale,
151+
} = other;
152+
153+
let clone_image_data = |shared_image: &Mutex<Option<_>>| {
154+
shared_image
155+
.lock()
156+
.unwrap_or_else(|err| err.into_inner())
157+
.to_owned()
158+
};
159+
let image_data = clone_image_data(image_data);
160+
let other_image_data = clone_image_data(other_image_data);
161+
162+
let some_bind_group = bind_group.is_some();
163+
let some_other_bind_group = other_bind_group.is_some();
164+
let bind_group_variant_matches = some_bind_group ^ !some_other_bind_group;
165+
166+
image_data == other_image_data
167+
&& is_aligned == other_is_aligned
168+
&& size == other_size
169+
&& is_link == other_is_link
170+
&& hidpi_scale == other_hidpi_scale
171+
&& bind_group_variant_matches
172+
}
173+
}
174+
130175
fn debug_ignore_image_data(mutex: &Mutex<Option<ImageData>>) -> bool {
131176
match mutex.lock() {
132177
Ok(data) => data.is_none(),

src/interpreter/snapshots/inlyne__interpreter__tests__bare_link_gets_autolinked.snap

-56
This file was deleted.

src/interpreter/snapshots/inlyne__interpreter__tests__blockquote.snap

-27
This file was deleted.

src/interpreter/snapshots/inlyne__interpreter__tests__centered_image_with_size_align_and_link.snap

-32
This file was deleted.

src/interpreter/snapshots/inlyne__interpreter__tests__code_block_bg_color.snap

-76
This file was deleted.

src/interpreter/snapshots/inlyne__interpreter__tests__handles_comma_in_info_str.snap

-54
This file was deleted.

src/interpreter/snapshots/inlyne__interpreter__tests__horizontal_ruler.snap

-25
This file was deleted.

0 commit comments

Comments
 (0)