-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptr_test.go
46 lines (39 loc) · 811 Bytes
/
ptr_test.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
43
44
45
46
package buzz
import (
"fmt"
"reflect"
"testing"
)
func Test_PtrType(t *testing.T) {
str := ""
if Ptr(String()).Type() != reflect.TypeOf(&str) {
t.FailNow()
}
}
func Test_PtrValidate(t *testing.T) {
str := "[email protected]"
if err := Ptr(String().Email()).Nonnil().Validate(&str); err != nil {
t.FailNow()
}
}
func Test_PtrValidateNull(t *testing.T) {
if err := Ptr(String().Email()).Validate(nil); err != nil {
t.Error(err)
t.FailNow()
}
}
func Test_PtrValidateNullWithType(t *testing.T) {
var str *string
if err := Ptr(String().Email()).Validate(str); err != nil {
t.FailNow()
}
}
func Test_PtrInvalidTypeError(t *testing.T) {
i := new(int)
*i = 10
err := Ptr(String()).Validate(i)
if err.Error() != fmt.Sprintf(invalidTypeMsg, "*string", i) {
t.Log(err)
t.FailNow()
}
}