MCPcopy Create free account
hub / github.com/buger/jsonparser / TestEachArrayErrAlias

Function TestEachArrayErrAlias

aliases_test.go:113–153  ·  view source on GitHub ↗

Verifies: SYS-REQ-004 (error-returning array iteration alias) reqproof:proptest:skip parity test for a thin compatibility wrapper

(t *testing.T)

Source from the content-addressed store, hash-verified

111// Verifies: SYS-REQ-004 (error-returning array iteration alias)
112// reqproof:proptest:skip parity test for a thin compatibility wrapper
113func TestEachArrayErrAlias(t *testing.T) {
114 data := []byte(`{"payload":{"items":[1,"two",true,null]}}`)
115 stop := errors.New("stop")
116 var original, alias []arrayAliasObservation
117
118 originalCount, originalErr := ArrayEachErr(data, func(value []byte, dataType ValueType, offset int, err error) error {
119 original = append(original, arrayAliasObservation{
120 value: string(value),
121 dataType: dataType,
122 offset: offset,
123 err: aliasErrorString(err),
124 })
125 if len(original) == 3 {
126 return stop
127 }
128 return nil
129 }, "payload", "items")
130
131 aliasCount, aliasErr := EachArrayErr(data, func(value []byte, dataType ValueType, offset int, err error) error {
132 alias = append(alias, arrayAliasObservation{
133 value: string(value),
134 dataType: dataType,
135 offset: offset,
136 err: aliasErrorString(err),
137 })
138 if len(alias) == 3 {
139 return stop
140 }
141 return nil
142 }, "payload", "items")
143
144 if aliasCount != originalCount {
145 t.Fatalf("EachArrayErr() count = %d, ArrayEachErr() count = %d", aliasCount, originalCount)
146 }
147 if !errors.Is(aliasErr, originalErr) {
148 t.Fatalf("EachArrayErr() error = %v, ArrayEachErr() error = %v", aliasErr, originalErr)
149 }
150 if !reflect.DeepEqual(alias, original) {
151 t.Fatalf("EachArrayErr() observations = %#v, ArrayEachErr() observations = %#v", alias, original)
152 }
153}
154
155// Verifies: SYS-REQ-113 (wildcard array iteration alias)
156// reqproof:proptest:skip parity test for a thin compatibility wrapper

Callers

nothing calls this directly

Calls 3

ArrayEachErrFunction · 0.85
aliasErrorStringFunction · 0.85
EachArrayErrFunction · 0.85

Tested by

no test coverage detected