Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: assert-rs/snapbox
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: snapbox-v0.6.4
Choose a base ref
...
head repository: assert-rs/snapbox
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: snapbox-v0.6.5
Choose a head ref
  • 8 commits
  • 8 files changed
  • 1 contributor

Commits on May 27, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8bcc9b0 View commit details
  2. Copy the full SHA
    86a217c View commit details
  3. Copy the full SHA
    b4155bd View commit details
  4. Copy the full SHA
    7773f56 View commit details
  5. fix(filter): Normalize without consideration for TermSvg headers

    epage committed May 27, 2024
    Copy the full SHA
    e607393 View commit details
  6. Merge pull request #336 from epage/term

    fix(filter): Normalize without consideration for TermSvg headers
    epage authored May 27, 2024
    Copy the full SHA
    58f2474 View commit details
  7. docs: Update changelog

    epage committed May 27, 2024
    Copy the full SHA
    fa9e0c1 View commit details
  8. chore: Release

    epage committed May 27, 2024
    Copy the full SHA
    7d9cec1 View commit details
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion crates/snapbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- next-header -->
## [Unreleased] - ReleaseDate

## [0.6.5] - 2024-05-27

### Fixes

- Don't stop `.term.svg` redactions just because the document widths are different

## [0.6.4] - 2024-05-25

### Fixes
@@ -418,7 +424,8 @@ Other
## [0.1.0] - 2021-12-28

<!-- next-url -->
[Unreleased]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.4...HEAD
[Unreleased]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.5...HEAD
[0.6.5]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.4...snapbox-v0.6.5
[0.6.4]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.3...snapbox-v0.6.4
[0.6.3]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.2...snapbox-v0.6.3
[0.6.2]: https://github.com/assert-rs/trycmd/compare/snapbox-v0.6.1...snapbox-v0.6.2
2 changes: 1 addition & 1 deletion crates/snapbox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "snapbox"
version = "0.6.4"
version = "0.6.5"
description = "Snapshot testing toolbox"
repository = "https://github.com/assert-rs/trycmd/"
homepage = "https://github.com/assert-rs/trycmd/tree/main/crates/snapbox"
18 changes: 13 additions & 5 deletions crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
@@ -634,7 +634,7 @@ impl Data {
#[cfg(feature = "json")]
DataInner::JsonLines(_) => None,
#[cfg(feature = "term-svg")]
DataInner::TermSvg(data) => text_elem(data),
DataInner::TermSvg(data) => term_svg_body(data),
}
}
}
@@ -674,8 +674,8 @@ impl PartialEq for Data {
#[cfg(feature = "term-svg")]
(DataInner::TermSvg(left), DataInner::TermSvg(right)) => {
// HACK: avoid including `width` and `height` in the comparison
let left = text_elem(left.as_str());
let right = text_elem(right.as_str());
let left = term_svg_body(left.as_str()).unwrap_or(left.as_str());
let right = term_svg_body(right.as_str()).unwrap_or(right.as_str());
left == right
}
(_, _) => false,
@@ -710,7 +710,13 @@ fn parse_jsonlines(text: &str) -> Result<Vec<serde_json::Value>, serde_json::Err
}

#[cfg(feature = "term-svg")]
fn text_elem(svg: &str) -> Option<&str> {
fn term_svg_body(svg: &str) -> Option<&str> {
let (_header, body, _footer) = split_term_svg(svg)?;
Some(body)
}

#[cfg(feature = "term-svg")]
pub(crate) fn split_term_svg(svg: &str) -> Option<(&str, &str, &str)> {
let open_elem_start_idx = svg.find("<text")?;
_ = svg[open_elem_start_idx..].find('>')?;
let open_elem_line_start_idx = svg[..open_elem_start_idx]
@@ -725,8 +731,10 @@ fn text_elem(svg: &str) -> Option<&str> {
.map(|idx| idx + close_elem_start_idx + 1)
.unwrap_or(svg.len());

let header = &svg[..open_elem_line_start_idx];
let body = &svg[open_elem_line_start_idx..close_elem_line_end_idx];
Some(body)
let footer = &svg[close_elem_line_end_idx..];
Some((header, body, footer))
}

impl Eq for Data {}
12 changes: 6 additions & 6 deletions crates/snapbox/src/data/tests.rs
Original file line number Diff line number Diff line change
@@ -216,14 +216,14 @@ fn json_to_text_coerce_equals_render() {
}

#[cfg(feature = "term-svg")]
mod text_elem {
mod term_svg_body {
use super::super::*;

#[test]
fn empty() {
let input = "";
let expected = None;
let actual = text_elem(input);
let actual = term_svg_body(input);
assert_eq!(expected, actual);
}

@@ -233,7 +233,7 @@ mod text_elem {
</text>
world!";
let expected = None;
let actual = text_elem(input);
let actual = term_svg_body(input);
assert_eq!(expected, actual);
}

@@ -244,7 +244,7 @@ Hello
<text
world!";
let expected = None;
let actual = text_elem(input);
let actual = term_svg_body(input);
assert_eq!(expected, actual);
}

@@ -262,7 +262,7 @@ world
</text>
",
);
let actual = text_elem(input);
let actual = term_svg_body(input);
assert_eq!(expected, actual);
}

@@ -276,7 +276,7 @@ world";
"<text>
world",
);
let actual = text_elem(input);
let actual = term_svg_body(input);
assert_eq!(expected, actual);
}
}
102 changes: 54 additions & 48 deletions crates/snapbox/src/filter/pattern.rs
Original file line number Diff line number Diff line change
@@ -80,10 +80,10 @@ impl Default for NormalizeToExpected<'_> {
fn normalize_data_to_unordered(actual: Data, expected: &Data) -> Data {
let source = actual.source;
let filters = actual.filters;
let inner = match actual.inner {
DataInner::Error(err) => DataInner::Error(err),
DataInner::Binary(bin) => DataInner::Binary(bin),
DataInner::Text(text) => {
let inner = match (actual.inner, &expected.inner) {
(DataInner::Error(err), _) => DataInner::Error(err),
(DataInner::Binary(bin), _) => DataInner::Binary(bin),
(DataInner::Text(text), _) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_unordered(&text, &pattern);
DataInner::Text(lines)
@@ -92,30 +92,32 @@ fn normalize_data_to_unordered(actual: Data, expected: &Data) -> Data {
}
}
#[cfg(feature = "json")]
DataInner::Json(value) => {
(DataInner::Json(value), DataInner::Json(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_unordered(&mut value, exp);
}
normalize_value_to_unordered(&mut value, exp);
DataInner::Json(value)
}
#[cfg(feature = "json")]
DataInner::JsonLines(value) => {
(DataInner::JsonLines(value), DataInner::JsonLines(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_unordered(&mut value, exp);
}
normalize_value_to_unordered(&mut value, exp);
DataInner::JsonLines(value)
}
#[cfg(feature = "term-svg")]
DataInner::TermSvg(text) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_unordered(&text, &pattern);
DataInner::TermSvg(lines)
(DataInner::TermSvg(text), DataInner::TermSvg(exp)) => {
if let (Some((header, body, footer)), Some((_, exp, _))) = (
crate::data::split_term_svg(&text),
crate::data::split_term_svg(exp),
) {
let lines = normalize_str_to_unordered(body, exp);
DataInner::TermSvg(format!("{header}{lines}{footer}"))
} else {
DataInner::TermSvg(text)
}
}
// reachable if more than one structured data format is enabled
#[allow(unreachable_patterns)]
(inner, _) => inner,
};
Data {
inner,
@@ -208,10 +210,10 @@ fn normalize_data_to_unordered_redactions(
) -> Data {
let source = actual.source;
let filters = actual.filters;
let inner = match actual.inner {
DataInner::Error(err) => DataInner::Error(err),
DataInner::Binary(bin) => DataInner::Binary(bin),
DataInner::Text(text) => {
let inner = match (actual.inner, &expected.inner) {
(DataInner::Error(err), _) => DataInner::Error(err),
(DataInner::Binary(bin), _) => DataInner::Binary(bin),
(DataInner::Text(text), _) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_unordered_redactions(&text, &pattern, substitutions);
DataInner::Text(lines)
@@ -220,30 +222,32 @@ fn normalize_data_to_unordered_redactions(
}
}
#[cfg(feature = "json")]
DataInner::Json(value) => {
(DataInner::Json(value), DataInner::Json(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_unordered_redactions(&mut value, exp, substitutions);
}
normalize_value_to_unordered_redactions(&mut value, exp, substitutions);
DataInner::Json(value)
}
#[cfg(feature = "json")]
DataInner::JsonLines(value) => {
(DataInner::JsonLines(value), DataInner::JsonLines(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_unordered_redactions(&mut value, exp, substitutions);
}
normalize_value_to_unordered_redactions(&mut value, exp, substitutions);
DataInner::JsonLines(value)
}
#[cfg(feature = "term-svg")]
DataInner::TermSvg(text) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_unordered_redactions(&text, &pattern, substitutions);
DataInner::TermSvg(lines)
(DataInner::TermSvg(text), DataInner::TermSvg(exp)) => {
if let (Some((header, body, footer)), Some((_, exp, _))) = (
crate::data::split_term_svg(&text),
crate::data::split_term_svg(exp),
) {
let lines = normalize_str_to_unordered_redactions(body, exp, substitutions);
DataInner::TermSvg(format!("{header}{lines}{footer}"))
} else {
DataInner::TermSvg(text)
}
}
// reachable if more than one structured data format is enabled
#[allow(unreachable_patterns)]
(inner, _) => inner,
};
Data {
inner,
@@ -369,10 +373,10 @@ fn normalize_data_to_redactions(
) -> Data {
let source = actual.source;
let filters = actual.filters;
let inner = match actual.inner {
DataInner::Error(err) => DataInner::Error(err),
DataInner::Binary(bin) => DataInner::Binary(bin),
DataInner::Text(text) => {
let inner = match (actual.inner, &expected.inner) {
(DataInner::Error(err), _) => DataInner::Error(err),
(DataInner::Binary(bin), _) => DataInner::Binary(bin),
(DataInner::Text(text), _) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_redactions(&text, &pattern, substitutions);
DataInner::Text(lines)
@@ -381,30 +385,32 @@ fn normalize_data_to_redactions(
}
}
#[cfg(feature = "json")]
DataInner::Json(value) => {
(DataInner::Json(value), DataInner::Json(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_redactions(&mut value, exp, substitutions);
}
normalize_value_to_redactions(&mut value, exp, substitutions);
DataInner::Json(value)
}
#[cfg(feature = "json")]
DataInner::JsonLines(value) => {
(DataInner::JsonLines(value), DataInner::JsonLines(exp)) => {
let mut value = value;
if let DataInner::Json(exp) = &expected.inner {
normalize_value_to_redactions(&mut value, exp, substitutions);
}
normalize_value_to_redactions(&mut value, exp, substitutions);
DataInner::JsonLines(value)
}
#[cfg(feature = "term-svg")]
DataInner::TermSvg(text) => {
if let Some(pattern) = expected.render() {
let lines = normalize_str_to_redactions(&text, &pattern, substitutions);
DataInner::TermSvg(lines)
(DataInner::TermSvg(text), DataInner::TermSvg(exp)) => {
if let (Some((header, body, footer)), Some((_, exp, _))) = (
crate::data::split_term_svg(&text),
crate::data::split_term_svg(exp),
) {
let lines = normalize_str_to_redactions(body, exp, substitutions);
DataInner::TermSvg(format!("{header}{lines}{footer}"))
} else {
DataInner::TermSvg(text)
}
}
// reachable if more than one structured data format is enabled
#[allow(unreachable_patterns)]
(inner, _) => inner,
};
Data {
inner,
2 changes: 1 addition & 1 deletion crates/trycmd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ required-features = ["schema"]

[dependencies]
automod = "1.0.14"
snapbox = { path = "../snapbox", version = "0.6.4", default-features = false, features = ["cmd"] }
snapbox = { path = "../snapbox", version = "0.6.5", default-features = false, features = ["cmd"] }
anstream = { version = "0.6.7", optional = true }

glob = "0.3.0"
2 changes: 1 addition & 1 deletion crates/tryfn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -35,6 +35,6 @@ color = ["snapbox/color"]
color-auto = ["snapbox/color-auto"]

[dependencies]
snapbox = { path = "../snapbox", version = "0.6.4", default-features = false }
snapbox = { path = "../snapbox", version = "0.6.5", default-features = false }
libtest-mimic = "0.7.0"
ignore = "0.4"