-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation_test.go
More file actions
59 lines (49 loc) · 1.36 KB
/
validation_test.go
File metadata and controls
59 lines (49 loc) · 1.36 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
package cfg_test
import (
"testing"
"github.com/zpatrick/cfg"
"github.com/zpatrick/testx/assert"
)
func TestBetween(t *testing.T) {
assert.Error(t, cfg.Between(0, 2).Validate(-1))
assert.NilError(t, cfg.Between(0, 2).Validate(0))
assert.NilError(t, cfg.Between(0, 2).Validate(1))
assert.NilError(t, cfg.Between(0, 2).Validate(2))
assert.Error(t, cfg.Between(0, 2).Validate(3))
}
func TestOneOf(t *testing.T) {
assert.Error(t, cfg.OneOf[int]().Validate(0))
assert.Error(t, cfg.OneOf(1, 2, 3).Validate(0))
assert.NilError(t, cfg.OneOf(1, 2, 3).Validate(1))
assert.NilError(t, cfg.OneOf(1, 2, 3).Validate(2))
assert.NilError(t, cfg.OneOf(1, 2, 3).Validate(3))
assert.Error(t, cfg.OneOf(1, 2, 3).Validate(4))
}
func TestAnd(t *testing.T) {
assert.NilError(t, cfg.And(
cfg.Between(0, 100),
cfg.Between(0, 50),
).Validate(49))
assert.Error(t, cfg.And(
cfg.Between(0, 100),
cfg.Between(0, 50),
).Validate(51))
}
func TestOr(t *testing.T) {
assert.NilError(t, cfg.Or(
cfg.Between(0, 100),
cfg.Between(0, 50),
).Validate(51))
assert.NilError(t, cfg.Or(
cfg.Between(0, 50),
cfg.Between(0, 100),
).Validate(51))
assert.Error(t, cfg.Or(
cfg.Between(0, 100),
cfg.Between(0, 50),
).Validate(101))
}
func TestNot(t *testing.T) {
assert.NilError(t, cfg.Not(cfg.OneOf(1, 2, 3)).Validate(0))
assert.Error(t, cfg.Not(cfg.OneOf(1, 2, 3)).Validate(1))
}