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

Function TestEachObjectAlias

aliases_test.go:72–109  ·  view source on GitHub ↗

Verifies: SYS-REQ-007 (object iteration alias) reqproof:proptest:skip parity test for a thin compatibility wrapper

(t *testing.T)

Source from the content-addressed store, hash-verified

70// Verifies: SYS-REQ-007 (object iteration alias)
71// reqproof:proptest:skip parity test for a thin compatibility wrapper
72func TestEachObjectAlias(t *testing.T) {
73 data := []byte(`{"payload":{"first":1,"second":"two","third":true}}`)
74 stop := errors.New("stop")
75 var original, alias []objectAliasObservation
76
77 originalErr := ObjectEach(data, func(key []byte, value []byte, dataType ValueType, offset int) error {
78 original = append(original, objectAliasObservation{
79 key: string(key),
80 value: string(value),
81 dataType: dataType,
82 offset: offset,
83 })
84 if len(original) == 2 {
85 return stop
86 }
87 return nil
88 }, "payload")
89
90 aliasErr := EachObject(data, func(key []byte, value []byte, dataType ValueType, offset int) error {
91 alias = append(alias, objectAliasObservation{
92 key: string(key),
93 value: string(value),
94 dataType: dataType,
95 offset: offset,
96 })
97 if len(alias) == 2 {
98 return stop
99 }
100 return nil
101 }, "payload")
102
103 if !errors.Is(aliasErr, originalErr) {
104 t.Fatalf("EachObject() error = %v, ObjectEach() error = %v", aliasErr, originalErr)
105 }
106 if !reflect.DeepEqual(alias, original) {
107 t.Fatalf("EachObject() observations = %#v, ObjectEach() observations = %#v", alias, original)
108 }
109}
110
111// Verifies: SYS-REQ-004 (error-returning array iteration alias)
112// reqproof:proptest:skip parity test for a thin compatibility wrapper

Callers

nothing calls this directly

Calls 2

ObjectEachFunction · 0.85
EachObjectFunction · 0.85

Tested by

no test coverage detected