Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Jul 16, 2019
1 parent a79c85c commit 48edb72
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# diff-x

Pretty diffs for case classes.

## Scalatest integration

To use with scalatest, add the following dependency:

```scala
"com.softwaremill.diffx" %% "diffx-scalatest" % "0.1.0"
```

Then, extend the `com.softwaremill.diffx.DiffMatcher` trait or `import com.softwaremill.diffx.DiffMatcher._`.
You will then be able to use syntax such as:

```scala
left should matchTo(right)
```

Giving you nice error messages, such as:

![alt text](https://raw.githubusercontent.com/softwaremill/diffx/master/example.png)

## Using directly

Add the following dependency:

```scala
"com.softwaremill.diffx" %% "diffx-core" % "0.1.0"
```

Then call:

```scala
import com.softwaremill.diffx.DiffFor
implicitly[DiffFor[T]].diff(o1, o2)
```

## Custom types

If you'd like to implement custom matching logic for a custom type, create an implicit `DiffFor` instance for that
type, and make sure it's in scope when creating `DiffFor` for the case class.
1 change: 0 additions & 1 deletion core/src/main/scala/com/softwaremill/diffx/DiffFor.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.softwaremill.diffx

trait DiffFor[T] {

def diff(left: T, right: T): DiffResult
}

Expand Down
25 changes: 14 additions & 11 deletions core/src/test/scala/com/softwaremill/diffx/DiffTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class DiffTest extends FlatSpec with Matchers with DiffForInstances {
it should "calculate diff for product types" in {
compare(p1, p2) shouldBe DiffResultObject(
"Person",
Map("name" -> Identical("kasper"), "age" -> DiffResultValue(22, 11), "in" -> Identical(instant)))
Map("name" -> Identical("kasper"), "age" -> DiffResultValue(22, 11), "in" -> Identical(instant))
)
}

it should "calculate identity for product types" in {
Expand All @@ -32,10 +33,10 @@ class DiffTest extends FlatSpec with Matchers with DiffForInstances {
"Family",
Map(
"first" -> Identical(p1),
"second" -> DiffResultObject("Person",
Map("name" -> Identical("kasper"),
"age" -> DiffResultValue(11, 22),
"in" -> Identical(instant)))
"second" -> DiffResultObject(
"Person",
Map("name" -> Identical("kasper"), "age" -> DiffResultValue(11, 22), "in" -> Identical(instant))
)
)
)
}
Expand All @@ -50,20 +51,22 @@ class DiffTest extends FlatSpec with Matchers with DiffForInstances {
"List",
Map(
"0" -> Identical(p1),
"1" -> DiffResultObject("Person",
Map("name" -> Identical("kasper"),
"age" -> DiffResultValue(11, 22),
"in" -> Identical(instant))),
"1" -> DiffResultObject(
"Person",
Map("name" -> Identical("kasper"), "age" -> DiffResultValue(11, 22), "in" -> Identical(instant))
),
"2" -> DiffResultMissing(Person("kasper", 22, instant))
)
))
)
)
)
}

it should "calculate diff for sealed trait objects" in {
compare[TsDirection](TsDirection.Outgoing, TsDirection.Incoming) shouldBe DiffResultValue(
"com.softwaremill.diffx.TsDirection.Outgoing",
"com.softwaremill.diffx.TsDirection.Incoming")
"com.softwaremill.diffx.TsDirection.Incoming"
)
}

val right: Foo = Foo(
Expand Down
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ trait DiffMatcher extends DiffForInstances {
}

}

object DiffMatcher extends DiffMatcher
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DiffMatcherTest extends FlatSpec with Matchers with DiffMatcher {
Some(right)
)

ignore should "wor" in {
ignore should "work" in {
left should matchTo(right)
}

Expand Down

0 comments on commit 48edb72

Please sign in to comment.