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

Function TestParseInt

parser_test.go:2369–2445  ·  view source on GitHub ↗

Verifies: SYS-REQ-040 [example] MCDC SYS-REQ-040: raw_int_token_is_well_formed=F, raw_int_token_overflows_int64=F, returns_parseint_malformed_error=T => TRUE Verifies: SYS-REQ-039 [example] MCDC SYS-REQ-039: raw_int_token_overflows_int64=T, returns_parseint_overflow_error=T => TRUE Verifies: SYS-REQ

(t *testing.T)

Source from the content-addressed store, hash-verified

2367// MCDC SYS-REQ-015: raw_int_token_is_well_formed=T, returns_parseint_value=F => FALSE
2368// MCDC SYS-REQ-015: raw_int_token_is_well_formed=T, returns_parseint_value=T => TRUE
2369func TestParseInt(t *testing.T) {
2370 // SYS-REQ-015:malformed_input:nominal
2371 // Witness for the happy-path nominal partition: ParseInt on well-formed
2372 // JSON Number tokens ("0", "-12345", "9223372036854775807") returns the
2373 // expected int64 value with no error.
2374 // SYS-REQ-015:malformed_input:negative
2375 // Witness for the malformed-input partition of ParseInt. The "alpha
2376 // suffix", "fractional token", and "empty input" rows below all assert
2377 // MalformedValueError is returned for tokens that do not conform to the
2378 // JSON Number grammar. (Note: the sign-only partition `ParseInt("-")`
2379 // is covered separately by TestParseIntSignOnly_KI2.)
2380 tests := []struct {
2381 name string
2382 in string
2383 want int64
2384 wantErr error
2385 }{
2386 {
2387 name: "zero",
2388 in: "0",
2389 want: 0,
2390 },
2391 {
2392 name: "negative integer",
2393 in: "-12345",
2394 want: -12345,
2395 },
2396 {
2397 name: "max int64",
2398 in: "9223372036854775807",
2399 want: 9223372036854775807,
2400 },
2401 {
2402 name: "empty input",
2403 in: "",
2404 wantErr: MalformedValueError,
2405 },
2406 {
2407 name: "fractional token",
2408 in: "1.2",
2409 wantErr: MalformedValueError,
2410 },
2411 {
2412 name: "alpha suffix",
2413 in: "123x",
2414 wantErr: MalformedValueError,
2415 },
2416 {
2417 name: "overflow",
2418 in: "9223372036854775808",
2419 wantErr: OverflowIntegerError,
2420 },
2421 {
2422 name: "underflow",
2423 in: "-9223372036854775809",
2424 wantErr: OverflowIntegerError,
2425 },
2426 }

Callers

nothing calls this directly

Calls 1

ParseIntFunction · 0.85

Tested by

no test coverage detected