Source File
ignore.go
Belonging Package
github.com/google/go-cmp/cmp/cmpopts
package cmpopts
import (
)
func ( interface{}, ...string) cmp.Option {
:= newStructFilter(, ...)
return cmp.FilterPath(.filter, cmp.Ignore())
}
func ( ...interface{}) cmp.Option {
:= newTypeFilter(...)
return cmp.FilterPath(.filter, cmp.Ignore())
}
type typeFilter []reflect.Type
func ( ...interface{}) ( typeFilter) {
for , := range {
:= reflect.TypeOf()
func ( interface{}) cmp.Option {
:= newIfaceFilter()
return cmp.FilterPath(.filter, cmp.Ignore())
}
type ifaceFilter []reflect.Type
func ( interface{}) ( ifaceFilter) {
:= reflect.TypeOf()
if == nil || .Name() != "" || .Kind() != reflect.Struct {
panic("input must be an anonymous struct")
}
for := 0; < .NumField(); ++ {
:= .Field()
switch {
case !.Anonymous:
panic("struct cannot have named fields")
case .Type.Kind() != reflect.Interface:
panic("embedded field must be an interface type")
panic("cannot ignore empty interface")
default:
= append(, .Type)
}
}
return
}
func ( ifaceFilter) ( cmp.Path) bool {
if len() < 1 {
return false
}
:= .Last().Type()
for , := range {
if .AssignableTo() {
return true
}
if .Kind() != reflect.Ptr && reflect.PtrTo().AssignableTo() {
return true
}
}
return false
}
func ( ...interface{}) cmp.Option {
:= newUnexportedFilter(...)
return cmp.FilterPath(.filter, cmp.Ignore())
}
type unexportedFilter struct{ m map[reflect.Type]bool }
func ( ...interface{}) unexportedFilter {
:= unexportedFilter{m: make(map[reflect.Type]bool)}
for , := range {
:= reflect.TypeOf()
if == nil || .Kind() != reflect.Struct {
panic(fmt.Sprintf("%T must be a non-pointer struct", ))
}
.m[] = true
}
return
}
func ( unexportedFilter) ( cmp.Path) bool {
, := .Index(-1).(cmp.StructField)
if ! {
return false
}
return .m[.Index(-2).Type()] && !isExported(.Name())
}
func ( interface{}) cmp.Option {
:= reflect.ValueOf()
if !function.IsType(.Type(), function.ValuePredicate) || .IsNil() {
panic(fmt.Sprintf("invalid discard function: %T", ))
}
return cmp.FilterPath(func( cmp.Path) bool {
, := .Index(-1).(cmp.SliceIndex)
if ! {
return false
}
if !.Type().AssignableTo(.Type().In(0)) {
return false
}
, := .Values()
if .IsValid() && .Call([]reflect.Value{})[0].Bool() {
return true
}
if .IsValid() && .Call([]reflect.Value{})[0].Bool() {
return true
}
return false
}, cmp.Ignore())
}
func ( interface{}) cmp.Option {
:= reflect.ValueOf()
if !function.IsType(.Type(), function.KeyValuePredicate) || .IsNil() {
panic(fmt.Sprintf("invalid discard function: %T", ))
}
return cmp.FilterPath(func( cmp.Path) bool {
, := .Index(-1).(cmp.MapIndex)
if ! {
return false
}
if !.Key().Type().AssignableTo(.Type().In(0)) || !.Type().AssignableTo(.Type().In(1)) {
return false
}
:= .Key()
, := .Values()
if .IsValid() && .Call([]reflect.Value{, })[0].Bool() {
return true
}
if .IsValid() && .Call([]reflect.Value{, })[0].Bool() {
return true
}
return false
}, cmp.Ignore())
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |