-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: update documentation as errors messages changed
- Loading branch information
Showing
3 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package safecast_test | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
|
||
"github.com/ccoveille/go-safecast" | ||
) | ||
|
||
func ExampleToInt8() { | ||
fmt.Println(safecast.ToInt8(float64(200.42))) | ||
// Output: 0 conversion issue: 200.42 (float64) is greater than 127 (int8): maximum value for this type exceeded | ||
} | ||
|
||
func ExampleToUint8() { | ||
fmt.Println(safecast.ToUint8(int64(-1))) | ||
// Output: 0 conversion issue: -1 (int64) is less than 0 (uint8): minimum value for this type exceeded | ||
} | ||
|
||
func ExampleToInt16() { | ||
fmt.Println(safecast.ToInt16(int32(40000))) | ||
// Output: 0 conversion issue: 40000 (int32) is greater than 32767 (int16): maximum value for this type exceeded | ||
} | ||
|
||
func ExampleToUint16() { | ||
fmt.Println(safecast.ToUint16(int64(-1))) | ||
// Output: 0 conversion issue: -1 (int64) is less than 0 (uint16): minimum value for this type exceeded | ||
} | ||
|
||
func ExampleToInt32() { | ||
fmt.Println(safecast.ToInt32(math.MaxUint32 + 1)) | ||
// Output: 0 conversion issue: 4294967296 (int) is greater than 2147483647 (int32): maximum value for this type exceeded | ||
} | ||
|
||
func ExampleToUint32() { | ||
fmt.Println(safecast.ToUint32(int64(-1))) | ||
// Output: 0 conversion issue: -1 (int64) is less than 0 (uint32): minimum value for this type exceeded | ||
} | ||
|
||
func ExampleToInt64() { | ||
fmt.Println(safecast.ToInt64(uint64(math.MaxInt64) + 1)) | ||
// Output: 0 conversion issue: 9223372036854775808 (uint64) is greater than 9223372036854775807 (int64): maximum value for this type exceeded | ||
} | ||
|
||
func ExampleToUint64() { | ||
fmt.Println(safecast.ToUint64(int8(-1))) | ||
// Output: 0 conversion issue: -1 (int8) is less than 0 (uint64): minimum value for this type exceeded | ||
} | ||
|
||
func ExampleToInt() { | ||
fmt.Println(safecast.ToInt(uint64(math.MaxInt) + 1)) | ||
// Output: 0 conversion issue: 9223372036854775808 (uint64) is greater than 9223372036854775807 (int): maximum value for this type exceeded | ||
} | ||
|
||
func ExampleToUint() { | ||
fmt.Println(safecast.ToUint(int8(-1))) | ||
// Output: 0 conversion issue: -1 (int8) is less than 0 (uint): minimum value for this type exceeded | ||
} |