-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator_utils.go
67 lines (59 loc) · 1.35 KB
/
validator_utils.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package astjson
import (
"errors"
"fmt"
)
func ShouldEqualTrue() Validator {
return func(value *Value) error {
if !IsBool(value) {
return fmt.Errorf("value should be an bool type: %s", value)
}
if !GetBool(value) {
return errors.New("value should be true")
}
return nil
}
}
func ShouldEqualFalse() Validator {
return func(value *Value) error {
if !IsBool(value) {
return fmt.Errorf("value should be an bool type: %s", value)
}
if GetBool(value) {
return errors.New("value should be false")
}
return nil
}
}
func ShouldEqualString(str string) Validator {
return func(value *Value) error {
if !IsString(value) {
return fmt.Errorf("value should be a stirng type: %s", value)
}
actual := GetString(value)
if actual != str {
return fmt.Errorf("value is %s, not equal with expected value is %s", actual, str)
}
return nil
}
}
func ShouldNotEqualString(str string) Validator {
return func(value *Value) error {
if !IsString(value) {
return fmt.Errorf("value should be a stirng type: %s", value)
}
actual := GetString(value)
if actual == str {
return fmt.Errorf("value is %s, equal with expected value", str)
}
return nil
}
}
func ShouldEqualNull() Validator {
return func(value *Value) error {
if !IsNull(value) {
return fmt.Errorf("value should be a null type: %s", value)
}
return nil
}
}