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

Function TestPatchMakeAndPatchToText

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

Source from the content-addressed store, hash-verified

146}
147
148func TestPatchMakeAndPatchToText(t *testing.T) {
149 type TestCase struct {
150 Name string
151
152 Input1 interface{}
153 Input2 interface{}
154 Input3 interface{}
155
156 Expected string
157 }
158
159 dmp := New()
160
161 text1 := "The quick brown fox jumps over the lazy dog."
162 text2 := "That quick brown fox jumped over a lazy dog."
163
164 for i, tc := range []TestCase{
165 {"Null case", "", "", nil, ""},
166 {"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"},
167 {"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"},
168 {"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"},
169 {"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"},
170 {"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"},
171 {"Character encoding", "`1234567890-=[]\\;',./", "~!@#$%^&*()_+{}|:\"<>?", nil, "@@ -1,21 +1,21 @@\n-%601234567890-=%5B%5D%5C;',./\n+~!@#$%25%5E&*()_+%7B%7D%7C:%22%3C%3E?\n"},
172 {"Long string with repeats", strings.Repeat("abcdef", 100), strings.Repeat("abcdef", 100) + "123", nil, "@@ -573,28 +573,31 @@\n cdefabcdefabcdefabcdefabcdef\n+123\n"},
173 {"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"},
174 } {
175 var patches []Patch
176 if tc.Input3 != nil {
177 patches = dmp.PatchMake(tc.Input1, tc.Input2, tc.Input3)
178 } else if tc.Input2 != nil {
179 patches = dmp.PatchMake(tc.Input1, tc.Input2)
180 } else if ps, ok := tc.Input1.([]Patch); ok {
181 patches = ps
182 } else {
183 patches = dmp.PatchMake(tc.Input1)
184 }
185
186 actual := dmp.PatchToText(patches)
187 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %s", i, tc.Name))
188 }
189
190 // Corner case of #28 wrong patch with timeout of 0
191 dmp.DiffTimeout = 0
192
193 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."
194 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."
195
196 diffs := dmp.DiffMain(text1, text2, true)
197 // Additional check that the diff texts are equal to the originals even if we are using DiffMain with checklines=true #29
198 assert.Equal(t, text1, dmp.DiffText1(diffs))
199 assert.Equal(t, text2, dmp.DiffText2(diffs))
200
201 patches := dmp.PatchMake(text1, diffs)
202
203 actual := dmp.PatchToText(patches)
204 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)
205

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…