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