Newer
Older
package errcore
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
import (
"fmt"
"strings"
"gitlab.com/evatix-go/core/constants"
)
type ExpectationMessageDef struct {
CaseIndex int
FuncName string
TestCaseName string
When string
Expected interface{}
ActualProcessed interface{}
ExpectedProcessed interface{}
IsNonWhiteSort bool
expectedString *string
}
func (it ExpectationMessageDef) ExpectedSafeString() string {
if it.expectedString != nil {
return *it.expectedString
}
var expectedStr string
if it.Expected != nil {
expectedStr = fmt.Sprintf(
constants.SprintValueFormat,
it.Expected)
}
it.expectedString = &expectedStr
return *it.expectedString
}
func (it ExpectationMessageDef) ExpectedStringTrim() string {
return strings.TrimSpace(it.ExpectedString())
}
func (it ExpectationMessageDef) ExpectedString() string {
if it.Expected == nil {
panic("ExpectationMessageDef! Expected needs to be set before getting it!")
}
return it.ExpectedSafeString()
}
func (it ExpectationMessageDef) ToString(actual interface{}) string {
return GetWhenActualAndExpectProcessedMessage(
actual,
&it)
}
func (it ExpectationMessageDef) PrintIf(
isPrint bool,
actual interface{},
) {
if !isPrint {
return
}
it.Print(actual)
}
func (it ExpectationMessageDef) PrintIfFailed(
isPrintOnFail,
isFailed bool,
actual interface{},
) {
if isPrintOnFail && isFailed {
it.Print(actual)
}
}
func (it ExpectationMessageDef) Print(actual interface{}) {
msg := MsgHeaderPlusEnding(
it.When,
it.ToString(actual))
fmt.Println(msg)
}