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)
| 416 | // str := NewString(t, "Hello") |
| 417 | // str.InListFold("hEllo", "Goodbye") |
| 418 | func (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). |