File tree 3 files changed +59
-1
lines changed
3 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,28 @@ func DeepEqual(expect interface{}) CheckFunc {
261
261
}
262
262
}
263
263
264
+ // NotCompareEqual returns a check function that fails when the test value
265
+ // compare equals to reject.
266
+ func NotCompareEqual (reject interface {}) CheckFunc {
267
+ return func (got interface {}) error {
268
+ if reject == got {
269
+ return FailReject (msgNotCompareEqual , got , reject )
270
+ }
271
+ return nil
272
+ }
273
+ }
274
+
275
+ // CompareEqual returns a check function that fails when the test value does not
276
+ // compare equals to expect.
277
+ func CompareEqual (expect interface {}) CheckFunc {
278
+ return func (got interface {}) error {
279
+ if expect != got {
280
+ return FailExpect (msgCompareEqual , got , expect )
281
+ }
282
+ return nil
283
+ }
284
+ }
285
+
264
286
// NotReflectNil returns a check function that fails when the test value is
265
287
// either an untyped nil value or reflects to a pointer with a nil value.
266
288
func NotReflectNil () CheckFunc {
Original file line number Diff line number Diff line change 1
1
package subtest
2
2
3
- import "fmt"
3
+ import (
4
+ "fmt"
5
+ )
4
6
5
7
// OnFloat64 returns a check function where the test value is converted to
6
8
// float64 before it's passed to c.
@@ -52,3 +54,13 @@ func OnIndex(i int, c Check) CheckFunc {
52
54
return nil
53
55
}
54
56
}
57
+
58
+ // Iterate runs the first check on index 0, the second on index 1 etc, and
59
+ // returns an aggregated error.
60
+ func Iterate (cs ... Check ) Check {
61
+ all := make (AllOf , 0 , len (cs ))
62
+ for i , c := range cs {
63
+ all = append (all , OnIndex (i , c ))
64
+ }
65
+ return all
66
+ }
Original file line number Diff line number Diff line change 1
1
package subjson
2
2
3
3
import (
4
+ "encoding/json"
5
+
4
6
"github.com/clarify/subtest"
5
7
)
6
8
9
+ // Fields is a short-hand for OnMap(subtest.Fields{...})
10
+ type Fields subtest.Fields
11
+
12
+ // Check validates the json decoded vf against m, expecting vf to return a json
13
+ // map.
14
+ func (m Fields ) Check (vf subtest.ValueFunc ) error {
15
+ return OnMap (subtest .Fields (m )).Check (vf )
16
+ }
17
+
18
+ // RawEqual is a short-hand for subtest.DeepEqual(json.RawMessage(s))
19
+ type RawEqual []byte
20
+
21
+ // Check validates the raw json equals m.
22
+ func (m RawEqual ) Check (vf subtest.ValueFunc ) error {
23
+ return subtest .DeepEqual (json .RawMessage (m )).Check (vf )
24
+ }
25
+
26
+ // IterateSlice is a short-hand for OnSlice(subtest.Iterate(cs...))
27
+ func IterateSlice (cs ... subtest.Check ) subtest.Check {
28
+ return OnSlice (subtest .Iterate (cs ... ))
29
+ }
30
+
7
31
// LessThan is a short-hand for OnNumber(subtest.LessThan(expect)).
8
32
func LessThan (expect float64 ) subtest.CheckFunc {
9
33
return OnNumber (subtest .LessThan (expect ))
You can’t perform that action at this time.
0 commit comments