-
Notifications
You must be signed in to change notification settings - Fork 1
/
int_test.go
67 lines (53 loc) · 1.68 KB
/
int_test.go
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
//go:build !(386 || arm || mips || mipsle)
package bstore
import (
"math"
"os"
"testing"
)
func TestIntwidth(t *testing.T) {
// int is treated as int32, for portability between 32 and 64 bit (int)
// systems. We detect values that are too large. We have types for int
// and uint as PK, since code for packing keys is different from the
// other fields.
type User struct {
ID int
Uint uint
}
type User2 struct {
ID uint
Int int
}
const path = "testdata/tmp.intwidth.db"
os.Remove(path)
db, err := topen(t, path, nil, User{}, User2{})
tcheck(t, err, "open")
defer tclose(t, db)
err = db.Insert(ctxbg, &User{math.MinInt32 - 1, 1})
tneed(t, err, ErrParam, "out of range")
err = db.Insert(ctxbg, &User{math.MaxInt32 + 1, 1})
tneed(t, err, ErrParam, "out of range")
err = db.Insert(ctxbg, &User{0, math.MaxUint32 + 1})
tneed(t, err, ErrParam, "out of range")
u0 := User{math.MinInt32, 1}
err = db.Insert(ctxbg, &u0)
tcheck(t, err, "insert user")
err = db.Get(ctxbg, &u0)
tcompare(t, err, u0, User{math.MinInt32, 1}, "get user")
u1 := User{math.MaxInt32, 1}
err = db.Insert(ctxbg, &u1)
tcheck(t, err, "insert user")
err = db.Get(ctxbg, &u1)
tcompare(t, err, u1, User{math.MaxInt32, 1}, "get user")
err = db.Insert(ctxbg, &User2{math.MaxUint32 + 1, 1})
tneed(t, err, ErrParam, "out of range")
err = db.Insert(ctxbg, &User2{0, math.MinInt32 - 1})
tneed(t, err, ErrParam, "out of range")
err = db.Insert(ctxbg, &User2{0, math.MaxInt32 + 1})
tneed(t, err, ErrParam, "out of range")
u2 := User2{math.MaxUint32, 1}
err = db.Insert(ctxbg, &u2)
tcheck(t, err, "insert user")
err = db.Get(ctxbg, &u2)
tcompare(t, err, u2, User2{math.MaxUint32, 1}, "get user")
}