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

Function TestPatchMakeAndPatchToText

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

Source from the content-addressed store, hash-verified

152}
153
154func TestPatchMakeAndPatchToText(t *testing.T) {
155 type TestCase struct {
156 Name string
157
158 Input1 interface{}
159 Input2 interface{}
160 Input3 interface{}
161
162 Expected string
163 }
164
165 dmp := New()
166
167 text1 := "The quick brown fox jumps over the lazy dog."
168 text2 := "That quick brown fox jumped over a lazy dog."
169
170 for i, tc := range []TestCase{
171 {"Null case", "", "", nil, ""},
172 {"Text2+Text1 inputs", text2, text1, nil, "@@ -1,8 +1,7 @@\n Th\n-at\n+e\n qui\n@@ -21,17 +21,18 @@\n jump\n-ed\n+s\n over \n-a\n+the\n laz\n"},
173 {"Text1+Text2 inputs", text1, text2, nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"},
174 {"Diff input", dmp.DiffMain(text1, text2, false), nil, nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"},
175 {"Text1+Diff inputs", text1, dmp.DiffMain(text1, text2, false), nil, "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"},
176 {"Text1+Text2+Diff inputs (deprecated)", text1, text2, dmp.DiffMain(text1, text2, false), "@@ -1,11 +1,12 @@\n Th\n-e\n+at\n quick b\n@@ -22,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n laz\n"},
177 {"Character encoding", "`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?", nil, "@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n"},
178 {"Long string with repeats", strings.Repeat("abcdef", 100), strings.Repeat("abcdef", 100) + "123", nil, "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"},
179 {"Corner case of #31 fixed by #32", "2016-09-01T03:07:14.807830741Z", "2016-09-01T03:07:15.154800781Z", nil, "@@ -15,16 +15,16 @@\n 07:1\n+5.15\n 4\n-.\n 80\n+0\n 78\n-3074\n 1Z\n"},
180 } {
181 var patches []Patch
182 if tc.Input3 != nil {
183 patches = dmp.PatchMake(tc.Input1, tc.Input2, tc.Input3)
184 } else if tc.Input2 != nil {
185 patches = dmp.PatchMake(tc.Input1, tc.Input2)
186 } else if ps, ok := tc.Input1.([]Patch); ok {
187 patches = ps
188 } else {
189 patches = dmp.PatchMake(tc.Input1)
190 }
191
192 actual := dmp.PatchToText(patches)
193 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
194 }
195
196 // Corner case of #28 wrong patch with timeout of 0
197 dmp.DiffTimeout = 0
198
199 text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum libero vel."
200 text2 = "Lorem a ipsum dolor sit amet, consectetur adipiscing elit. Vivamus ut risus et enim consectetur convallis a non ipsum. Sed nec nibh cursus, interdum liberovel."
201
202 diffs := dmp.DiffMain(text1, text2, true)
203 // Additional check that the diff texts are equal to the originals even if we are using DiffMain with checklines=true #29
204 assert.Equal(t, text1, dmp.DiffText1(diffs))
205 assert.Equal(t, text2, dmp.DiffText2(diffs))
206
207 patches := dmp.PatchMake(text1, diffs)
208
209 actual := dmp.PatchToText(patches)
210 assert.Equal(t, "@@ -1,14 +1,16 @@\n Lorem \n+a \n ipsum do\n@@ -148,13 +148,12 @@\n m libero\n- \n vel.\n", actual)
211

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
DiffMainMethod · 0.80
PatchMakeMethod · 0.80
PatchToTextMethod · 0.80
DiffText1Method · 0.80
DiffText2Method · 0.80

Tested by

no test coverage detected