-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_test.go
More file actions
101 lines (81 loc) · 2.09 KB
/
Copy pathassert_test.go
File metadata and controls
101 lines (81 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ctrl
import (
"testing"
"github.com/stretchr/testify/suite"
)
type AssertTestSuite struct {
suite.Suite
}
func TestAssertSuite(t *testing.T) {
suite.Run(t, new(AssertTestSuite))
}
func (s *AssertTestSuite) TestAssert() {
s.NotPanics(func() {
Assert(true)
})
s.PanicsWithValue("assertion failed", func() {
Assert(false)
})
}
func (s *AssertTestSuite) TestAssertf() {
s.NotPanics(func() {
Assertf(true, "this should not panic")
})
msg := "test message"
s.PanicsWithValue("assertion failed: "+msg, func() {
Assertf(false, msg)
})
s.PanicsWithValue("assertion failed: value is 42", func() {
Assertf(false, "value is %d", 42)
})
}
func (s *AssertTestSuite) TestAssertFunc() {
s.NotPanics(func() {
AssertFunc(func() bool { return true })
})
s.PanicsWithValue("assertion failed", func() {
AssertFunc(func() bool { return false })
})
counter := 0
s.NotPanics(func() {
AssertFunc(func() bool {
counter++
return counter > 0
})
})
}
func (s *AssertTestSuite) TestAssertFuncf() {
s.NotPanics(func() {
AssertFuncf(func() bool { return true }, "this should not panic")
})
msg := "custom func message"
s.PanicsWithValue("assertion failed: "+msg, func() {
AssertFuncf(func() bool { return false }, msg)
})
s.PanicsWithValue("assertion failed: value is 42", func() {
AssertFuncf(func() bool { return false }, "value is %d", 42)
})
}
// Additional test for complex formatting scenarios
func (s *AssertTestSuite) TestComplexFormatting() {
type testStruct struct {
Name string
Value int
}
test := testStruct{Name: "test", Value: 42}
s.PanicsWithValue("assertion failed: struct value - Name: test, Value: 42", func() {
Assertf(false, "struct value - Name: %s, Value: %d", test.Name, test.Value)
})
s.PanicsWithValue("assertion failed: multiple values: 1, 2, 3", func() {
Assertf(false, "multiple values: %d, %d, %d", 1, 2, 3)
})
}
// Test boundary cases
func (s *AssertTestSuite) TestBoundaryCases() {
s.PanicsWithValue("assertion failed: ", func() {
Assertf(false, "")
})
s.PanicsWithValue("assertion failed: test", func() {
Assertf(false, "test")
})
}