Fix diff case
authorTom Clegg <tom@curii.com>
Tue, 26 Jul 2022 17:16:15 +0000 (13:16 -0400)
committerTom Clegg <tom@curii.com>
Tue, 26 Jul 2022 17:16:15 +0000 (13:16 -0400)
refs #19236 #note-15.1

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

hgvs/diff.go
hgvs/diff_test.go

index e2b73439bf9d316e44afdc55005c05a0b1036e6f..c217949ee41e41d46429aa52d987da09c88edf6f 100644 (file)
@@ -219,6 +219,19 @@ func cleanup(in []diffmatchpatch.Diff) (out []diffmatchpatch.Diff) {
                        i++
                        continue
                }
+               // when diffmatchpatch says [delA, =X, delBX], we
+               // prefer [delAB, =X].
+               if i < len(in)-2 &&
+                       d.Type == diffmatchpatch.DiffDelete &&
+                       in[i+1].Type == diffmatchpatch.DiffEqual &&
+                       in[i+2].Type == diffmatchpatch.DiffDelete &&
+                       strings.HasSuffix(in[i+2].Text, in[i+1].Text) {
+                       out = append(out,
+                               diffmatchpatch.Diff{diffmatchpatch.DiffDelete, d.Text + in[i+2].Text[:len(in[i+2].Text)-len(in[i+1].Text)]},
+                               in[i+1])
+                       i += 2
+                       continue
+               }
                out = append(out, d)
        }
        in, out = out, make([]diffmatchpatch.Diff, 0, len(in))
index 2778dc8f553e2ce5f4964f9b0d0fb59c2efed1ab..3cac5db020eedd2c86969ec25854c774950132ec 100644 (file)
@@ -192,6 +192,11 @@ func (s *diffSuite) TestDiff(c *check.C) {
                        b:      "acGTTTTTatcc",
                        expect: []string{"2_3insGT"},
                },
+               {
+                       a:      "aGACGGACAGGGCCCgg",
+                       b:      "agg",
+                       expect: []string{"3_15del"},
+               },
        } {
                c.Log(trial)
                var vars []string