if (expected != null) checkLineChanges(fragments, expected)
}
- private fun doWordTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
+ private fun doLineInnerTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
val rawFragments = MANAGER.compareLinesInner(before.charsSequence, after.charsSequence, policy, INDICATOR)
val fragments = MANAGER.squash(rawFragments)
- checkConsistencyWord(fragments, before, after)
+ checkConsistencyLineInner(fragments, before, after)
val diffFragments = fragments[0].innerFragments!!
if (matchings != null) checkDiffMatching(diffFragments, matchings)
if (expected != null) checkDiffChanges(diffFragments, expected)
}
+ private fun doWordTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
+ val fragments = MANAGER.compareWords(before.charsSequence, after.charsSequence, policy, INDICATOR)
+ checkConsistency(fragments, before, after)
+
+ if (matchings != null) checkDiffMatching(fragments, matchings)
+ if (expected != null) checkDiffChanges(fragments, expected)
+ }
+
private fun doCharTest(before: Document, after: Document, matchings: Couple<BitSet>?, expected: List<Change>?, policy: ComparisonPolicy) {
val fragments = MANAGER.compareChars(before.charsSequence, after.charsSequence, policy, INDICATOR)
checkConsistency(fragments, before, after)
if (expected != null) checkLineChanges(fragments, expected)
}
- private fun checkConsistencyWord(fragments: List<LineFragment>, before: Document, after: Document) {
+ private fun checkConsistencyLineInner(fragments: List<LineFragment>, before: Document, after: Document) {
assertTrue(fragments.size == 1)
val fragment = fragments[0]
//
internal enum class TestType {
- LINE, WORD, CHAR, SPLITTER
+ LINE, LINE_INNER, WORD, CHAR, SPLITTER
}
internal inner class TestBuilder(private val type: TestType) {
when (type) {
TestType.LINE -> doLineTest(before!!, after!!, matchings, change, policy)
+ TestType.LINE_INNER -> {
+ doLineInnerTest(before!!, after!!, matchings, change, policy)
+ doWordTest(before!!, after!!, matchings, change, policy)
+ }
TestType.WORD -> doWordTest(before!!, after!!, matchings, change, policy)
TestType.CHAR -> doCharTest(before!!, after!!, matchings, change, policy)
TestType.SPLITTER -> {
internal fun lines(f: TestBuilder.() -> Unit): Unit = doTest(TestType.LINE, f)
+ internal fun lines_inner(f: TestBuilder.() -> Unit): Unit = doTest(TestType.LINE_INNER, f)
+
internal fun words(f: TestBuilder.() -> Unit): Unit = doTest(TestType.WORD, f)
internal fun chars(f: TestBuilder.() -> Unit): Unit = doTest(TestType.CHAR, f)
class WordComparisonUtilTest : ComparisonUtilTestBase() {
fun testSimpleCases() {
- words {
+ lines_inner {
("x z" - "y z")
("- " - "- ").default()
testAll()
}
- words {
+ lines_inner {
("x z" - "y z")
("- " - "- ").default()
testAll()
}
- words {
+ lines_inner {
(" x z" - "y z")
("-- " - "- ").default()
(" - " - "- ").trim()
testAll()
}
- words {
+ lines_inner {
("x z " - "y z")
("- -" - "- ").default()
("- " - "- ").trim()
testAll()
}
- words {
+ lines_inner {
("x z " - "y z")
("- -" - "- ").default()
("- " - "- ").trim()
testAll()
}
- words {
+ lines_inner {
("x z" - " y z ")
("- " - "-- -").default()
("- " - " - ").trim()
testAll()
}
- words {
+ lines_inner {
("x y" - "x z ")
(" -" - " --").default()
(" -" - " - ").trim()
testAll()
}
- words {
+ lines_inner {
("x,y" - "x")
(" --" - " ").default()
testAll()
}
- words {
+ lines_inner {
("x,y" - "y")
("-- " - " ").default()
testAll()
}
- words {
+ lines_inner {
(".x=" - ".!=")
(" - " - " - ").default()
testAll()
}
- words {
+ lines_inner {
("X xyz1 Z" - "X xyz2 Z")
(" ---- " - " ---- ").default()
testAll()
}
fun testPunctuation() {
- words {
+ lines_inner {
(" x.z.x " - "x..x")
("- - -" - " ").default()
(" - " - " ").trim()
testAll()
}
- words {
+ lines_inner {
("x..x" - " x.z.x ")
(" " - "- - -").default()
(" " - " - ").trim()
testAll()
}
- words {
+ lines_inner {
("x ... z" - "y ... z")
("- " - "- ").default()
testAll()
}
- words {
+ lines_inner {
("x ... z" - "x ... y")
(" -" - " -").default()
testAll()
}
- words {
+ lines_inner {
("x ,... z" - "x ... y")
(" - -" - " -").default()
testAll()
}
- words {
+ lines_inner {
("x . , .. z" - "x ... y")
(" --- -" - " -").default()
(" - -" - " -").ignore()
testAll()
}
- words {
+ lines_inner {
("x==y==z" - "x====z")
(" - " - " ").default()
testAll()
}
- words {
+ lines_inner {
("x====z" - "x==t==z")
(" " - " - ").default()
testAll()
}
fun testOldDiffBug() {
- words {
+ lines_inner {
("x'y'>" - "x'>")
(" -- " - " ").default()
testAll()
}
- words {
+ lines_inner {
("x'>" - "x'y'>")
(" " - " -- ").default()
testAll()
}
fun testWhitespaceOnlyChanges() {
- words {
+ lines_inner {
("x =z" - "x= z")
(" -- " - " -- ").default()
testDefault()
testTrim()
}
- words {
+ lines_inner {
("x =" - "x= z")
(" -- " - " ---").default()
(" " - " -").ignore()
}
fun testNewlines() {
- words {
+ lines_inner {
(" x _ y _ z " - "x z")
("- ------ -" - " ").default()
(" - " - " ").trim()
testAll()
}
- words {
+ lines_inner {
("x z" - " x _ y _ z ")
(" " - "- ------ -").default()
(" " - " - ").trim()
}
fun testFixedBugs() {
- words {
+ lines_inner {
(".! " - ". y!")
(" -" - " --- ").default()
(" " - " --- ").trim()
testAll()
}
- words {
+ lines_inner {
(" x n" - " y_ x m")
(" -" - "---- -").default()
(" -" - " - -").trim()
testAll()
}
- words {
+ lines_inner {
("x_" - "x! ")
(" -" - " ---").default()
(" " - " - ").trim()
}
fun testInnerWhitespaces() {
- words {
+ lines_inner {
("<< x >>" - "<.<>.>")
(" --- " - " - - ").default()
(" - " - " - - ").ignore()
testAll()
}
- words {
+ lines_inner {
("<< x >>" - "y<<x>>y")
(" - - " - "- -").default()
(" " - "- -").ignore()
testAll()
}
- words {
+ lines_inner {
("x .. z" - "x y .. z")
(" " - " -- ").default() // TODO: looks wrong
(" " - " - ").ignore()
testAll()
}
- words {
+ lines_inner {
(" x..z" - "x..y ")
("-- -" - " ---").default()
(" -" - " - ").trim()
testAll()
}
- words {
+ lines_inner {
(" x y x _ x z x " - "x x_x x")
("- -- - - -- -" - " ").default()
(" -- -- " - " ").trim()
fun testAlgorithmSpecific() {
// prefer words over punctuation
- words {
+ lines_inner {
("...x" - "x...")
("--- " - " ---").default()
testAll()
}
// prefer longer words sequences
- words {
+ lines_inner {
("x x y" - "x y")
("-- " - " ").default()
("- " - " ").ignore()
testAll()
}
- words {
+ lines_inner {
("y x x" - "y x")
(" --" - " ").default()
(" -" - " ").ignore()
testAll()
}
- words {
+ lines_inner {
("A X A B" - "A B")
("---- " - " ").default()
("--- " - " ").ignore()
}
// prefer less modified 'sentences'
- words {
+ lines_inner {
("A.X A.Z" - "A.X A.Y A.Z")
(" " - " ---- ").default()
(" " - " --- ").ignore()
testAll()
}
- words {
+ lines_inner {
("X.A Z.A" - "X.A Y.A Z.A")
(" " - " ---- ").default()
(" " - " --- ").ignore()
}
// prefer punctuation over whitespaces
- words {
+ lines_inner {
(". " - " .")
(" ---" - "--- ").default()
testDefault()
}
fun `test legacy cases from ByWordTest`() {
- words {
+ lines_inner {
("abc def, 123" - "ab def, 12")
("--- ---" - "-- --").default()
testAll()
}
- words {
+ lines_inner {
(" a[xy]+1" - ",a[]+1")
("- -- " - "- ").default()
(" -- " - "- ").trim()
testAll()
}
- words {
+ lines_inner {
("0987_ a.g();_" - "yyyy_")
("------------- " - "---- ").default()
testAll()
}
- words {
+ lines_inner {
(" abc_2222_" - " x = abc_zzzz_")
//(" ---- " - "-- ---- ---- ").legacy()
(" ---- " - " ------ ---- ").default()
testAll()
}
- words { // Idea58505
+ lines_inner { // Idea58505
(" if (eventMerger!=null && !dataSelection.getValueIsAdjusting()) {" -
" if (eventMerger!=null && (dataSelection==null || !dataSelection.getValueIsAdjusting())) {")
//(" - " -
testAll()
}
- words { // Idea56428
+ lines_inner { // Idea56428
("messageInsertStatement = connection.prepareStatement(\"INSERT INTO AUDIT (AUDIT_TYPE_ID, STATUS, SERVER_ID, INSTANCE_ID, REQUEST_ID) VALUES (?, ?, ?, ?, ?)\");" -
"messageInsertStatement = connection.prepareStatement(\"INSERT INTO AUDIT (AUDIT_TYPE_ID, CREATION_TIMESTAMP, STATUS, SERVER_ID, INSTANCE_ID, REQUEST_ID) VALUES (?, ?, ?, ?, ?, ?)\");").plainSource()
//(" . . " -
testAll()
}
- words {
+ lines_inner {
("f(a, b);" - "f(a,_ b);")
(" " - " -- ").default()
(" " - " ").trim()
testAll()
}
- words {
+ lines_inner {
(" o.f(a)" - "o. f( b)")
("- - " - " - -- ").default()
(" - " - " - -- ").trim()
testAll()
}
- words {
+ lines_inner {
(" 123 " - "xyz")
(" --- " - "---").trim()
testTrim()
}
fun testEmptyRangePositions() {
- words {
+ lines_inner {
("x? y" - "x y")
(" - " - " ").default()
default(del(1, 1, 1))
testAll()
}
- words {
+ lines_inner {
("x ?y" - "x y")
(" - " - " ").default()
default(del(2, 2, 1))