Repository navigation
Improve diff rendering with multi-line show instance - #245
Merged
Merged
Conversation
zainab-ali
force-pushed
the
multi-line-show
branch
from
November 6, 2025 16:45
60eee26 to
03ba697
Compare
zainab-ali
commented
Nov 6, 2025
| @@ -0,0 +1,6 @@ | |||
| package weaver | |||
|
|
|||
| object ScalaCompat { | |||
Collaborator
Author
There was a problem hiding this comment.
These are only used in tests. We could move them to the test folder and define a test -> test relationship in SBT, but this would be best left to a different PR.
zainab-ali
commented
Nov 6, 2025
| private val comma: String = "," | ||
| private val indentStep = 1 | ||
|
|
||
| private[weaver] def show[A]: Show[A] = (a: A) => { |
Collaborator
Author
There was a problem hiding this comment.
This code uses explicit recursion and string builders, so is non-idiomatic for the weaver codebase.
However, I don't think we'll need to modify it much going forwards. If users have edge cases, they can support them with their own Show instances.
Collaborator
There was a problem hiding this comment.
I'm perfectly happy with String builders to be honest.
zainab-ali
commented
Nov 6, 2025
| """- (same with default show) 0ms | ||
| Values not equal: (src/main/DogFoodTests.scala:5) | ||
|
|
||
| => Diff (- obtained, + expected) |
Collaborator
Author
There was a problem hiding this comment.
Scala 2.12 doesn't support field names, hence this test is different for different Scala versions.
Baccata
reviewed
Nov 7, 2025
| private[weaver] def productElementNames(p: Product): Iterator[String] = | ||
| p.productElementNames | ||
| private[weaver] def collectionClassName(i: Iterable[_]): String = i | ||
| .asInstanceOf[{ def collectionClassName: String }].collectionClassName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation of
Comparisonforexpect.sameandexpect.eqluses a defaultShow.fromToStringinstance.This prints the obtained or expected values on a single line. The Myers diff algorithm works on multi-line strings, not one-line strings, so the diff is hard to read.
This PR adapts munit's multi-line string printing logic to create a better default show instance.
Before
Running the test in:
After