MCPcopy Create free account
hub / github.com/sergi/go-diff / TestPatchAddContext

Function TestPatchAddContext

diffmatchpatch/patch_test.go:121–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

119}
120
121func TestPatchAddContext(t *testing.T) {
122 type TestCase struct {
123 Name string
124
125 Patch string
126 Text string
127
128 Expected string
129 }
130
131 dmp := New()
132 dmp.PatchMargin = 4
133
134 for i, tc := range []TestCase{
135 {"Simple case", "@@ -21,4 +21,10 @@\n-jump\n+somersault\n", "The quick brown fox jumps over the lazy dog.", "@@ -17,12 +17,18 @@\n fox \n-jump\n+somersault\n s ov\n"},
136 {"Not enough trailing context", "@@ -21,4 +21,10 @@\n-jump\n+somersault\n", "The quick brown fox jumps.", "@@ -17,10 +17,16 @@\n fox \n-jump\n+somersault\n s.\n"},
137 {"Not enough leading context", "@@ -3 +3,2 @@\n-e\n+at\n", "The quick brown fox jumps.", "@@ -1,7 +1,8 @@\n Th\n-e\n+at\n qui\n"},
138 {"Ambiguity", "@@ -3 +3,2 @@\n-e\n+at\n", "The quick brown fox jumps. The quick brown fox crashes.", "@@ -1,27 +1,28 @@\n Th\n-e\n+at\n quick brown fox jumps. \n"},
139 } {
140 patches, err := dmp.PatchFromText(tc.Patch)
141 assert.Nil(t, err)
142
143 actual := dmp.PatchAddContext(patches[0], tc.Text)
144 assert.Equal(t, tc.Expected, actual.String(), fmt.Sprintf("Test case #%d, %s", i, tc.Name))
145 }
146}
147
148func TestPatchMakeAndPatchToText(t *testing.T) {
149 type TestCase struct {

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
PatchFromTextMethod · 0.80
PatchAddContextMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…