Skip to content

Commit 2e246ae

Browse files
committed
switched to a different assert package
1 parent 29b9f95 commit 2e246ae

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

diff/dmp_test.go

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,9 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/bmizerany/assert"
12+
"github.com/stretchrcom/testify/assert"
1313
)
1414

15-
func softAssert(t *testing.T, cond bool, msg string) {
16-
if !cond {
17-
print("assertion fail: ", msg, "\n")
18-
panic(1)
19-
}
20-
}
21-
2215
func caller() string {
2316
if _, _, line, ok := runtime.Caller(2); ok {
2417
return fmt.Sprintf("(actual-line %v) ", line)
@@ -79,13 +72,15 @@ func assertMapEqual(t *testing.T, seq1, seq2 interface{}) {
7972
func assertDiffEqual(t *testing.T, seq1, seq2 []Diff) {
8073
if a, b := len(seq1), len(seq2); a != b {
8174
t.Errorf("%v\nseq1:\n%v\nseq2:\n%v", caller(), pretty(seq1), pretty(seq2))
82-
t.Fatalf("%v Sequences of different length: %v != %v", caller(), a, b)
75+
t.Errorf("%v Sequences of different length: %v != %v", caller(), a, b)
76+
return
8377
}
8478

8579
for i := range seq1 {
8680
if a, b := seq1[i], seq2[i]; a != b {
8781
t.Errorf("%v\nseq1:\n%v\nseq2:\n%v", caller(), pretty(seq1), pretty(seq2))
88-
t.Fatalf("%v %v != %v", caller(), a, b)
82+
t.Errorf("%v %v != %v", caller(), a, b)
83+
return
8984
}
9085
}
9186
}
@@ -166,8 +161,8 @@ func Test_diffHalfmatchTest(t *testing.T) {
166161
dmp := New()
167162
dmp.DiffTimeout = 1
168163
// No match.
169-
softAssert(t, dmp.DiffHalfMatch("1234567890", "abcdef") == nil, "")
170-
softAssert(t, dmp.DiffHalfMatch("12345", "23") == nil, "")
164+
assert.True(t, dmp.DiffHalfMatch("1234567890", "abcdef") == nil, "")
165+
assert.True(t, dmp.DiffHalfMatch("12345", "23") == nil, "")
171166

172167
// Single Match.
173168
assertStrEqual(t,
@@ -193,7 +188,7 @@ func Test_diffHalfmatchTest(t *testing.T) {
193188

194189
// Optimal no halfmatch.
195190
dmp.DiffTimeout = 0
196-
softAssert(t, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy") == nil, "")
191+
assert.True(t, dmp.DiffHalfMatch("qHilloHelloHew", "xHelloHeHulloy") == nil, "")
197192
}
198193

199194
func Test_diffLinesToChars(t *testing.T) {
@@ -703,13 +698,13 @@ func Test_diffDelta(t *testing.T) {
703698
// Generates error (19 < 20).
704699
_, err = dmp.DiffFromDelta(text1+"x", delta)
705700
if err == nil {
706-
panic(1) //assert.Fail("diff_fromDelta: Too long.");
701+
t.Fatal("diff_fromDelta: Too long.")
707702
}
708703

709704
// Generates error (19 > 18).
710705
_, err = dmp.DiffFromDelta(text1[1:], delta)
711706
if err == nil {
712-
panic(1) //assert.Fail("diff_fromDelta: Too short.");
707+
t.Fatal("diff_fromDelta: Too short.")
713708
}
714709

715710
// Generates error (%c3%xy invalid Unicode).
@@ -880,7 +875,12 @@ func Test_diffMain(t *testing.T) {
880875
Diff{DiffDelete, "EFGHIJKLMNOefg"}}
881876
assertDiffEqual(t, diffs, dmp.DiffMain("ABCDa=bcd=efghijklmnopqrsEFGHIJKLMNOefg", "a-bcd-efghijklmnopqrs", false))
882877

883-
diffs = []Diff{Diff{DiffInsert, " "}, Diff{DiffEqual, "a"}, Diff{DiffInsert, "nd"}, Diff{DiffEqual, " [[Pennsylvania]]"}, Diff{DiffDelete, " and [[New"}}
878+
diffs = []Diff{
879+
Diff{DiffInsert, " "},
880+
Diff{DiffEqual, "a"},
881+
Diff{DiffInsert, "nd"},
882+
Diff{DiffEqual, " [[Pennsylvania]]"},
883+
Diff{DiffDelete, " and [[New"}}
884884
assertDiffEqual(t, diffs, dmp.DiffMain("a [[Pennsylvania]] and [[New", " and [[Pennsylvania]]", false))
885885

886886
dmp.DiffTimeout = 0.1 // 100ms
@@ -897,11 +897,11 @@ func Test_diffMain(t *testing.T) {
897897
endTime := time.Now().Unix()
898898
endTime *= 1000
899899
// Test that we took at least the timeout period.
900-
softAssert(t, dmp.DiffTimeout*1000 <= float64(endTime-startTime), "")
900+
assert.True(t, dmp.DiffTimeout*1000 <= float64(endTime-startTime), "")
901901
// Test that we didn't take forever (be forgiving).
902902
// Theoretically this test could fail very occasionally if the
903903
// OS task swaps or locks up for a second at the wrong moment.
904-
softAssert(t, dmp.DiffTimeout*1000*2 > float64(endTime-startTime), "")
904+
assert.True(t, dmp.DiffTimeout*1000*2 > float64(endTime-startTime), "")
905905
dmp.DiffTimeout = 0
906906

907907
// Test the linemode speedup.
@@ -1034,7 +1034,7 @@ func Test_patch_fromText(t *testing.T) {
10341034
dmp := New()
10351035

10361036
_v1, _ := dmp.PatchFromText("")
1037-
softAssert(t, len(_v1) == 0, "patch_fromText: #0.")
1037+
assert.True(t, len(_v1) == 0, "patch_fromText: #0.")
10381038
strp := "@@ -21,18 +22,17 @@\n jump\n-s\n+ed\n over \n-the\n+a\n %0Alaz\n"
10391039
_v2, _ := dmp.PatchFromText(strp)
10401040
assert.Equal(t, strp, _v2[0].String(), "patch_fromText: #1.")
@@ -1050,7 +1050,7 @@ func Test_patch_fromText(t *testing.T) {
10501050

10511051
// Generates error.
10521052
_, err := dmp.PatchFromText("Bad\nPatch\n")
1053-
softAssert(t, err != nil, "There should be an error")
1053+
assert.True(t, err != nil, "There should be an error")
10541054
}
10551055

10561056
func Test_patch_toText(t *testing.T) {
@@ -1172,9 +1172,13 @@ func Test_PatchAddPadding(t *testing.T) {
11721172
dmp := New()
11731173
var patches []Patch
11741174
patches = dmp.PatchMake("", "test")
1175-
assert.Equal(t, "@@ -0,0 +1,4 @@\n+test\n",
1175+
pass := assert.Equal(t, "@@ -0,0 +1,4 @@\n+test\n",
11761176
dmp.PatchToText(patches),
11771177
"PatchAddPadding: Both edges full.")
1178+
if !pass {
1179+
t.FailNow()
1180+
}
1181+
11781182
dmp.PatchAddPadding(patches)
11791183
assert.Equal(t, "@@ -1,8 +1,12 @@\n %01%02%03%04\n+test\n %01%02%03%04\n",
11801184
dmp.PatchToText(patches),
@@ -1209,7 +1213,10 @@ func Test_patchApply(t *testing.T) {
12091213
results0, results1 := dmp.PatchApply(patches, "Hello world.")
12101214
boolArray := results1
12111215
resultStr := results0 + "\t" + string(len(boolArray))
1212-
assert.Equal(t, "Hello world.\t0", resultStr, "patch_apply: Null case.")
1216+
pass := assert.Equal(t, "Hello world.\t0", resultStr, "patch_apply: Null case.")
1217+
if !pass {
1218+
t.FailNow()
1219+
}
12131220

12141221
patches = dmp.PatchMake("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.")
12151222
results0, results1 = dmp.PatchApply(patches, "The quick brown fox jumps over the lazy dog.")

0 commit comments

Comments
 (0)