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

Function TestDiffMainWithTimeout

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

Source from the content-addressed store, hash-verified

1435}
1436
1437func TestDiffMainWithTimeout(t *testing.T) {
1438 dmp := New()
1439 dmp.DiffTimeout = 200 * time.Millisecond
1440
1441 a := "`Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.\n"
1442 b := "I am the very model of a modern major general,\nI've information vegetable, animal, and mineral,\nI know the kings of England, and I quote the fights historical,\nFrom Marathon to Waterloo, in order categorical.\n"
1443 // Increase the text lengths by 1024 times to ensure a timeout.
1444 for x := 0; x < 13; x++ {
1445 a = a + a
1446 b = b + b
1447 }
1448
1449 startTime := time.Now()
1450 dmp.DiffMain(a, b, true)
1451 endTime := time.Now()
1452
1453 delta := endTime.Sub(startTime)
1454
1455 // Test that we took at least the timeout period.
1456 assert.True(t, delta >= dmp.DiffTimeout, fmt.Sprintf("%v !>= %v", delta, dmp.DiffTimeout))
1457
1458 // Test that we didn't take forever (be very forgiving). Theoretically this test could fail very occasionally if the OS task swaps or locks up for a second at the wrong moment.
1459 assert.True(t, delta < (dmp.DiffTimeout*100), fmt.Sprintf("%v !< %v", delta, dmp.DiffTimeout*100))
1460}
1461
1462func TestDiffMainWithCheckLines(t *testing.T) {
1463 type TestCase struct {

Callers

nothing calls this directly

Calls 2

NewFunction · 0.85
DiffMainMethod · 0.80

Tested by

no test coverage detected