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

Function TestEachKey

parser_test.go:1996–2075  ·  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

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

Callers

nothing calls this directly

Calls 2

EachKeyFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected