Verifies: SYS-REQ-096 MCDC SYS-REQ-096: getint_input_has_large_number_edge_case=T, getint_handles_large_numbers_safely=T => TRUE
(t *testing.T)
| 648 | // Verifies: SYS-REQ-096 |
| 649 | // MCDC SYS-REQ-096: getint_input_has_large_number_edge_case=T, getint_handles_large_numbers_safely=T => TRUE |
| 650 | func TestGetIntLargeNumberEdgeCases(t *testing.T) { |
| 651 | cases := []struct { |
| 652 | name string |
| 653 | data string |
| 654 | key string |
| 655 | wantVal int64 |
| 656 | wantErr bool |
| 657 | }{ |
| 658 | { |
| 659 | name: "max int64", |
| 660 | data: fmt.Sprintf(`{"n":%d}`, math.MaxInt64), |
| 661 | key: "n", |
| 662 | wantVal: math.MaxInt64, |
| 663 | }, |
| 664 | { |
| 665 | name: "min int64", |
| 666 | data: fmt.Sprintf(`{"n":%d}`, math.MinInt64), |
| 667 | key: "n", |
| 668 | wantVal: math.MinInt64, |
| 669 | }, |
| 670 | { |
| 671 | name: "overflow beyond max int64", |
| 672 | data: `{"n":9223372036854775808}`, |
| 673 | key: "n", |
| 674 | wantErr: true, |
| 675 | }, |
| 676 | { |
| 677 | name: "negative zero", |
| 678 | data: `{"n":-0}`, |
| 679 | key: "n", |
| 680 | wantVal: 0, |
| 681 | }, |
| 682 | { |
| 683 | name: "zero", |
| 684 | data: `{"n":0}`, |
| 685 | key: "n", |
| 686 | wantVal: 0, |
| 687 | }, |
| 688 | } |
| 689 | for _, tc := range cases { |
| 690 | t.Run(tc.name, func(t *testing.T) { |
| 691 | defer func() { |
| 692 | if r := recover(); r != nil { |
| 693 | t.Fatalf("GetInt panicked: %v", r) |
| 694 | } |
| 695 | }() |
| 696 | |
| 697 | val, err := GetInt([]byte(tc.data), tc.key) |
| 698 | if tc.wantErr { |
| 699 | if err == nil { |
| 700 | t.Fatalf("Expected error, got value %d", val) |
| 701 | } |
| 702 | return |
| 703 | } |
| 704 | if err != nil { |
| 705 | t.Fatalf("GetInt returned error: %v", err) |
| 706 | } |
| 707 | if val != tc.wantVal { |
nothing calls this directly
no test coverage detected
searching dependent graphs…