Fix diff case
authorTom Clegg <tom@curii.com>
Wed, 3 Aug 2022 20:14:27 +0000 (16:14 -0400)
committerTom Clegg <tom@curii.com>
Wed, 3 Aug 2022 20:14:27 +0000 (16:14 -0400)
refs #19236 #note-15.7

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

hgvs/diff.go
hgvs/diff_test.go

index 7fe72d9d263d060b5811e8bb300f109e4bf65e6b..bde91fba75ac8bcd791486675e20e561e3252679 100644 (file)
@@ -250,19 +250,6 @@ 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
-               }
                // [=AB,insCB,=D] => [=A,insBC,=BD]
                // and
                // [=AB,delCB,=D] => [=A,delBC,=BD]
@@ -271,7 +258,6 @@ func cleanup(in []diffmatchpatch.Diff) (out []diffmatchpatch.Diff) {
                        in[i+1].Type != diffmatchpatch.DiffEqual &&
                        in[i+2].Type == diffmatchpatch.DiffEqual &&
                        len(d.Text) > 0 && len(in[i+1].Text) > 0 &&
-                       d.Text[len(d.Text)-1] == in[i+1].Text[len(in[i+1].Text)-1] &&
                        !(i+3 < len(in) &&
                                // Except: leave deletion alone if an
                                // upcoming insertion will be moved up
@@ -297,6 +283,11 @@ func cleanup(in []diffmatchpatch.Diff) (out []diffmatchpatch.Diff) {
                                        in[i+1].Text[:len(in[i+1].Text)-x],
                                in[i+1].Text[len(in[i+1].Text)-x:]+in[i+2].Text
                }
+               // [=X,delAX] => [delXA,=X]
+               if i < len(in)-1 &&
+                       d.Type == diffmatchpatch.DiffEqual &&
+                       in[i+1].Type == diffmatchpatch.DiffDelete && false {
+               }
                out = append(out, d)
        }
        in, out = out, make([]diffmatchpatch.Diff, 0, len(in))
index 3e8be60d17e2cbc85e1766d01b580244f7af2df9..eb882fb856c4ac7b4eaded3cd0d007abef434881 100644 (file)
@@ -193,9 +193,9 @@ func (s *diffSuite) TestDiff(c *check.C) {
                        expect: []string{"2_3insGT"},
                },
                {
-                       a:      "aGACGGACAGGGCCCgg",
-                       b:      "agg",
-                       expect: []string{"3_15del"},
+                       a:      "aGACGGACAGGGCCCggatgcaa",
+                       b:      "aggatgcaa",
+                       expect: []string{"2_15del"},
                },
                {
                        a:      "aggGac",
@@ -223,14 +223,25 @@ func (s *diffSuite) TestDiff(c *check.C) {
                        expect: []string{"1_2insTTCG"},
                },
                {
-                       a:      "tcAACaggg",
-                       b:      "tcaggg",
+                       a:      "tCAACAggg",
+                       b:      "tCAggg",
                        expect: []string{"2_4del"},
                },
+               {
+                       a:      "caaAc",
+                       b:      "caaCc",
+                       expect: []string{"4A>C"},
+               },
+               {
+                       a:      "aGGgaca",
+                       b:      "agaca",
+                       expect: []string{"2_3del"},
+               },
        } {
                c.Log(trial)
                var vars []string
                diffs, _ := Diff(strings.ToUpper(trial.a), strings.ToUpper(trial.b), 0)
+               c.Logf("%v", diffs)
                for _, v := range diffs {
                        vars = append(vars, v.String())
                }