| 1 |
// Copyright (c) 2018, Maxime Soulé |
| 2 |
// All rights reserved. |
| 3 |
// |
| 4 |
// This source code is licensed under the BSD-style license found in the |
| 5 |
// LICENSE file in the root directory of this source tree. |
| 6 |
|
| 7 |
package td |
| 8 |
|
| 9 |
import ( |
| 10 |
"reflect" |
| 11 |
|
| 12 |
"github.com/maxatome/go-testdeep/internal/ctxerr" |
| 13 |
) |
| 14 |
|
| 15 |
type tdIgnore struct { |
| 16 |
baseOKNil |
| 17 |
} |
| 18 |
|
| 19 |
// summary(Ignore): allows to ignore a comparison |
| 20 |
// input(Ignore): all |
| 21 |
|
| 22 |
// Ignore operator is always true, whatever data is. It is useful when |
| 23 |
// comparing a slice with [Slice] and wanting to ignore some indexes, |
| 24 |
// for example (if you don't want to use [SuperSliceOf]). Or comparing |
| 25 |
// a struct with [SStruct] and wanting to ignore some fields: |
| 26 |
// |
| 27 |
// td.Cmp(t, got, td.SStruct( |
| 28 |
// Person{ |
| 29 |
// Name: "John Doe", |
| 30 |
// }, |
| 31 |
// td.StructFields{ |
| 32 |
// Age: td.Between(40, 45), |
| 33 |
// Children: td.Ignore(), |
| 34 |
// }), |
| 35 |
// ) |
| 36 |
func Ignore() TestDeep { |
| 37 |
return &tdIgnore{ |
| 38 |
baseOKNil: newBaseOKNil(3), |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
func (i *tdIgnore) Match(ctx ctxerr.Context, got reflect.Value) *ctxerr.Error { |
| 43 |
return nil |
| 44 |
} |
| 45 |
|
| 46 |
func (i *tdIgnore) String() string { |
| 47 |
return "Ignore()" |
| 48 |
} |