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

Function getTestCheckFoundAndNoError

parser_test.go:1208–1230  ·  view source on GitHub ↗

checkFoundAndNoError checks the dataType and error return from Get*() against the test case expectations. Returns true the test should proceed to checking the actual data returned from Get*(), or false if the test is finished. Test helper for SYS-REQ-001, SYS-REQ-002, SYS-REQ-003, SYS-REQ-004, SYS-R

(t *testing.T, testKind string, test GetTest, jtype ValueType, value interface{}, err error)

Source from the content-addressed store, hash-verified

1206// Returns true the test should proceed to checking the actual data returned from Get*(), or false if the test is finished.
1207// Test helper for SYS-REQ-001, SYS-REQ-002, SYS-REQ-003, SYS-REQ-004, SYS-REQ-005, and SYS-REQ-011.
1208func getTestCheckFoundAndNoError(t *testing.T, testKind string, test GetTest, jtype ValueType, value interface{}, err error) bool {
1209 isFound := (err != KeyPathNotFoundError)
1210 isErr := (err != nil && err != KeyPathNotFoundError)
1211
1212 if test.isErr != isErr {
1213 // If the call didn't match the error expectation, fail
1214 t.Errorf("%s test '%s' isErr mismatch: expected %t, obtained %t (err %v). Value: %v", testKind, test.desc, test.isErr, isErr, err, value)
1215 return false
1216 } else if isErr {
1217 // Else, if there was an error, don't fail and don't check isFound or the value
1218 return false
1219 } else if test.isFound != isFound {
1220 // Else, if the call didn't match the is-found expectation, fail
1221 t.Errorf("%s test '%s' isFound mismatch: expected %t, obtained %t", testKind, test.desc, test.isFound, isFound)
1222 return false
1223 } else if !isFound {
1224 // Else, if no value was found, don't fail and don't check the value
1225 return false
1226 } else {
1227 // Else, there was no error and a value was found, so check the value
1228 return true
1229 }
1230}
1231
1232// Test helper for SYS-REQ-001, SYS-REQ-002, SYS-REQ-003, SYS-REQ-004, SYS-REQ-005, and SYS-REQ-011.
1233func runGetTests(t *testing.T, testKind string, tests []GetTest, runner func(GetTest) (interface{}, ValueType, error), resultChecker func(GetTest, interface{}) (bool, interface{})) {

Callers 1

runGetTestsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected