MCPcopy Create free account
hub / github.com/bufbuild/buf / TestDiff

Function TestDiff

private/pkg/diff/diffmyers/diffmyers_test.go:30–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28const writeGoldenFiles = false
29
30func TestDiff(t *testing.T) {
31 t.Parallel()
32 t.Run("delete-and-insert", func(t *testing.T) {
33 t.Parallel()
34 const from = "Hello, world!\n"
35 const to = "Goodbye, world!\n"
36 edits := diffmyers.Diff(
37 splitLines(from),
38 splitLines(to),
39 )
40 assert.Equal(t, edits, []diffmyers.Edit{
41 {
42 Kind: diffmyers.EditKindDelete,
43 },
44 {
45 Kind: diffmyers.EditKindInsert,
46 FromPosition: 1,
47 },
48 })
49 testPrint(t, from, to, edits, "delete-and-insert")
50 })
51 t.Run("insert-one", func(t *testing.T) {
52 t.Parallel()
53 const from = "Hello, world!\n"
54 const to = "Hello, world!\nGoodbye, world!\n"
55 edits := diffmyers.Diff(
56 splitLines(from),
57 splitLines(to),
58 )
59 assert.Equal(t, edits, []diffmyers.Edit{
60 {
61 Kind: diffmyers.EditKindInsert,
62 FromPosition: 1,
63 ToPosition: 1,
64 },
65 })
66 testPrint(t, from, to, edits, "insert")
67 })
68 t.Run("delete-one", func(t *testing.T) {
69 t.Parallel()
70 const from = "Hello, world!\nGoodbye, world!\n"
71 const to = "Hello, world!\n"
72 edits := diffmyers.Diff(
73 splitLines(from),
74 splitLines(to),
75 )
76 assert.Equal(t, edits, []diffmyers.Edit{
77 {
78 Kind: diffmyers.EditKindDelete,
79 FromPosition: 1,
80 },
81 })
82 testPrint(t, from, to, edits, "delete")
83 })
84 t.Run("create-file", func(t *testing.T) {
85 t.Parallel()
86 const from = ""
87 const to = "Hello, world!\n"

Callers

nothing calls this directly

Calls 6

DiffFunction · 0.92
PrintFunction · 0.92
splitLinesFunction · 0.85
testPrintFunction · 0.85
LenMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…