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

Method InListFold

string.go:418–461  ·  view source on GitHub ↗

InListFold succeeds if the string is equal to one of the values from given list of strings after applying Unicode case-folding (so it's a case-insensitive match). Example: str := NewString(t, "Hello") str.InListFold("hEllo", "Goodbye")

(values ...string)

Source from the content-addressed store, hash-verified

416// str := NewString(t, "Hello")
417// str.InListFold("hEllo", "Goodbye")
418func (s *String) InListFold(values ...string) *String {
419 opChain := s.chain.enter("InListFold()")
420 defer opChain.leave()
421
422 if opChain.failed() {
423 return s
424 }
425
426 if len(values) == 0 {
427 opChain.fail(AssertionFailure{
428 Type: AssertUsage,
429 Errors: []error{
430 errors.New("unexpected empty list argument"),
431 },
432 })
433 return s
434 }
435
436 var isListed bool
437 for _, v := range values {
438 if strings.EqualFold(s.value, v) {
439 isListed = true
440 break
441 }
442 }
443
444 if !isListed {
445 valueList := make([]interface{}, 0, len(values))
446 for _, v := range values {
447 valueList = append(valueList, v)
448 }
449
450 opChain.fail(AssertionFailure{
451 Type: AssertBelongs,
452 Actual: &AssertionValue{s.value},
453 Expected: &AssertionValue{AssertionList(valueList)},
454 Errors: []error{
455 errors.New("expected: string is equal to one of the values (if folded)"),
456 },
457 })
458 }
459
460 return s
461}
462
463// NotInListFold succeeds if the string is not equal to any of the values from given
464// list of strings after applying Unicode case-folding (so it's a case-insensitive match).

Callers 2

TestString_FailedChainFunction · 0.80
TestString_InListFunction · 0.80

Calls 6

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

Tested by 2

TestString_FailedChainFunction · 0.64
TestString_InListFunction · 0.64