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

Function builtinComparator

array.go:1744–1829  ·  view source on GitHub ↗
(opChain *chain, array []interface{})

Source from the content-addressed store, hash-verified

1742}
1743
1744func builtinComparator(opChain *chain, array []interface{}) func(x, y *Value) bool {
1745 var prev interface{}
1746 for index, curr := range array {
1747 switch curr.(type) {
1748 case bool, float64, string, nil:
1749 // ok, do nothing
1750
1751 default:
1752 opChain.fail(AssertionFailure{
1753 Type: AssertBelongs,
1754 Actual: &AssertionValue{
1755 unquotedType(fmt.Sprintf("%T", curr)),
1756 },
1757 Expected: &AssertionValue{AssertionList{
1758 unquotedType("Boolean (bool)"),
1759 unquotedType("Number (int*, uint*, float*)"),
1760 unquotedType("String (string)"),
1761 unquotedType("Null (nil)"),
1762 }},
1763 Reference: &AssertionValue{
1764 array,
1765 },
1766 Errors: []error{
1767 errors.New("expected: type of each element of reference array" +
1768 " belongs to allowed list"),
1769 fmt.Errorf("element %v has disallowed type %T", index, curr),
1770 },
1771 })
1772 return nil
1773 }
1774
1775 if index > 0 && fmt.Sprintf("%T", curr) != fmt.Sprintf("%T", prev) {
1776 opChain.fail(AssertionFailure{
1777 Type: AssertEqual,
1778 Actual: &AssertionValue{
1779 unquotedType(fmt.Sprintf("%T (type of element %v)", curr, index)),
1780 },
1781 Expected: &AssertionValue{
1782 unquotedType(fmt.Sprintf("%T (type of element %v)", prev, index-1)),
1783 },
1784 Reference: &AssertionValue{
1785 array,
1786 },
1787 Errors: []error{
1788 errors.New("expected:" +
1789 " types of all elements of reference array are the same"),
1790 fmt.Errorf("element %v has type %T, but element %v has type %T",
1791 index-1, prev, index, curr),
1792 },
1793 })
1794 return nil
1795 }
1796
1797 prev = curr
1798 }
1799
1800 if len(array) > 1 {
1801 switch array[0].(type) {

Callers 3

IsOrderedMethod · 0.85
NotOrderedMethod · 0.85

Calls 4

unquotedTypeTypeAlias · 0.85
failMethod · 0.80
ErrorfMethod · 0.65
RawMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…