-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
68 lines (57 loc) · 1.25 KB
/
errors_test.go
File metadata and controls
68 lines (57 loc) · 1.25 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package atom
import (
"errors"
"testing"
)
func TestErrOverflow(t *testing.T) {
type Small struct {
Value int8
}
atomizer, err := Use[Small]()
if err != nil {
t.Fatalf("Use failed: %v", err)
}
// Create atom with value that overflows int8
atom := &Atom{
Ints: map[string]int64{"Value": 200}, // max int8 is 127
}
_, err = atomizer.Deatomize(atom)
if err == nil {
t.Fatal("expected overflow error")
}
if !errors.Is(err, ErrOverflow) {
t.Errorf("expected ErrOverflow, got: %v", err)
}
}
func TestErrUnsupportedType(t *testing.T) {
type Bad struct {
Ch chan int
}
_, err := Use[Bad]()
if err == nil {
t.Fatal("expected unsupported type error")
}
if !errors.Is(err, ErrUnsupportedType) {
t.Errorf("expected ErrUnsupportedType, got: %v", err)
}
}
func TestErrSizeMismatch(t *testing.T) {
type Fixed struct {
Data [4]byte
}
atomizer, err := Use[Fixed]()
if err != nil {
t.Fatalf("Use failed: %v", err)
}
// Create atom with wrong size byte slice
atom := &Atom{
Bytes: map[string][]byte{"Data": {1, 2, 3}}, // 3 bytes, need 4
}
_, err = atomizer.Deatomize(atom)
if err == nil {
t.Fatal("expected size mismatch error")
}
if !errors.Is(err, ErrSizeMismatch) {
t.Errorf("expected ErrSizeMismatch, got: %v", err)
}
}