From 519577af0a389a3d6dc4af8da8a3332b9504e9fb Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Tue, 26 Jul 2022 13:16:15 -0400 Subject: [PATCH] Fix diff case refs #19236 #note-15.1 Arvados-DCO-1.1-Signed-off-by: Tom Clegg --- hgvs/diff.go | 13 +++++++++++++ hgvs/diff_test.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/hgvs/diff.go b/hgvs/diff.go index e2b73439bf..c217949ee4 100644 --- a/hgvs/diff.go +++ b/hgvs/diff.go @@ -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)) diff --git a/hgvs/diff_test.go b/hgvs/diff_test.go index 2778dc8f55..3cac5db020 100644 --- a/hgvs/diff_test.go +++ b/hgvs/diff_test.go @@ -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 -- 2.30.2