MCPcopy Index your code
hub / github.com/buger/jsonparser / TestObjectEach

Function TestObjectEach

parser_test.go:1855–1899  ·  view source on GitHub ↗

Verifies: SYS-REQ-031 [example] MCDC SYS-REQ-031: addressed_object_is_well_formed=F, malformed_object_input_returns_error=T => TRUE Verifies: SYS-REQ-030 [example] MCDC SYS-REQ-030: addressed_object_is_empty=T, addressed_object_is_well_formed=T, empty_object_produces_no_entries=T => TRUE Verifies: S

(t *testing.T)

Source from the content-addressed store, hash-verified

1853// MCDC SYS-REQ-007: addressed_object_is_empty=F, addressed_object_is_well_formed=T, object_callback_receives_entries=F => FALSE
1854// MCDC SYS-REQ-007: addressed_object_is_empty=F, addressed_object_is_well_formed=T, object_callback_receives_entries=T => TRUE
1855func TestObjectEach(t *testing.T) {
1856 for _, test := range objectEachTests {
1857 if activeTest != "" && test.desc != activeTest {
1858 continue
1859 }
1860
1861 // Execute ObjectEach and capture all of the entries visited, in order
1862 var entries []keyValueEntry
1863 err := ObjectEach([]byte(test.json), func(key, value []byte, valueType ValueType, off int) error {
1864 entries = append(entries, keyValueEntry{
1865 key: string(key),
1866 value: string(value),
1867 valueType: valueType,
1868 })
1869 return nil
1870 })
1871
1872 // Check the correctness of the result
1873 isErr := (err != nil)
1874 if test.isErr != isErr {
1875 // If the call didn't match the error expectation, fail
1876 t.Errorf("ObjectEach test '%s' isErr mismatch: expected %t, obtained %t (err %v)", test.desc, test.isErr, isErr, err)
1877 } else if isErr {
1878 // Else, if there was an expected error, don't fail and don't check anything further
1879 } else if len(test.entries) != len(entries) {
1880 t.Errorf("ObjectEach test '%s' mismatch in number of key-value entries: expected %d, obtained %d (entries found: %s)", test.desc, len(test.entries), len(entries), entries)
1881 } else {
1882 for i, entry := range entries {
1883 expectedEntry := test.entries[i]
1884 if expectedEntry.key != entry.key {
1885 t.Errorf("ObjectEach test '%s' key mismatch at entry %d: expected %s, obtained %s", test.desc, i, expectedEntry.key, entry.key)
1886 break
1887 } else if expectedEntry.value != entry.value {
1888 t.Errorf("ObjectEach test '%s' value mismatch at entry %d: expected %s, obtained %s", test.desc, i, expectedEntry.value, entry.value)
1889 break
1890 } else if expectedEntry.valueType != entry.valueType {
1891 t.Errorf("ObjectEach test '%s' value type mismatch at entry %d: expected %s, obtained %s", test.desc, i, expectedEntry.valueType, entry.valueType)
1892 break
1893 } else {
1894 // Success for this entry
1895 }
1896 }
1897 }
1898 }
1899}
1900
1901// Verifies: SYS-REQ-032 [boundary]
1902// MCDC SYS-REQ-032: addressed_object_is_well_formed=T, object_callback_returns_error=T, object_callback_error_is_returned=T => TRUE

Callers

nothing calls this directly

Calls 1

ObjectEachFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…