-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
43 lines (34 loc) · 922 Bytes
/
Copy pathexample_test.go
File metadata and controls
43 lines (34 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MPL-2.0
//
// Copyright (c) 2026 Alex Hermann, Hexla. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package bytesconv_test
import (
"fmt"
"go.hexla.nl/bytesconv"
)
func ExampleAtoI() {
if n, err := bytesconv.AtoI[int16]([]byte("-32768")); err == nil {
fmt.Printf("%T, %v\n", n, n)
}
if n, err := bytesconv.AtoI[uint32]([]byte("4294967295")); err == nil {
fmt.Printf("%T, %v\n", n, n)
}
if _, err := bytesconv.AtoI[int8]([]byte("128")); err != nil {
fmt.Println(err == bytesconv.ErrRange)
}
// Output:
// int16, -32768
// uint32, 4294967295
// true
}
func ExampleAtoi() {
if n, err := bytesconv.Atoi([]byte("10")); err == nil {
fmt.Printf("%T, %v", n, n)
}
// Output:
// int, 10
}