Skip to content

Commit

Permalink
Fixes #100
Browse files Browse the repository at this point in the history
When a key in the `actual` results in a noop and its key index in the `expected`
is less than its index in the `actual`, the diff would display a `delete` for
this key along with a noop. For instance, in the diff below we have
`-   profile_background_tile: false,` and `    profile_background_tile: false`.

```
Differing hashes.

Expected: { created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, media_count: 51044, statuses_count: 273860, contributors_enabled: false, profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_color: "FFF1E0", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", listed_count: 37009, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" }
  Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_background_tile: false }

Diff:

  {
    listed_count: 37009,
    created_at: "Tue Jan 13 19:28:24 +0000 2009",
    favourites_count: 38,
-   geo_enabled: false,
-   verified: true,
+   utc_offset: nil,
    statuses_count: 273860,
    media_count: 51044,
    contributors_enabled: false,
+   is_translator: false,
+   is_translation_enabled: false,
    profile_background_color: "FFF1E0",
    profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
-   profile_background_tile: false,
-   profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
    profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
    profile_background_tile: false
  }
```
  • Loading branch information
groyoh authored and mcmire committed May 6, 2021
1 parent 2bce2b1 commit 5872288
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/super_diff/operation_tree_builders/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def unary_operations_using_variant_of_patience_algorithm
ev2, av2 = expected[ek], actual[ek]

if (
(!actual.include?(ek) || ev != av2) &&
(!actual.include?(ek) || ev2 != av2) &&
operations.none? { |operation|
[:delete, :noop].include?(operation.name) &&
operation.key == ek
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/equality_matchers/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@
is_translation_enabled: false,
profile_background_color: "FFF1E0",
profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
profile_background_tile: false,
profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
profile_background_tile: false,
}
)

Expand All @@ -1177,7 +1177,7 @@
#{
colored do
expected_line %(Expected: { created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, media_count: 51044, statuses_count: 273860, contributors_enabled: false, profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_color: "FFF1E0", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", listed_count: 37009, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
actual_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
actual_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592", profile_background_tile: false })
end
}
Expand All @@ -1199,9 +1199,9 @@
actual_line %(+ is_translation_enabled: false,)
plain_line %( profile_background_color: "FFF1E0",)
plain_line %( profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",)
plain_line %( profile_background_tile: false,)
expected_line %(- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592")
plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",)
plain_line %( profile_background_tile: false)
plain_line %( })
end
}
Expand Down

0 comments on commit 5872288

Please sign in to comment.