bizzabo / diff Goto Github PK
View Code? Open in Web Editor NEWVisually compare Scala data structures with out of the box support for arbitrary case classes.
License: Other
Visually compare Scala data structures with out of the box support for arbitrary case classes.
License: Other
Test with Array of bytes:
"diff Arrays of bytes" in {
case class CaseClassWithArrayBytes(id: String, hash: Option[Array[Byte]])
import ai.x.diff.DiffShow
import ai.x.diff.conversions._
println(
DiffShow.diff[CaseClassWithArrayBytes](
CaseClassWithArrayBytes("A", Some( Array[Byte](192.toByte, 168.toByte) )),
CaseClassWithArrayBytes("B", Some( Array[Byte](192.toByte, 168.toByte) ))
).toString
)
}
It prints the exception:
Different(CaseClassWithArrayBytes$3(
hash = Some(
java.lang.Exception: ERROR: Cannot find DiffShow[Array[byte]] to show values ([B@13a37e2a, [B@a50ae65)
at ai.x.diff.DiffShowInstancesLowPriority$$anon$4.diff(diff.scala:110)
at ai.x.diff.DiffShowInstancesLowPriority$$anon$4.diff(diff.scala:106)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at ai.x.diff.DiffShowInstances$$anon$5.diff(diff.scala:122)
at ai.x.diff.DiffShowInstances$$anon$5.diff(diff.scala:115)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowInstances$CaseClassDiffShow.diff(diff.scala:201)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$2.apply$mcV$sp(CompareDatasetsTest.scala:30)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$2.apply(CompareDatasetsTest.scala:24)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$2.apply(CompareDatasetsTest.scala:24)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.WordSpecLike$$anon$1.apply(WordSpecLike.scala:1078)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at com.dnb.optimus.prime.report.CompareDatasetsTest.withFixture(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$class.invokeWithFixture$1(WordSpecLike.scala:1075)
at org.scalatest.WordSpecLike$$anonfun$runTest$1.apply(WordSpecLike.scala:1088)
at org.scalatest.WordSpecLike$$anonfun$runTest$1.apply(WordSpecLike.scala:1088)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.WordSpecLike$class.runTest(WordSpecLike.scala:1088)
at com.dnb.optimus.prime.report.CompareDatasetsTest.runTest(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$$anonfun$runTests$1.apply(WordSpecLike.scala:1147)
at org.scalatest.WordSpecLike$$anonfun$runTests$1.apply(WordSpecLike.scala:1147)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:396)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:379)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
at org.scalatest.WordSpecLike$class.runTests(WordSpecLike.scala:1147)
at com.dnb.optimus.prime.report.CompareDatasetsTest.runTests(CompareDatasetsTest.scala:7)
at org.scalatest.Suite$class.run(Suite.scala:1147)
at com.dnb.optimus.prime.report.CompareDatasetsTest.org$scalatest$WordSpecLike$$super$run(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$$anonfun$run$1.apply(WordSpecLike.scala:1192)
at org.scalatest.WordSpecLike$$anonfun$run$1.apply(WordSpecLike.scala:1192)
at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
at org.scalatest.WordSpecLike$class.run(WordSpecLike.scala:1192)
at com.dnb.optimus.prime.report.CompareDatasetsTest.run(CompareDatasetsTest.scala:7)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1346)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1340)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1340)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1010)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1506)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
),
id = "A" -> "B"
))
Test with Array of Strings:
"diff Arrays of String" in {
case class CaseClassWithArrayStrings(id: String, hash: Option[Array[String]])
import ai.x.diff.DiffShow
import ai.x.diff.conversions._
println(
DiffShow.diff[CaseClassWithArrayStrings](
CaseClassWithArrayStrings("A", Some( Array[String]("A","B") )),
CaseClassWithArrayStrings("B", Some( Array[String]("A", "B") ))
).toString
)
}
Prints the exception:
Different(CaseClassWithArrayStrings$3(
hash = Some(
java.lang.Exception: ERROR: Cannot find DiffShow[Array[java.lang.String]] to show values ([Ljava.lang.String;@18324f97, [Ljava.lang.String;@64f555e7)
at ai.x.diff.DiffShowInstancesLowPriority$$anon$4.diff(diff.scala:110)
at ai.x.diff.DiffShowInstancesLowPriority$$anon$4.diff(diff.scala:106)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at ai.x.diff.DiffShowInstances$$anon$5.diff(diff.scala:122)
at ai.x.diff.DiffShowInstances$$anon$5.diff(diff.scala:115)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowInstances$CaseClassDiffShow.diff(diff.scala:201)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$3.apply$mcV$sp(CompareDatasetsTest.scala:43)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$3.apply(CompareDatasetsTest.scala:37)
at com.dnb.optimus.prime.report.CompareDatasetsTest$$anonfun$3.apply(CompareDatasetsTest.scala:37)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.WordSpecLike$$anon$1.apply(WordSpecLike.scala:1078)
at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
at com.dnb.optimus.prime.report.CompareDatasetsTest.withFixture(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$class.invokeWithFixture$1(WordSpecLike.scala:1075)
at org.scalatest.WordSpecLike$$anonfun$runTest$1.apply(WordSpecLike.scala:1088)
at org.scalatest.WordSpecLike$$anonfun$runTest$1.apply(WordSpecLike.scala:1088)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
at org.scalatest.WordSpecLike$class.runTest(WordSpecLike.scala:1088)
at com.dnb.optimus.prime.report.CompareDatasetsTest.runTest(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$$anonfun$runTests$1.apply(WordSpecLike.scala:1147)
at org.scalatest.WordSpecLike$$anonfun$runTests$1.apply(WordSpecLike.scala:1147)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:396)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:379)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
at org.scalatest.WordSpecLike$class.runTests(WordSpecLike.scala:1147)
at com.dnb.optimus.prime.report.CompareDatasetsTest.runTests(CompareDatasetsTest.scala:7)
at org.scalatest.Suite$class.run(Suite.scala:1147)
at com.dnb.optimus.prime.report.CompareDatasetsTest.org$scalatest$WordSpecLike$$super$run(CompareDatasetsTest.scala:7)
at org.scalatest.WordSpecLike$$anonfun$run$1.apply(WordSpecLike.scala:1192)
at org.scalatest.WordSpecLike$$anonfun$run$1.apply(WordSpecLike.scala:1192)
at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
at org.scalatest.WordSpecLike$class.run(WordSpecLike.scala:1192)
at com.dnb.optimus.prime.report.CompareDatasetsTest.run(CompareDatasetsTest.scala:7)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1346)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1340)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1340)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1010)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1506)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
at org.scalatest.tools.Runner$.run(Runner.scala:850)
at org.scalatest.tools.Runner.run(Runner.scala)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:131)
at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
),
id = "A" -> "B"
))
Hi,
Any chance for publishing a Scala 2.10 build of this library?
Thanks
Hi folks,
Will be there any release for scala 2.13?
Also, does anyone knows if there is any alternative for this repo? That has the same functionalities.
Best regards
Since 1.2.0 Scala 2.10 shows the following type error
Trying to annotate the type leads to a compiler crash. Working through all the places where the compiler show's errors in -Xprint:typer and filling them in didn't help. Here is my attempt: https://github.com/xdotai/diff/tree/2.10
If anyone finds a solution, please let me know.
The show() method in the map diff is broken. It always looks in the right map, but it is called once for elements only in the right map and once for elements only in the left map.
A quick fix is:
def show( keys: List[K] ) = keys.map( k => DiffShow.show( k ) -> DiffShow.show( left.getOrElse( k, right( k ) ) ) )
Now that Scala 2.12.0 has been released, would it be possible to release a build of diff 1.2.0 for it? Thanks!
scala> import ai.x.diff._
import ai.x.diff._
scala> case class Foo(i: Int, s: String)
defined class Foo
scala> case class Bar(d: Double, f: Foo)
defined class Bar
scala> val b1 = Bar(1.0,Foo(1,"test"))
b1: Bar = Bar(1.0,Foo(1,test))
scala> val b2 = Bar(2.0,Foo(1,"baz"))
b2: Bar = Bar(2.0,Foo(1,baz))
scala> DiffShow.diff(b1, b2)
java.lang.InternalError: Malformed class name
at java.lang.Class.getSimpleName(Class.java:1330)
at ai.x.diff.DiffShowInstances$CaseClassDiffShow.diff(diff.scala:207)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:99)
at ai.x.diff.DiffShowFields$$anon$3.diff(diff.scala:95)
at ai.x.diff.DiffShowInstances$CaseClassDiffShow.diff(diff.scala:201)
at ai.x.diff.DiffShow$.diff(diff.scala:64)
... 32 elided
scala>
Would it be possible to have a scalajs build? Then I can diff in the browser.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.