difftest

package
v0.0.0-...-3f344d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2021 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package difftest supplies a set of tests that will operate on any implementation of a diff algorithm as exposed by "github.com/system-pclub/GCatch/GCatch/tools/internal/lsp/diff"

Index

Constants

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

Variables

View Source
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: "multiple_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,
	},
}

Functions

func DiffTest

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

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL