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

Function TestDiffMain

diffmatchpatch/diff_test.go:1274–1407  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1272}
1273
1274func TestDiffMain(t *testing.T) {
1275 type TestCase struct {
1276 Text1 string
1277 Text2 string
1278
1279 Expected []Diff
1280 }
1281
1282 dmp := New()
1283
1284 // Perform a trivial diff.
1285 for i, tc := range []TestCase{
1286 {
1287 "",
1288 "",
1289 nil,
1290 },
1291 {
1292 "abc",
1293 "abc",
1294 []Diff{Diff{DiffEqual, "abc"}},
1295 },
1296 {
1297 "abc",
1298 "ab123c",
1299 []Diff{Diff{DiffEqual, "ab"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "c"}},
1300 },
1301 {
1302 "a123bc",
1303 "abc",
1304 []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "bc"}},
1305 },
1306 {
1307 "abc",
1308 "a123b456c",
1309 []Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "b"}, Diff{DiffInsert, "456"}, Diff{DiffEqual, "c"}},
1310 },
1311 {
1312 "a123b456c",
1313 "abc",
1314 []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "b"}, Diff{DiffDelete, "456"}, Diff{DiffEqual, "c"}},
1315 },
1316 } {
1317 actual := dmp.DiffMain(tc.Text1, tc.Text2, false)
1318 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
1319 }
1320
1321 // Perform a real diff and switch off the timeout.
1322 dmp.DiffTimeout = 0
1323
1324 for i, tc := range []TestCase{
1325 {
1326 "a",
1327 "b",
1328 []Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}},
1329 },
1330 {
1331 "Apples are a fruit.",

Callers

nothing calls this directly

Calls 2

NewFunction · 0.85
DiffMainMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…