| 1 | package jsonparserscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.13 strings/" |
| 6 | "testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 7 | ) |
| 8 | |
| 9 | var testPathsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/testPaths. = [][]string{ |
| 10 | []string{"test"}, |
| 11 | []string{"these"}, |
| 12 | []string{"keys"}, |
| 13 | []string{"please"}, |
| 14 | } |
| 15 | |
| 16 | // Test helper for SYS-REQ-008. |
| 17 | func testIterscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/testIter().(data []byte) (err error) { |
| 18 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, iterErr error) { |
| 19 | if iterErr != nil { |
| 20 | err = fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.13 fmt/Errorf().("Error parsing json: %s", iterErr.Error()) |
| 21 | } |
| 22 | }, testPathsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/testPaths....) |
| 23 | return err |
| 24 | } |
| 25 | |
| 26 | // Verifies: SYS-REQ-001 [malformed] |
| 27 | // MCDC SYS-REQ-001: N/A |
| 28 | // Verifies: SYS-REQ-008 [malformed] |
| 29 | // MCDC SYS-REQ-008: eachkey_callback_receives_found_values=F, eachkey_completes_requested_scan=F, eachkey_malformed_input_returns_error=T, missing_multipath_request_does_not_emit_callback=F, multipath_requests_are_provided=T => TRUE |
| 30 | func TestPanickingErrorsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestPanickingErrors().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 31 | if err := testIterscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/testIter().([]byte(`{"test":`)); err == nil { |
| 32 | t.Errorscip-go gomod github.com/golang/go/src go1.13 testing/common#Error().("Expected error...") |
| 33 | } |
| 34 | |
| 35 | if err := testIterscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/testIter().([]byte(`{"test":0}some":[{"these":[{"keys":"some"}]}]}some"}]}],"please":"some"}`)); err == nil { |
| 36 | t.Errorscip-go gomod github.com/golang/go/src go1.13 testing/common#Error().("Expected error...") |
| 37 | } |
| 38 | |
| 39 | if _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`{"test":`), "test"); err == nil { |
| 40 | t.Errorscip-go gomod github.com/golang/go/src go1.13 testing/common#Error().("Expected error...") |
| 41 | } |
| 42 | |
| 43 | if _, _, _, err := Getscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/Get().([]byte(`{"some":0}some":[{"some":[{"some":"some"}]}]}some"}]}],"some":"some"}`), "x"); err == nil { |
| 44 | t.Errorscip-go gomod github.com/golang/go/src go1.13 testing/common#Error().("Expected error...") |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Verifies: SYS-REQ-008 [boundary] |
| 49 | // 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=F => TRUE |
| 50 | func TestEachKeyNoRequestsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestEachKeyNoRequests().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 51 | called := false |
| 52 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().([]byte(`{"a":1}`), func(idx int, value []byte, vt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 53 | called = true |
| 54 | }) |
| 55 | if called { |
| 56 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("EachKey should not invoke the callback when no paths are requested") |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // check having a very deep key depth |
| 61 | // Verifies: SYS-REQ-008 [boundary] |
| 62 | // MCDC SYS-REQ-008: N/A |
| 63 | func TestKeyDepthscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestKeyDepth().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 64 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 65 | var keys []string |
| 66 | //build data |
| 67 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("{") |
| 68 | for i := 0; i < 128; i++ { |
| 69 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `"key%d": %dx,`, i, i) |
| 70 | keys = append(keys, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("key%d", i)) |
| 71 | } |
| 72 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("}") |
| 73 | |
| 74 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 75 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 76 | return |
| 77 | }, keys) |
| 78 | } |
| 79 | |
| 80 | // check having a bunch of keys in a call to EachKey |
| 81 | // Verifies: SYS-REQ-008 [boundary] |
| 82 | // MCDC SYS-REQ-008: N/A |
| 83 | func TestKeyCountscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestKeyCount().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 84 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 85 | var keys [][]string |
| 86 | //build data |
| 87 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("{") |
| 88 | for i := 0; i < 128; i++ { |
| 89 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `"key%d":"%d"`, i, i) |
| 90 | if i < 127 { |
| 91 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(",") |
| 92 | } |
| 93 | keys = append(keys, []string{fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("key%d", i)}) |
| 94 | } |
| 95 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("}") |
| 96 | |
| 97 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 98 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 99 | return |
| 100 | }, keys...) |
| 101 | } |
| 102 | |
| 103 | // try pulling lots of keys out of a big array |
| 104 | // Verifies: SYS-REQ-008 [boundary] |
| 105 | // MCDC SYS-REQ-008: N/A |
| 106 | func TestKeyDepthArrayscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestKeyDepthArray().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 107 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 108 | var keys []string |
| 109 | //build data |
| 110 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("[") |
| 111 | for i := 0; i < 128; i++ { |
| 112 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `{"key": %d},`, i) |
| 113 | keys = append(keys, fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("[%d].key", i)) |
| 114 | } |
| 115 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("]") |
| 116 | |
| 117 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 118 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 119 | return |
| 120 | }, keys) |
| 121 | } |
| 122 | |
| 123 | // check having a bunch of keys |
| 124 | // Verifies: SYS-REQ-008 [boundary] |
| 125 | // MCDC SYS-REQ-008: N/A |
| 126 | func TestKeyCountArrayscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestKeyCountArray().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 127 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 128 | var keys [][]string |
| 129 | //build data |
| 130 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("[") |
| 131 | for i := 0; i < 128; i++ { |
| 132 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `{"key":"%d"}`, i) |
| 133 | if i < 127 { |
| 134 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(",") |
| 135 | } |
| 136 | keys = append(keys, []string{fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("[%d].key", i)}) |
| 137 | } |
| 138 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().("]") |
| 139 | |
| 140 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 141 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 142 | return |
| 143 | }, keys...) |
| 144 | } |
| 145 | |
| 146 | // check having a bunch of keys in a super deep array |
| 147 | // Verifies: SYS-REQ-008 [boundary] |
| 148 | // MCDC SYS-REQ-008: N/A |
| 149 | func TestEachKeyArrayscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestEachKeyArray().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 150 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 151 | var keys [][]string |
| 152 | //build data |
| 153 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`[`) |
| 154 | for i := 0; i < 127; i++ { |
| 155 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `%d`, i) |
| 156 | if i < 127 { |
| 157 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(",") |
| 158 | } |
| 159 | if i < 32 { |
| 160 | keys = append(keys, []string{fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("[%d]", 128+i)}) |
| 161 | } |
| 162 | } |
| 163 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`]`) |
| 164 | |
| 165 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 166 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 167 | return |
| 168 | }, keys...) |
| 169 | } |
| 170 | |
| 171 | // Verifies: SYS-REQ-008 [boundary] |
| 172 | // MCDC SYS-REQ-008: N/A |
| 173 | func TestLargeArrayscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestLargeArray().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 174 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 175 | //build data |
| 176 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`[`) |
| 177 | for i := 0; i < 127; i++ { |
| 178 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `%d`, i) |
| 179 | if i < 127 { |
| 180 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(",") |
| 181 | } |
| 182 | } |
| 183 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`]`) |
| 184 | keys := [][]string{[]string{`[1]`}} |
| 185 | |
| 186 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 187 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 188 | return |
| 189 | }, keys...) |
| 190 | } |
| 191 | |
| 192 | // Verifies: SYS-REQ-008 [boundary] |
| 193 | // MCDC SYS-REQ-008: N/A |
| 194 | func TestArrayOutOfBoundsscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/TestArrayOutOfBounds().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 195 | var sb stringsscip-go gomod github.com/golang/go/src go1.13 strings/.Builderscip-go gomod github.com/golang/go/src go1.13 strings/Builder# |
| 196 | //build data |
| 197 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`[`) |
| 198 | for i := 0; i < 61; i++ { |
| 199 | fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Fprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Fprintf().(&sb, `%d`, i) |
| 200 | if i < 61 { |
| 201 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(",") |
| 202 | } |
| 203 | } |
| 204 | sb.WriteStringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#WriteString().(`]`) |
| 205 | keys := [][]string{[]string{`[128]`}} |
| 206 | |
| 207 | data := []byte(sb.Stringscip-go gomod github.com/golang/go/src go1.13 strings/Builder#String().()) |
| 208 | EachKeyscip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/EachKey().(data, func(offset int, value []byte, dt ValueTypescip-go gomod github.com/buger/jsonparser . `github.com/buger/jsonparser`/ValueType#, err error) { |
| 209 | return |
| 210 | }, keys...) |
| 211 | } |