Skip to content

Commit bbee0ed

Browse files
committed
Refactor assert_rendered_output internals
Previously assert_rendered_output used String building to generate matching lines. While this works, it makes adding more dynamic pattern matching impossible. This updates those Strings into a set of LinePattern matchers, that can match dynamically, based on the type, instead of String comparisons. As well, previously, assert_rendered_output matched against the entire rendered output, including an often repeated header. This also provides a new mode for the macro, that will only render and match against the view body. This should allow assertions to be simplified in cases where the header values are not important.
1 parent 914f8f6 commit bbee0ed

File tree

7 files changed

+842
-454
lines changed

7 files changed

+842
-454
lines changed

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/view/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ readme = "README.md"
1515
name = "view"
1616

1717
[features]
18-
testutils = ["dep:bitflags"]
18+
testutils = ["dep:bitflags", "dep:iter_tools"]
1919

2020
[dependencies]
2121
anyhow = "1.0.72"
@@ -25,6 +25,7 @@ crossbeam-channel = "0.5.8"
2525
parking_lot = "0.12.1"
2626
unicode-segmentation = "1.10.1"
2727
unicode-width = "0.1.10"
28+
iter_tools = { version = "0.1.4", optional = true }
2829
xi-unicode = "0.3.0"
2930
girt-display = {version = "2.3.0", path = "../display"}
3031
girt-runtime = {version = "2.3.0", path = "../runtime"}

src/view/src/render_slice/tests.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
use display::DisplayColor;
22

33
use super::*;
4-
use crate::testutil::{_assert_rendered_output, render_view_line, AssertRenderOptions};
4+
use crate::testutil::{
5+
assert_rendered_output::_assert_rendered_output,
6+
render_view_line,
7+
AssertRenderOptions,
8+
ExactPattern,
9+
LinePattern,
10+
};
511

612
fn assert_rendered(render_slice: &RenderSlice, expected: &[&str]) {
713
let mut output = vec![];
@@ -48,10 +54,17 @@ fn assert_rendered(render_slice: &RenderSlice, expected: &[&str]) {
4854
}
4955
}
5056
}
57+
5158
_assert_rendered_output(
5259
AssertRenderOptions::default(),
5360
&output,
54-
&expected.iter().map(|s| String::from(*s)).collect::<Vec<String>>(),
61+
&expected
62+
.iter()
63+
.map(|s| {
64+
let pattern: Box<dyn LinePattern> = Box::new(ExactPattern::new(s));
65+
pattern
66+
})
67+
.collect::<Vec<Box<dyn LinePattern>>>(),
5568
);
5669
}
5770

0 commit comments

Comments
 (0)