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

Function TestDiffMain

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

Source from the content-addressed store, hash-verified

1300}
1301
1302func TestDiffMain(t *testing.T) {
1303 type TestCase struct {
1304 Text1 string
1305 Text2 string
1306
1307 Expected []Diff
1308 }
1309
1310 dmp := New()
1311
1312 // Perform a trivial diff.
1313 for i, tc := range []TestCase{
1314 {
1315 "",
1316 "",
1317 nil,
1318 },
1319 {
1320 "abc",
1321 "abc",
1322 []Diff{Diff{DiffEqual, "abc"}},
1323 },
1324 {
1325 "abc",
1326 "ab123c",
1327 []Diff{Diff{DiffEqual, "ab"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "c"}},
1328 },
1329 {
1330 "a123bc",
1331 "abc",
1332 []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "bc"}},
1333 },
1334 {
1335 "abc",
1336 "a123b456c",
1337 []Diff{Diff{DiffEqual, "a"}, Diff{DiffInsert, "123"}, Diff{DiffEqual, "b"}, Diff{DiffInsert, "456"}, Diff{DiffEqual, "c"}},
1338 },
1339 {
1340 "a123b456c",
1341 "abc",
1342 []Diff{Diff{DiffEqual, "a"}, Diff{DiffDelete, "123"}, Diff{DiffEqual, "b"}, Diff{DiffDelete, "456"}, Diff{DiffEqual, "c"}},
1343 },
1344 } {
1345 actual := dmp.DiffMain(tc.Text1, tc.Text2, false)
1346 assert.Equal(t, tc.Expected, actual, fmt.Sprintf("Test case #%d, %#v", i, tc))
1347 }
1348
1349 // Perform a real diff and switch off the timeout.
1350 dmp.DiffTimeout = 0
1351
1352 for i, tc := range []TestCase{
1353 {
1354 "a",
1355 "b",
1356 []Diff{Diff{DiffDelete, "a"}, Diff{DiffInsert, "b"}},
1357 },
1358 {
1359 "Apples are a fruit.",

Callers

nothing calls this directly

Calls 2

NewFunction · 0.85
DiffMainMethod · 0.80

Tested by

no test coverage detected