Skip to content
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

[Feature request] allow to override default printer #637

Closed
wahtique opened this issue Mar 22, 2023 · 1 comment
Closed

[Feature request] allow to override default printer #637

wahtique opened this issue Mar 22, 2023 · 1 comment

Comments

@wahtique
Copy link
Contributor

wahtique commented Mar 22, 2023

Hi !

I am confronted with a case where the default diff printer for iterable is less than helpful. Specifically, I have a case class ( a product ) wrapping a ByteVector ( an iterable ). When comparing two instances, the resulting diff look like this :

image

which is not very helpful as I do not actually want to compar byte by byte. The root cause seem to be

Rough expected behaviour would be :

//> using scala "3.2.2"
//> using dep  "org.scodec::scodec-bits:1.1.37"

import scodec.bits.ByteVector

final case class Wrapped(bv: ByteVector) {
  val stringValue: String = s"0x${bv.toHex}"
  override def toString: String = stringValue
}
  • When I compare two instances
//> using dep "org.scalameta::munit0.7.29"

import munit.FunSuite

class Example extends FunSuite {
  test("This will fail") {
    val a = Wrapped(ByteVector.fromValidHex("0x1")
    val b = Wrapped(ByteVector.fromValidHex("0x2")
    assertEquals(a, b)
  }
}
  • Then the diff should be
- Wrapped(0x1)
+ Wrapped(0x2)

Would it be possible to :

  • use traits instead of an object for printers so that users could override them when needed ?
  • use implicits for printers to allow more fine grained control over diffs for specific types ?
@wahtique
Copy link
Contributor Author

Nvm foud the custom printer param :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant