/
td_ignore.go
48 lines (40 loc) · 1.06 KB
/
td_ignore.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
// Copyright (c) 2018, Maxime Soulé
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
package td
import (
"reflect"
"github.com/maxatome/go-testdeep/internal/ctxerr"
)
type tdIgnore struct {
baseOKNil
}
// summary(Ignore): allows to ignore a comparison
// input(Ignore): all
// Ignore operator is always true, whatever data is. It is useful when
// comparing a slice with [Slice] and wanting to ignore some indexes,
// for example (if you don't want to use [SuperSliceOf]). Or comparing
// a struct with [SStruct] and wanting to ignore some fields:
//
// td.Cmp(t, got, td.SStruct(
// Person{
// Name: "John Doe",
// },
// td.StructFields{
// Age: td.Between(40, 45),
// Children: td.Ignore(),
// }),
// )
func Ignore() TestDeep {
return &tdIgnore{
baseOKNil: newBaseOKNil(3),
}
}
func (i *tdIgnore) Match(ctx ctxerr.Context, got reflect.Value) *ctxerr.Error {
return nil
}
func (i *tdIgnore) String() string {
return "Ignore()"
}