File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -967,7 +967,7 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
967967 float64 (overlapLength2 ) >= float64 (len (insertion ))/ 2 {
968968 // Reverse overlap found.
969969 // Insert an equality and swap and trim the surrounding edits.
970- overlap := Diff {DiffEqual , insertion [ len ( insertion ) - overlapLength2 : ]}
970+ overlap := Diff {DiffEqual , deletion [: overlapLength2 ]}
971971 diffs = append (
972972 diffs [:pointer ],
973973 append ([]Diff {overlap }, diffs [pointer :]... )... )
Original file line number Diff line number Diff line change @@ -680,6 +680,21 @@ func Test_diffCleanupSemantic(t *testing.T) {
680680 Diff {DiffDelete , "A" },
681681 Diff {DiffEqual , "3" },
682682 Diff {DiffInsert , "BC" }}, diffs )
683+
684+ // Test case for adapting DiffCleanupSemantic to be equal to the Python version #19
685+ diffs = dmp .DiffMain ("James McCarthy close to signing new Everton deal" , "James McCarthy signs new five-year deal at Everton" , false )
686+ diffs = dmp .DiffCleanupSemantic (diffs )
687+ assertDiffEqual (t , []Diff {
688+ Diff {DiffEqual , "James McCarthy " },
689+ Diff {DiffDelete , "close to " },
690+ Diff {DiffEqual , "sign" },
691+ Diff {DiffDelete , "ing" },
692+ Diff {DiffInsert , "s" },
693+ Diff {DiffEqual , " new " },
694+ Diff {DiffInsert , "five-year deal at " },
695+ Diff {DiffEqual , "Everton" },
696+ Diff {DiffDelete , " deal" },
697+ }, diffs )
683698}
684699
685700func Test_diffCleanupEfficiency (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments