tools: golang.org/x/tools/internal/lsp/diff/difftest Index | Files

package difftest

import "golang.org/x/tools/internal/lsp/diff/difftest"

Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "golang.org/x/tools/internal/lsp/diff"

Index

Package Files

difftest.go

Constants

const (
    FileA         = "from"
    FileB         = "to"
    UnifiedPrefix = "--- " + FileA + "\n+++ " + FileB + "\n"
)

Variables

var TestCases = []struct {
    Name, In, Out, Unified string
    Edits, LineEdits       []diff.TextEdit
    NoDiff                 bool
}{{
    Name: "empty",
    In:   "",
    Out:  "",
}, {
    Name: "no_diff",
    In:   "gargantuan\n",
    Out:  "gargantuan\n",
}, {
    Name: "replace_all",
    In:   "fruit\n",
    Out:  "cheese\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-fruit
+cheese
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(0, 5), NewText: "cheese"}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 6), NewText: "cheese\n"}},
}, {
    Name: "insert_rune",
    In:   "gord\n",
    Out:  "gourd\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-gord
+gourd
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(2, 2), NewText: "u"}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 5), NewText: "gourd\n"}},
}, {
    Name: "delete_rune",
    In:   "groat\n",
    Out:  "goat\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-groat
+goat
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(1, 2), NewText: ""}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 6), NewText: "goat\n"}},
}, {
    Name: "replace_rune",
    In:   "loud\n",
    Out:  "lord\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-loud
+lord
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(2, 3), NewText: "r"}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 5), NewText: "lord\n"}},
}, {
    Name: "replace_partials",
    In:   "blanket\n",
    Out:  "bunker\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-blanket
+bunker
`[1:],
    Edits: []diff.TextEdit{
        {Span: newSpan(1, 3), NewText: "u"},
        {Span: newSpan(6, 7), NewText: "r"},
    },
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 8), NewText: "bunker\n"}},
}, {
    Name: "insert_line",
    In:   "1: one\n3: three\n",
    Out:  "1: one\n2: two\n3: three\n",
    Unified: UnifiedPrefix + `
@@ -1,2 +1,3 @@
 1: one
+2: two
 3: three
`[1:],
    Edits: []diff.TextEdit{{Span: newSpan(7, 7), NewText: "2: two\n"}},
}, {
    Name: "replace_no_newline",
    In:   "A",
    Out:  "B",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-A
\ No newline at end of file
+B
\ No newline at end of file
`[1:],
    Edits: []diff.TextEdit{{Span: newSpan(0, 1), NewText: "B"}},
}, {
    Name: "add_end",
    In:   "A",
    Out:  "AB",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-A
\ No newline at end of file
+AB
\ No newline at end of file
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(1, 1), NewText: "B"}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 1), NewText: "AB"}},
}, {
    Name: "add_newline",
    In:   "A",
    Out:  "A\n",
    Unified: UnifiedPrefix + `
@@ -1 +1 @@
-A
\ No newline at end of file
+A
`[1:],
    Edits:     []diff.TextEdit{{Span: newSpan(1, 1), NewText: "\n"}},
    LineEdits: []diff.TextEdit{{Span: newSpan(0, 1), NewText: "A\n"}},
}, {
    Name: "delete_front",
    In:   "A\nB\nC\nA\nB\nB\nA\n",
    Out:  "C\nB\nA\nB\nA\nC\n",
    Unified: UnifiedPrefix + `
@@ -1,7 +1,6 @@
-A
-B
 C
+B
 A
 B
-B
 A
+C
`[1:],
    Edits: []diff.TextEdit{
        {Span: newSpan(0, 4), NewText: ""},
        {Span: newSpan(6, 6), NewText: "B\n"},
        {Span: newSpan(10, 12), NewText: ""},
        {Span: newSpan(14, 14), NewText: "C\n"},
    },
    NoDiff: true,
},
    {
        Name: "replace_last_line",
        In:   "A\nB\n",
        Out:  "A\nC\n\n",
        Unified: UnifiedPrefix + `
@@ -1,2 +1,3 @@
 A
-B
+C
+
`[1:],
        Edits:     []diff.TextEdit{{Span: newSpan(2, 3), NewText: "C\n"}},
        LineEdits: []diff.TextEdit{{Span: newSpan(2, 4), NewText: "C\n\n"}},
    },
    {
        Name: "mulitple_replace",
        In:   "A\nB\nC\nD\nE\nF\nG\n",
        Out:  "A\nH\nI\nJ\nE\nF\nK\n",
        Unified: UnifiedPrefix + `
@@ -1,7 +1,7 @@
 A
-B
-C
-D
+H
+I
+J
 E
 F
-G
+K
`[1:],
        Edits: []diff.TextEdit{
            {Span: newSpan(2, 8), NewText: "H\nI\nJ\n"},
            {Span: newSpan(12, 14), NewText: "K\n"},
        },
        NoDiff: true,
    },
}

func DiffTest Uses

func DiffTest(t *testing.T, compute diff.ComputeEdits)

Package difftest imports 4 packages (graph). Updated 2019-11-15. Refresh now. Tools for package owners.