Fix left-most diff cases.
[lightning.git] / hgvs / diff_test.go
index 9c04ea75b657c4c21f70a90fcc3e3ea07d6f43ca..10acdb772c64c65fad369e8abad0a33a3afc15cf 100644 (file)
@@ -1,6 +1,11 @@
+// Copyright (C) The Lightning Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package hgvs
 
 import (
+       "strings"
        "testing"
 
        "gopkg.in/check.v1"
@@ -21,7 +26,7 @@ func (s *diffSuite) TestDiff(c *check.C) {
                {
                        a:      "aaaaaaaaaa",
                        b:      "aaaaCaaaaa",
-                       expect: []string{"5a>C"},
+                       expect: []string{"5A>C"},
                },
                {
                        a:      "aaaacGcaaa",
@@ -56,12 +61,120 @@ func (s *diffSuite) TestDiff(c *check.C) {
                {
                        a:      "aaGGttAAtttt",
                        b:      "aaCCttttttC",
-                       expect: []string{"3_4delinsCC", "7_8del", "12_13insC"},
+                       expect: []string{"3G>C", "4G>C", "7_8del", "12_13insC"},
+               },
+               {
+                       // without cleanup, diffmatchpatch solves this as {"3del", "=A", "4_5insA"}
+                       a:      "aggaggggg",
+                       b:      "agAaggggg",
+                       expect: []string{"3G>A"},
+               },
+               {
+                       // without cleanup, diffmatchpatch solves this as {"3_4del", "=A", "5_6insAA"}
+                       a:      "agggaggggg",
+                       b:      "agAAaggggg",
+                       expect: []string{"3G>A", "4G>A"},
+               },
+               {
+                       // without cleanup, diffmatchpatch solves this as {"3_4del", "=A", "5_6insCA"}
+                       a:      "agggaggggg",
+                       b:      "agACaggggg",
+                       expect: []string{"3G>A", "4G>C"},
+               },
+               {
+                       // without cleanup, diffmatchpatch solves this as {"3_7del", "=A", "8_9insAAACA"}
+                       a:      "aggggggaggggg",
+                       b:      "agAAAACaggggg",
+                       expect: []string{"3_7delinsAAAAC"},
+               },
+               {
+                       // without cleanup, diffmatchpatch solves this as {"3_7del", "=AAAA", "11_12insCAAAA"}
+                       a:      "aggggggaaaaggggg",
+                       b:      "agAAAACaaaaggggg",
+                       expect: []string{"3_7delinsAAAAC"},
+               },
+               {
+                       a:      "agggaggggg",
+                       b:      "agCAaggggg",
+                       expect: []string{"3G>C", "4G>A"},
+               },
+               {
+                       a:      "agggg",
+                       b:      "agAAg",
+                       expect: []string{"3G>A", "4G>A"},
+               },
+               {
+                       a:      "aggggg",
+                       b:      "agAAAg",
+                       expect: []string{"3_5delinsAAA"},
+               },
+               {
+                       a:      "acgtgaa",
+                       b:      "acTtgaa",
+                       expect: []string{"3G>T"},
+               },
+               {
+                       a:      "tcagaagac",
+                       b:      "tcaAaagac",
+                       expect: []string{"4G>A"},
+               },
+               {
+                       a:      "tcagatggac",
+                       b:      "tcaAaCggac",
+                       expect: []string{"4G>A", "6T>C"},
+               },
+               {
+                       a:      "tcagatggac",
+                       b:      "tcaAaCggTc",
+                       expect: []string{"4G>A", "6T>C", "9A>T"},
+               },
+               {
+                       a:      "tcagatggac",
+                       b:      "tcaAaCCggTc",
+                       expect: []string{"4G>A", "6delinsCC", "9A>T"},
+               },
+               {
+                       a:      "tcatagagac",
+                       b:      "tcacaagac",
+                       expect: []string{"4T>C", "6del"},
+               },
+               {
+                       a:      "tcatcgagac",
+                       b:      "tcGCcgagac",
+                       expect: []string{"3A>G", "4T>C"},
+               },
+               {
+                       a:      "tcatcgagac",
+                       b:      "tcGCcggac",
+                       expect: []string{"3A>G", "4T>C", "7del"},
+               },
+               {
+                       // should delete leftmost
+                       a:      "acgacaTTtttacac",
+                       b:      "acgacatttacac",
+                       expect: []string{"7_8del"},
+               },
+               {
+                       // should insert leftmost
+                       a:      "acgacatttacac",
+                       b:      "acgacaTTtttacac",
+                       expect: []string{"6_7insTT"},
+               },
+               {
+                       a:      "ccccaGATAtat",
+                       b:      "ccccatat",
+                       expect: []string{"6_9del"},
+               },
+               {
+                       a:      "aGATAtat",
+                       b:      "atat",
+                       expect: []string{"2_5del"},
                },
        } {
                c.Log(trial)
                var vars []string
-               for _, v := range Diff(trial.a, trial.b, 0) {
+               diffs, _ := Diff(strings.ToUpper(trial.a), strings.ToUpper(trial.b), 0)
+               for _, v := range diffs {
                        vars = append(vars, v.String())
                }
                c.Check(vars, check.DeepEquals, trial.expect)