Skip to content

Commit

Permalink
Add always ignore differ
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang committed Jul 27, 2021
1 parent f5f7b10 commit e395e00
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ projectFilesBackup/
version.properties
RUNNING_PID
.metals
metals.sbt
.bsp
TempGo.scala
29 changes: 29 additions & 0 deletions modules/core/src/main/scala/difflicious/AlwaysIgnoreDiffer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package difflicious

import difflicious.DiffResult.ValueResult

/** A Differ that always return an Ignored result.
* Useful when you can't really diff a type */
class AlwaysIgnoreDiffer[T] extends Differ[T] {
override type R = ValueResult

override def diff(inputs: DiffInput[T]): ValueResult =
ValueResult.Both("[ALWAYS IGNORED]", "[ALWAYS IGNORED]", isSame = true, isIgnored = true)

override protected def configureIgnored(newIgnored: Boolean): Differ[T] = this

override protected def configurePath(
step: String,
nextPath: ConfigurePath,
op: ConfigureOp,
): Either[ConfigureError, Differ[T]] = {
Left(ConfigureError.PathTooLong(nextPath))
}

override protected def configurePairBy(
path: ConfigurePath,
op: ConfigureOp.PairBy[_],
): Either[ConfigureError, Differ[T]] = {
Left(ConfigureError.InvalidConfigureOp(path, op, "AlwaysIgnoreDiffer"))
}
}
3 changes: 3 additions & 0 deletions modules/core/src/main/scala/difflicious/Differ.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ object Differ extends DifferTupleInstances with DifferGen with DifferTimeInstanc
def useEquals[T](valueToString: T => String): EqualsDiffer[T] =
new EqualsDiffer[T](isIgnored = false, valueToString = valueToString)

/** A Differ that always return an Ignored result. Useful when you can't really diff something */
def alwaysIgnore[T]: AlwaysIgnoreDiffer[T] = new AlwaysIgnoreDiffer[T]

// TODO: better string diff (edit distance and a description of how to get there?
// this can help especially in cases like extra space or special char)
implicit val stringDiffer: ValueDiffer[String] = useEquals[String](str => s""""$str"""")
Expand Down

0 comments on commit e395e00

Please sign in to comment.