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

Method ContainsOnly

array.go:1442–1487  ·  view source on GitHub ↗

ContainsOnly succeeds if array contains all given elements, in any order, and only them, ignoring duplicates. Before comparison, array and all elements are converted to canonical form. Example: array := NewArray(t, []interface{}{"foo", 123, 123}) array.ContainsOnly(123, "foo") These calls are e

(values ...interface{})

Source from the content-addressed store, hash-verified

1440// array.ContainsOnly("a", "b")
1441// array.ContainsOnly("b", "a")
1442func (a *Array) ContainsOnly(values ...interface{}) *Array {
1443 opChain := a.chain.enter("ContainsOnly()")
1444 defer opChain.leave()
1445
1446 if opChain.failed() {
1447 return a
1448 }
1449
1450 elements, ok := canonArray(opChain, values)
1451 if !ok {
1452 return a
1453 }
1454
1455 for _, element := range elements {
1456 if countElement(a.value, element) == 0 {
1457 opChain.fail(AssertionFailure{
1458 Type: AssertContainsElement,
1459 Actual: &AssertionValue{a.value},
1460 Expected: &AssertionValue{element},
1461 Reference: &AssertionValue{values},
1462 Errors: []error{
1463 errors.New("expected: array contains element from reference array"),
1464 },
1465 })
1466 return a
1467 }
1468 }
1469
1470 for _, element := range a.value {
1471 if countElement(elements, element) == 0 {
1472 opChain.fail(AssertionFailure{
1473 Type: AssertNotContainsElement,
1474 Actual: &AssertionValue{a.value},
1475 Expected: &AssertionValue{element},
1476 Reference: &AssertionValue{values},
1477 Errors: []error{
1478 errors.New("expected: array does not contain elements" +
1479 " that are not present in reference array"),
1480 },
1481 })
1482 return a
1483 }
1484 }
1485
1486 return a
1487}
1488
1489// NotContainsOnly is opposite to ContainsOnly.
1490//

Callers 5

TestArray_FailedChainFunction · 0.80
TestArray_ContainsOnlyFunction · 0.80
testEchoFunction · 0.80
TestFruitsFunction · 0.80
testCookieHandlerFunction · 0.80

Calls 6

canonArrayFunction · 0.85
countElementFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 5

TestArray_FailedChainFunction · 0.64
TestArray_ContainsOnlyFunction · 0.64
testEchoFunction · 0.64
TestFruitsFunction · 0.64
testCookieHandlerFunction · 0.64