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

Function TestEachKey

parser_test.go:1997–2076  ·  view source on GitHub ↗

Verifies: SYS-REQ-008 [example] STK-REQ-004:AC-3:acceptance MCDC SYS-REQ-008: eachkey_callback_receives_found_values=F, eachkey_completes_requested_scan=F, eachkey_malformed_input_returns_error=F, missing_multipath_request_does_not_emit_callback=F, multipath_requests_are_provided=T => FALSE MCDC SYS

(t *testing.T)

Source from the content-addressed store, hash-verified

1995// MCDC SYS-REQ-008: eachkey_callback_receives_found_values=F, eachkey_completes_requested_scan=T, eachkey_malformed_input_returns_error=F, missing_multipath_request_does_not_emit_callback=F, multipath_requests_are_provided=T => TRUE
1996// MCDC SYS-REQ-008: eachkey_callback_receives_found_values=T, eachkey_completes_requested_scan=F, eachkey_malformed_input_returns_error=F, missing_multipath_request_does_not_emit_callback=F, multipath_requests_are_provided=T => TRUE
1997func TestEachKey(t *testing.T) {
1998 paths := [][]string{
1999 {"name"},
2000 {"order"},
2001 {"nested", "a"},
2002 {"nested", "b"},
2003 {"nested2", "a"},
2004 {"nested", "nested3", "b"},
2005 {"arr", "[1]", "b"},
2006 {"arrInt", "[3]"},
2007 {"arrInt", "[5]"}, // Should not find last key
2008 {"nested"},
2009 {"arr", "["}, // issue#177 Invalid arguments
2010 {"a\n", "b\n"}, // issue#165
2011 {"nested", "b"}, // Should find repeated key
2012 }
2013
2014 keysFound := 0
2015
2016 EachKey(testJson, func(idx int, value []byte, vt ValueType, err error) {
2017 keysFound++
2018
2019 switch idx {
2020 case 0:
2021 if string(value) != "Name" {
2022 t.Error("Should find 1 key", string(value))
2023 }
2024 case 1:
2025 if string(value) != "Order" {
2026 t.Errorf("Should find 2 key")
2027 }
2028 case 2:
2029 if string(value) != "test" {
2030 t.Errorf("Should find 3 key")
2031 }
2032 case 3:
2033 if string(value) != "2" {
2034 t.Errorf("Should find 4 key")
2035 }
2036 case 4:
2037 if string(value) != "test2" {
2038 t.Error("Should find 5 key", string(value))
2039 }
2040 case 5:
2041 if string(value) != "4" {
2042 t.Errorf("Should find 6 key")
2043 }
2044 case 6:
2045 if string(value) != "2" {
2046 t.Errorf("Should find 7 key")
2047 }
2048 case 7:
2049 if string(value) != "4" {
2050 t.Error("Should find 8 key", string(value))
2051 }
2052 case 8:
2053 t.Errorf("Found key #8 that should not be found")
2054 case 9:

Callers

nothing calls this directly

Calls 1

EachKeyFunction · 0.85

Tested by

no test coverage detected