-
-
Notifications
You must be signed in to change notification settings - Fork 13
Improve diff rendering with multi-line show instance #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
60eee26 to
03ba697
Compare
| @@ -0,0 +1,6 @@ | |||
| package weaver | |||
|
|
|||
| object ScalaCompat { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| private val comma: String = "," | ||
| private val indentStep = 1 | ||
|
|
||
| private[weaver] def show[A]: Show[A] = (a: A) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm perfectly happy with String builders to be honest.
| """- (same with default show) 0ms | ||
| Values not equal: (src/main/DogFoodTests.scala:5) | ||
| => Diff (- obtained, + expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scala 2.12 doesn't support field names, hence this test is different for different Scala versions.
| private[weaver] def productElementNames(p: Product): Iterator[String] = | ||
| p.productElementNames | ||
| private[weaver] def collectionClassName(i: Iterable[_]): String = i | ||
| .asInstanceOf[{ def collectionClassName: String }].collectionClassName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :D
Baccata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fantastic !
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