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

Function TestParseInt

parser_test.go:2369–2447  ·  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 tracked separately under DEFECT-260726-3F95 / KI-2 — that partition
2380 // currently returns (0, nil) instead of MalformedValueError and is the
2381 // one malformed sub-case NOT covered here.)
2382 tests := []struct {
2383 name string
2384 in string
2385 want int64
2386 wantErr error
2387 }{
2388 {
2389 name: "zero",
2390 in: "0",
2391 want: 0,
2392 },
2393 {
2394 name: "negative integer",
2395 in: "-12345",
2396 want: -12345,
2397 },
2398 {
2399 name: "max int64",
2400 in: "9223372036854775807",
2401 want: 9223372036854775807,
2402 },
2403 {
2404 name: "empty input",
2405 in: "",
2406 wantErr: MalformedValueError,
2407 },
2408 {
2409 name: "fractional token",
2410 in: "1.2",
2411 wantErr: MalformedValueError,
2412 },
2413 {
2414 name: "alpha suffix",
2415 in: "123x",
2416 wantErr: MalformedValueError,
2417 },
2418 {
2419 name: "overflow",
2420 in: "9223372036854775808",
2421 wantErr: OverflowIntegerError,
2422 },
2423 {
2424 name: "underflow",
2425 in: "-9223372036854775809",
2426 wantErr: OverflowIntegerError,

Callers

nothing calls this directly

Calls 1

ParseIntFunction · 0.85

Tested by

no test coverage detected