MCPcopy Index your code
hub / github.com/buger/jsonparser / TestParseInt

Function TestParseInt

parser_test.go:2337–2403  ·  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

2335// MCDC SYS-REQ-015: raw_int_token_is_well_formed=T, returns_parseint_value=F => FALSE
2336// MCDC SYS-REQ-015: raw_int_token_is_well_formed=T, returns_parseint_value=T => TRUE
2337func TestParseInt(t *testing.T) {
2338 tests := []struct {
2339 name string
2340 in string
2341 want int64
2342 wantErr error
2343 }{
2344 {
2345 name: "zero",
2346 in: "0",
2347 want: 0,
2348 },
2349 {
2350 name: "negative integer",
2351 in: "-12345",
2352 want: -12345,
2353 },
2354 {
2355 name: "max int64",
2356 in: "9223372036854775807",
2357 want: 9223372036854775807,
2358 },
2359 {
2360 name: "empty input",
2361 in: "",
2362 wantErr: MalformedValueError,
2363 },
2364 {
2365 name: "fractional token",
2366 in: "1.2",
2367 wantErr: MalformedValueError,
2368 },
2369 {
2370 name: "alpha suffix",
2371 in: "123x",
2372 wantErr: MalformedValueError,
2373 },
2374 {
2375 name: "overflow",
2376 in: "9223372036854775808",
2377 wantErr: OverflowIntegerError,
2378 },
2379 {
2380 name: "underflow",
2381 in: "-9223372036854775809",
2382 wantErr: OverflowIntegerError,
2383 },
2384 }
2385
2386 for _, test := range tests {
2387 t.Run(test.name, func(t *testing.T) {
2388 got, err := ParseInt([]byte(test.in))
2389 if test.wantErr != nil {
2390 if !errors.Is(err, test.wantErr) {
2391 t.Fatalf("ParseInt(%q) error mismatch: expected %v, got %v", test.in, test.wantErr, err)
2392 }
2393 return
2394 }

Callers

nothing calls this directly

Calls 1

ParseIntFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…