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

Function TestParseIntEdgeCaseNumbers

obligation_property_test.go:833–873  ·  view source on GitHub ↗

Verifies: SYS-REQ-109 MCDC SYS-REQ-109: parseint_input_has_edge_case_number=T, parseint_handles_edge_numbers_safely=T => TRUE

(t *testing.T)

Source from the content-addressed store, hash-verified

831// Verifies: SYS-REQ-109
832// MCDC SYS-REQ-109: parseint_input_has_edge_case_number=T, parseint_handles_edge_numbers_safely=T => TRUE
833func TestParseIntEdgeCaseNumbers(t *testing.T) {
834 cases := []struct {
835 name string
836 input string
837 wantVal int64
838 wantErr bool
839 }{
840 {name: "negative zero", input: "-0", wantVal: 0},
841 {name: "positive zero", input: "0", wantVal: 0},
842 {name: "max int64", input: "9223372036854775807", wantVal: math.MaxInt64},
843 {name: "min int64", input: "-9223372036854775808", wantVal: math.MinInt64},
844 {name: "max+1 overflow", input: "9223372036854775808", wantErr: true},
845 {name: "min-1 overflow", input: "-9223372036854775809", wantErr: true},
846 {name: "100-digit number", input: strings.Repeat("9", 100), wantErr: true},
847 {name: "single digit", input: "7", wantVal: 7},
848 {name: "negative single digit", input: "-3", wantVal: -3},
849 }
850 for _, tc := range cases {
851 t.Run(tc.name, func(t *testing.T) {
852 defer func() {
853 if r := recover(); r != nil {
854 t.Fatalf("ParseInt panicked: %v", r)
855 }
856 }()
857
858 val, err := ParseInt([]byte(tc.input))
859 if tc.wantErr {
860 if err == nil {
861 t.Fatalf("Expected error for %q, got value %d", tc.input, val)
862 }
863 return
864 }
865 if err != nil {
866 t.Fatalf("ParseInt(%q) returned error: %v", tc.input, err)
867 }
868 if val != tc.wantVal {
869 t.Fatalf("ParseInt(%q) = %d, want %d", tc.input, val, tc.wantVal)
870 }
871 })
872 }
873}

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…