-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #756 from majk-p/extract-diff-module
Extract diff module
- Loading branch information
Showing
29 changed files
with
406 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../scala/munit/internal/difflib/Chunk.scala → ...red/src/main/scala/munit/diff/Chunk.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
import java.util | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../scala/munit/internal/difflib/Delta.scala → ...red/src/main/scala/munit/diff/Delta.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...unit/internal/difflib/DiffAlgorithm.scala → ...main/scala/munit/diff/DiffAlgorithm.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
import java.util | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...la/munit/internal/difflib/DiffUtils.scala → ...src/main/scala/munit/diff/DiffUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
import java.util | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...flib/DifferentiationFailedException.scala → ...diff/DifferentiationFailedException.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
class DifferentiationFailedException(message: String) extends Exception(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package munit.diff | ||
|
||
object Diffs { | ||
|
||
def create(obtained: String, expected: String): Diff = | ||
new Diff(obtained, expected) | ||
|
||
def createDiffOnlyReport( | ||
obtained: String, | ||
expected: String | ||
): String = { | ||
create(obtained, expected).createDiffOnlyReport() | ||
} | ||
|
||
def createReport( | ||
obtained: String, | ||
expected: String, | ||
title: String, | ||
printObtainedAsStripMargin: Boolean = true | ||
): String = { | ||
create(obtained, expected).createReport(title, printObtainedAsStripMargin) | ||
} | ||
|
||
def unifiedDiff(obtained: String, expected: String): String = { | ||
create(obtained, expected).unifiedDiff | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...la/munit/internal/difflib/Equalizer.scala → ...src/main/scala/munit/diff/Equalizer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../scala/munit/internal/difflib/Patch.scala → ...red/src/main/scala/munit/diff/Patch.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.difflib | ||
package munit.diff | ||
|
||
import java.util | ||
import java.util.{Collections, Comparator} | ||
|
2 changes: 1 addition & 1 deletion
2
...ala/munit/internal/difflib/PathNode.scala → .../src/main/scala/munit/diff/PathNode.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...shared/src/main/scala/munit/Printer.scala → ...d/src/main/scala/munit/diff/Printer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit | ||
package munit.diff | ||
|
||
/** | ||
* Implement this trait to customize the default printer | ||
|
2 changes: 1 addition & 1 deletion
2
...a/munit/internal/console/AnsiColors.scala → ...scala/munit/diff/console/AnsiColors.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package munit.internal.console | ||
package munit.diff.console | ||
|
||
object AnsiColors { | ||
val LightRed = "\u001b[91m" | ||
|
59 changes: 59 additions & 0 deletions
59
munit-diff/shared/src/main/scala/munit/diff/console/Printers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package munit.diff.console | ||
|
||
import munit.diff.{EmptyPrinter, Printer} | ||
|
||
import scala.annotation.switch | ||
|
||
object Printers { | ||
|
||
def print(input: String): String = { | ||
val out = new StringBuilder() | ||
printString(input, out, EmptyPrinter) | ||
munit.diff.console.AnsiColors.filterAnsi(out.toString()) | ||
} | ||
|
||
def printString( | ||
string: String, | ||
out: StringBuilder, | ||
printer: Printer | ||
): Unit = { | ||
val isMultiline = printer.isMultiline(string) | ||
if (isMultiline) { | ||
out.append('"') | ||
out.append('"') | ||
out.append('"') | ||
out.append(string) | ||
out.append('"') | ||
out.append('"') | ||
out.append('"') | ||
} else { | ||
out.append('"') | ||
var i = 0 | ||
while (i < string.length()) { | ||
printChar(string.charAt(i), out) | ||
i += 1 | ||
} | ||
out.append('"') | ||
} | ||
} | ||
|
||
def printChar( | ||
c: Char, | ||
sb: StringBuilder, | ||
isEscapeUnicode: Boolean = true | ||
): Unit = | ||
(c: @switch) match { | ||
case '"' => sb.append("\\\"") | ||
case '\\' => sb.append("\\\\") | ||
case '\b' => sb.append("\\b") | ||
case '\f' => sb.append("\\f") | ||
case '\n' => sb.append("\\n") | ||
case '\r' => sb.append("\\r") | ||
case '\t' => sb.append("\\t") | ||
case c => | ||
val isNonReadableAscii = c < ' ' || (c > '~' && isEscapeUnicode) | ||
if (isNonReadableAscii && !Character.isLetter(c)) | ||
sb.append("\\u%04x".format(c.toInt)) | ||
else sb.append(c) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.