MCPcopy Index your code
hub / github.com/gavv/httpexpect / InList

Method InList

value.go:834–877  ·  view source on GitHub ↗

InList succeeds if whole value is equal to one of the values from given list of values (e.g. map, slice, string, etc). Before comparison, all values are converted to canonical form. If at least one value has wrong type, failure is reported. Example: value := NewValue(t, "foo") value.InList("foo

(values ...interface{})

Source from the content-addressed store, hash-verified

832// value := NewValue(t, "foo")
833// value.InList("foo", 123)
834func (v *Value) InList(values ...interface{}) *Value {
835 opChain := v.chain.enter("InList()")
836 defer opChain.leave()
837
838 if opChain.failed() {
839 return v
840 }
841
842 if len(values) == 0 {
843 opChain.fail(AssertionFailure{
844 Type: AssertUsage,
845 Errors: []error{
846 errors.New("unexpected empty list argument"),
847 },
848 })
849 return v
850 }
851
852 var isListed bool
853 for _, val := range values {
854 expected, ok := canonValue(opChain, val)
855 if !ok {
856 return v
857 }
858
859 if reflect.DeepEqual(expected, v.value) {
860 isListed = true
861 // continue loop to check that all values are correct
862 }
863 }
864
865 if !isListed {
866 opChain.fail(AssertionFailure{
867 Type: AssertBelongs,
868 Actual: &AssertionValue{v.value},
869 Expected: &AssertionValue{AssertionList(values)},
870 Errors: []error{
871 errors.New("expected: value is equal to one of the values"),
872 },
873 })
874 }
875
876 return v
877}
878
879// NotInList succeeds if the whole value is not equal to any of the values from
880// given list of values (e.g. map, slice, string, etc).

Callers 15

TestDuration_FailedChainFunction · 0.45
TestDuration_InListFunction · 0.45
TestNumber_FailedChainFunction · 0.45
TestNumber_InListFunction · 0.45
TestString_FailedChainFunction · 0.45
TestString_InListFunction · 0.45
TestArray_FailedChainFunction · 0.45
TestArray_InListFunction · 0.45
TestDateTime_FailedChainFunction · 0.45
TestDateTime_InListFunction · 0.45
TestBoolean_FailedChainFunction · 0.45
TestBoolean_InListFunction · 0.45

Calls 6

canonValueFunction · 0.85
AssertionListTypeAlias · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 15

TestDuration_FailedChainFunction · 0.36
TestDuration_InListFunction · 0.36
TestNumber_FailedChainFunction · 0.36
TestNumber_InListFunction · 0.36
TestString_FailedChainFunction · 0.36
TestString_InListFunction · 0.36
TestArray_FailedChainFunction · 0.36
TestArray_InListFunction · 0.36
TestDateTime_FailedChainFunction · 0.36
TestDateTime_InListFunction · 0.36
TestBoolean_FailedChainFunction · 0.36
TestBoolean_InListFunction · 0.36