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

Function TestPatchAddContext

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

Source from the content-addressed store, hash-verified

125}
126
127func TestPatchAddContext(t *testing.T) {
128 type TestCase struct {
129 Name string
130
131 Patch string
132 Text string
133
134 Expected string
135 }
136
137 dmp := New()
138 dmp.PatchMargin = 4
139
140 for i, tc := range []TestCase{
141 {"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"},
142 {"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"},
143 {"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"},
144 {"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"},
145 } {
146 patches, err := dmp.PatchFromText(tc.Patch)
147 assert.Nil(t, err)
148
149 actual := dmp.PatchAddContext(patches[0], tc.Text)
150 assert.Equal(t, tc.Expected, actual.String(), fmt.Sprintf("Test case #%d, %s", i, tc.Name))
151 }
152}
153
154func TestPatchMakeAndPatchToText(t *testing.T) {
155 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