-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.go
42 lines (34 loc) · 911 Bytes
/
types.go
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
package assert
import (
"fmt"
"strings"
)
// Config is used to configure the behavior of the assertion library.
type Config struct {
// IncludeSource determines if source context is included in errors.
//
// Default: true
IncludeSource bool
// ContextLines determines how many lines of context to show.
//
// Default: 5
ContextLines int
}
// Assert is the main assertion function. It panics if the condition is false.
type AssertionError struct {
Message string
File string
SourceContext string
Line int
}
// Error returns the error message.
func (e AssertionError) Error() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("Assertion failed at %s:%d\n", e.File, e.Line))
sb.WriteString(fmt.Sprintf("Message: %s\n", e.Message))
if e.SourceContext != "" {
sb.WriteString("Source context:\n")
sb.WriteString(e.SourceContext)
}
return sb.String()
}