Skip to content

Commit da9bdb2

Browse files
gnarlexPaddy
authored andcommitted
Add tests for diag func wrapper
1 parent 234f9e6 commit da9bdb2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

helper/validation/meta_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,38 @@ func TestValidationAny(t *testing.T) {
9999
},
100100
})
101101
}
102+
103+
func TestToDiagFunc(t *testing.T) {
104+
runDiagTestCases(t, []diagTestCase{
105+
{
106+
val: 43,
107+
f: ToDiagFunc(Any(
108+
IntAtLeast(42),
109+
IntAtMost(5),
110+
)),
111+
},
112+
{
113+
val: "foo",
114+
f: ToDiagFunc(All(
115+
StringLenBetween(1, 10),
116+
StringIsNotWhiteSpace,
117+
)),
118+
},
119+
{
120+
val: 7,
121+
f: ToDiagFunc(Any(
122+
IntAtLeast(42),
123+
IntAtMost(5),
124+
)),
125+
expectedErr: regexp.MustCompile("expected [\\w]+ to be at least \\(42\\), got 7"),
126+
},
127+
{
128+
val: 7,
129+
f: ToDiagFunc(Any(
130+
IntAtLeast(42),
131+
IntAtMost(5),
132+
)),
133+
expectedErr: regexp.MustCompile("expected [\\w]+ to be at most \\(5\\), got 7"),
134+
},
135+
})
136+
}

0 commit comments

Comments
 (0)