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

Function TestArrayEach

parser_test.go:1633–1661  ·  view source on GitHub ↗

Verifies: SYS-REQ-006 [example] STK-REQ-004:AC-1:acceptance MCDC SYS-REQ-006: addressed_array_is_empty=F, addressed_array_is_well_formed=T, array_callback_receives_elements_in_order=F => FALSE MCDC SYS-REQ-006: addressed_array_is_empty=F, addressed_array_is_well_formed=T, array_callback_receives_ele

(t *testing.T)

Source from the content-addressed store, hash-verified

1631// MCDC SYS-REQ-006: addressed_array_is_empty=F, addressed_array_is_well_formed=T, array_callback_receives_elements_in_order=F => FALSE
1632// MCDC SYS-REQ-006: addressed_array_is_empty=F, addressed_array_is_well_formed=T, array_callback_receives_elements_in_order=T => TRUE
1633func TestArrayEach(t *testing.T) {
1634 mock := []byte(`{"a": { "b":[{"x": 1} ,{"x":2},{ "x":3}, {"x":4} ]}}`)
1635 count := 0
1636
1637 ArrayEach(mock, func(value []byte, dataType ValueType, offset int, err error) {
1638 count++
1639
1640 switch count {
1641 case 1:
1642 if string(value) != `{"x": 1}` {
1643 t.Errorf("Wrong first item: %s", string(value))
1644 }
1645 case 2:
1646 if string(value) != `{"x":2}` {
1647 t.Errorf("Wrong second item: %s", string(value))
1648 }
1649 case 3:
1650 if string(value) != `{ "x":3}` {
1651 t.Errorf("Wrong third item: %s", string(value))
1652 }
1653 case 4:
1654 if string(value) != `{"x":4}` {
1655 t.Errorf("Wrong forth item: %s", string(value))
1656 }
1657 default:
1658 t.Errorf("Should process only 4 items")
1659 }
1660 }, "a", "b")
1661}
1662
1663// Verifies: SYS-REQ-029 [boundary]
1664// MCDC SYS-REQ-029: addressed_array_is_well_formed=F, malformed_array_input_returns_error=T => TRUE

Callers

nothing calls this directly

Calls 1

ArrayEachFunction · 0.85

Tested by

no test coverage detected