Skip to content

Commit 68a66e8

Browse files
committed
Add ArrayEach tests
1 parent 722dd68 commit 68a66e8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

parser_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,33 @@ func TestGetSlice(t *testing.T) {
565565
},
566566
)
567567
}
568+
569+
func TestArrayEach(t *testing.T) {
570+
mock := []byte(`{"a": { "b":[{"x": 1} ,{"x":2},{ "x":3}, {"x":4} ]}}`)
571+
count := 0
572+
573+
ArrayEach(mock, func(value []byte, dataType ValueType, offset int, err error) {
574+
count++
575+
576+
switch count {
577+
case 1:
578+
if string(value) != `{"x": 1}` {
579+
t.Errorf("Wrong first item: %s", string(value))
580+
}
581+
case 2:
582+
if string(value) != `{"x":2}` {
583+
t.Errorf("Wrong second item: %s", string(value))
584+
}
585+
case 3:
586+
if string(value) != `{ "x":3}` {
587+
t.Errorf("Wrong third item: %s", string(value))
588+
}
589+
case 4:
590+
if string(value) != `{"x":4}` {
591+
t.Errorf("Wrong forth item: %s", string(value))
592+
}
593+
default:
594+
t.Errorf("Should process only 4 items")
595+
}
596+
}, "a", "b")
597+
}

0 commit comments

Comments
 (0)