(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestParseOptionalInt(t *testing.T) { |
| 15 | t.Run("integer float is accepted", func(t *testing.T) { |
| 16 | value := parseOptionalInt(7.0) |
| 17 | require.NotNil(t, value) |
| 18 | assert.Equal(t, 7, *value) |
| 19 | }) |
| 20 | |
| 21 | t.Run("fractional float is rejected", func(t *testing.T) { |
| 22 | assert.Nil(t, parseOptionalInt(7.5)) |
| 23 | }) |
| 24 | |
| 25 | t.Run("nan and infinity are rejected", func(t *testing.T) { |
| 26 | assert.Nil(t, parseOptionalInt(math.NaN())) |
| 27 | assert.Nil(t, parseOptionalInt(math.Inf(1))) |
| 28 | }) |
| 29 | |
| 30 | t.Run("uint64 above max int is rejected", func(t *testing.T) { |
| 31 | assert.Nil(t, parseOptionalInt(uint64(math.MaxInt)+1)) |
| 32 | }) |
| 33 | |
| 34 | t.Run("large exact float is architecture aware", func(t *testing.T) { |
| 35 | value := parseOptionalInt(1e12) |
| 36 | if strconv.IntSize == 32 { |
| 37 | assert.Nil(t, value) |
| 38 | return |
| 39 | } |
| 40 | require.NotNil(t, value) |
| 41 | assert.Equal(t, 1000000000000, *value) |
| 42 | }) |
| 43 | } |
nothing calls this directly
no test coverage detected