Skip to content

Commit

Permalink
adapter 32bit system
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Oct 13, 2021
1 parent 28c498e commit fac4223
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 444 deletions.
13 changes: 13 additions & 0 deletions Dockerfile.32bit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM i386/golang:alpine

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && \
apk add --no-cache bash git openssh ca-certificates tzdata && \
rm -rf /var/cache/apk/*

ENV CGO_ENABLED=0 \
GOPROXY="https://goproxy.cn"

WORKDIR /usr/src/myapp

CMD ["bash"]
64 changes: 32 additions & 32 deletions bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestBool_HasDefault(t *testing.T) {
}{
// supported value, def is not used, def != expect
{0, true, false},
{float64(0.00), true, false},
{0.00, true, false},
{int(0.00), true, false},
{int64(0.00), true, false},
{uint(0.00), true, false},
Expand All @@ -32,12 +32,12 @@ func TestBool_HasDefault(t *testing.T) {
{"off", true, false},
{"Off", true, false},
{[]byte("Off"), true, false},
{aliasTypeInt_0, true, false},
{&aliasTypeInt_0, true, false},
{aliasTypeString_0, true, false},
{&aliasTypeString_0, true, false},
{aliasTypeString_off, true, false},
{&aliasTypeString_off, true, false},
{aliasTypeInt0, true, false},
{&aliasTypeInt0, true, false},
{aliasTypeString0, true, false},
{&aliasTypeString0, true, false},
{aliasTypeStringOff, true, false},
{&aliasTypeStringOff, true, false},

{[]int{}, true, false},
{[]string{}, true, false},
Expand All @@ -56,12 +56,12 @@ func TestBool_HasDefault(t *testing.T) {
{"on", false, true},
{"On", false, true},
{0.01, false, true},
{aliasTypeInt_1, false, true},
{&aliasTypeInt_1, false, true},
{aliasTypeString_1, false, true},
{&aliasTypeString_1, false, true},
{aliasTypeString_on, false, true},
{&aliasTypeString_on, false, true},
{aliasTypeInt1, false, true},
{&aliasTypeInt1, false, true},
{aliasTypeString1, false, true},
{&aliasTypeString1, false, true},
{aliasTypeStringOn, false, true},
{&aliasTypeStringOn, false, true},

{[]int{1, 2, 3}, false, true},
{[]string{"a", "b", "c"}, false, true},
Expand Down Expand Up @@ -99,8 +99,8 @@ func TestBool_BaseLine(t *testing.T) {
{[]string{"a", "b", "c"}, true},
{[...]string{}, false},
{map[int]string{}, false},
{aliasTypeString_8d15_minus, true},
{&aliasTypeString_8d15_minus, true},
{aliasTypeString8d15Minus, true},
{&aliasTypeString8d15Minus, true},
}

for i, tt := range tests {
Expand All @@ -119,7 +119,7 @@ func TestBoolE(t *testing.T) {
}{
// false/scale
{0, false, false},
{float64(0.00), false, false},
{0.00, false, false},
{int(0.00), false, false},
{int64(0.00), false, false},
{uint(0.00), false, false},
Expand All @@ -138,14 +138,14 @@ func TestBoolE(t *testing.T) {
{"0.00", false, false},
{[]byte("false"), false, false},
{[]byte("Off"), false, false},
{aliasTypeInt_0, false, false},
{&aliasTypeInt_0, false, false},
{aliasTypeString_0, false, false},
{&aliasTypeString_0, false, false},
{aliasTypeString_off, false, false},
{&aliasTypeString_off, false, false},
{aliasTypeBool_false, false, false},
{&aliasTypeBool_false, false, false},
{aliasTypeInt0, false, false},
{&aliasTypeInt0, false, false},
{aliasTypeString0, false, false},
{&aliasTypeString0, false, false},
{aliasTypeStringOff, false, false},
{&aliasTypeStringOff, false, false},
{aliasTypeBool4False, false, false},
{&aliasTypeBool4False, false, false},

// false/slice/array/map
{[]int{}, false, false},
Expand All @@ -168,14 +168,14 @@ func TestBoolE(t *testing.T) {
{0.01, true, false},
{"0.01", true, false},
{[]byte("true"), true, false},
{aliasTypeInt_1, true, false},
{&aliasTypeInt_1, true, false},
{aliasTypeString_1, true, false},
{&aliasTypeString_1, true, false},
{aliasTypeString_on, true, false},
{&aliasTypeString_on, true, false},
{aliasTypeBool_true, true, false},
{&aliasTypeBool_true, true, false},
{aliasTypeInt1, true, false},
{&aliasTypeInt1, true, false},
{aliasTypeString1, true, false},
{&aliasTypeString1, true, false},
{aliasTypeStringOn, true, false},
{&aliasTypeStringOn, true, false},
{aliasTypeBool4True, true, false},
{&aliasTypeBool4True, true, false},

// true/slice/array/map
{[]int{1, 2, 3}, true, false},
Expand Down
32 changes: 16 additions & 16 deletions cvte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ type (
)

var (
aliasTypeBool_true AliasTypeBool = true
aliasTypeBool_false AliasTypeBool = false
aliasTypeBool4True AliasTypeBool = true
aliasTypeBool4False AliasTypeBool = false

aliasTypeInt_0 AliasTypeInt = 0
aliasTypeInt_1 AliasTypeInt = 1
aliasTypeInt0 AliasTypeInt = 0
aliasTypeInt1 AliasTypeInt = 1

aliasTypeUint_0 AliasTypeUint = 0
aliasTypeUint_1 AliasTypeUint = 1
aliasTypeUint0 AliasTypeUint = 0
aliasTypeUint1 AliasTypeUint = 1

aliasTypeString_0 AliasTypeString = "0"
aliasTypeString_1 AliasTypeString = "1"
aliasTypeString_8d15 AliasTypeString = "8.15"
aliasTypeString_8d15_minus AliasTypeString = "-8.15"
aliasTypeString_on AliasTypeString = "on"
aliasTypeString_off AliasTypeString = "off"
aliasTypeString0 AliasTypeString = "0"
aliasTypeString1 AliasTypeString = "1"
aliasTypeString8d15 AliasTypeString = "8.15"
aliasTypeString8d15Minus AliasTypeString = "-8.15"
aliasTypeStringOn AliasTypeString = "on"
aliasTypeStringOff AliasTypeString = "off"

pointerRunes = []rune("中国")
pointerInterNil *AliasTypeInterface
AliasTypeBytes_nil AliasTypeBytes
pointerRunes = []rune("中国")
pointerInterNil *AliasTypeInterface
AliasTypeBytesNil AliasTypeBytes
)

// custom type
Expand Down Expand Up @@ -100,7 +100,7 @@ func (t TestTimeStringer) String() string {

func Benchmark(b *testing.B) {
for i := 0; i < b.N; i++ {
cvt.Bool(aliasTypeString_0, true)
cvt.Bool(aliasTypeString0, true)
}
}

Expand Down
23 changes: 23 additions & 0 deletions doc/develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# develop

## test in 32bit

> use `i386/golang:alpine` image for testing 32bit system, detail in `Dockerfile.32bit`
- build image

```shell
docker build -t cvt-test -f Dockerfile.32bit .
```

- run container

```shell
docker run -it --name cvt-test -v "$PWD":/usr/src/myapp -w /usr/src/myapp cvt-test bash
```

- run test

```shell
go test ./...
```
112 changes: 56 additions & 56 deletions float_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ func TestFloat64_HasDefault(t *testing.T) {
{true, 2, 1},
{false, 2, 0},
{nil, 2, 0},
{aliasTypeInt_0, 2, 0},
{&aliasTypeInt_0, 2, 0},
{aliasTypeInt_1, 2, 1},
{&aliasTypeInt_1, 2, 1},
{aliasTypeString_0, 2, 0},
{&aliasTypeString_0, 2, 0},
{aliasTypeString_1, 2, 1},
{&aliasTypeString_1, 2, 1},
{aliasTypeString_8d15, 2, 8.15},
{&aliasTypeString_8d15, 2, 8.15},
{aliasTypeString_8d15_minus, 1, -8.15},
{&aliasTypeString_8d15_minus, 1, -8.15},
{aliasTypeInt0, 2, 0},
{&aliasTypeInt0, 2, 0},
{aliasTypeInt1, 2, 1},
{&aliasTypeInt1, 2, 1},
{aliasTypeString0, 2, 0},
{&aliasTypeString0, 2, 0},
{aliasTypeString1, 2, 1},
{&aliasTypeString1, 2, 1},
{aliasTypeString8d15, 2, 8.15},
{&aliasTypeString8d15, 2, 8.15},
{aliasTypeString8d15Minus, 1, -8.15},
{&aliasTypeString8d15Minus, 1, -8.15},

// unsupported value, def == expect
{"10a", 1.11, 1.11},
Expand Down Expand Up @@ -139,18 +139,18 @@ func TestFloat32_HasDefault(t *testing.T) {
{true, 2, 1},
{false, 2, 0},
{nil, 2, 0},
{aliasTypeInt_0, 2, 0},
{&aliasTypeInt_0, 2, 0},
{aliasTypeInt_1, 2, 1},
{&aliasTypeInt_1, 2, 1},
{aliasTypeString_0, 2, 0},
{&aliasTypeString_0, 2, 0},
{aliasTypeString_1, 2, 1},
{&aliasTypeString_1, 2, 1},
{aliasTypeString_8d15, 2, 8.15},
{&aliasTypeString_8d15, 2, 8.15},
{aliasTypeString_8d15_minus, 1, -8.15},
{&aliasTypeString_8d15_minus, 1, -8.15},
{aliasTypeInt0, 2, 0},
{&aliasTypeInt0, 2, 0},
{aliasTypeInt1, 2, 1},
{&aliasTypeInt1, 2, 1},
{aliasTypeString0, 2, 0},
{&aliasTypeString0, 2, 0},
{aliasTypeString1, 2, 1},
{&aliasTypeString1, 2, 1},
{aliasTypeString8d15, 2, 8.15},
{&aliasTypeString8d15, 2, 8.15},
{aliasTypeString8d15Minus, 1, -8.15},
{&aliasTypeString8d15Minus, 1, -8.15},

// unsupported value, def == expect
{"10a", 1.11, 1.11},
Expand Down Expand Up @@ -239,22 +239,22 @@ func TestFloat64E(t *testing.T) {
{int64(math.MaxInt64), float64(math.MaxInt64), false},
{uint64(math.MaxUint64), float64(math.MaxUint64), false},
{nil, 0, false},
{aliasTypeInt_0, 0, false},
{&aliasTypeInt_0, 0, false},
{aliasTypeInt_1, 1, false},
{&aliasTypeInt_1, 1, false},
{aliasTypeString_0, 0, false},
{&aliasTypeString_0, 0, false},
{aliasTypeString_1, 1, false},
{&aliasTypeString_1, 1, false},
{aliasTypeString_8d15, 8.15, false},
{&aliasTypeString_8d15, 8.15, false},
{aliasTypeString_8d15_minus, -8.15, false},
{&aliasTypeString_8d15_minus, -8.15, false},
{aliasTypeBool_true, 1, false},
{&aliasTypeBool_true, 1, false},
{aliasTypeBool_false, 0, false},
{&aliasTypeBool_false, 0, false},
{aliasTypeInt0, 0, false},
{&aliasTypeInt0, 0, false},
{aliasTypeInt1, 1, false},
{&aliasTypeInt1, 1, false},
{aliasTypeString0, 0, false},
{&aliasTypeString0, 0, false},
{aliasTypeString1, 1, false},
{&aliasTypeString1, 1, false},
{aliasTypeString8d15, 8.15, false},
{&aliasTypeString8d15, 8.15, false},
{aliasTypeString8d15Minus, -8.15, false},
{&aliasTypeString8d15Minus, -8.15, false},
{aliasTypeBool4True, 1, false},
{&aliasTypeBool4True, 1, false},
{aliasTypeBool4False, 0, false},
{&aliasTypeBool4False, 0, false},

// errors
{"10a", 0, true},
Expand Down Expand Up @@ -327,22 +327,22 @@ func TestFloat32E(t *testing.T) {
{[]byte("8.01"), 8.01, false},
{int(math.MaxInt32), float32(math.MaxInt32), false},
{nil, 0, false},
{aliasTypeInt_0, 0, false},
{&aliasTypeInt_0, 0, false},
{aliasTypeInt_1, 1, false},
{&aliasTypeInt_1, 1, false},
{aliasTypeString_0, 0, false},
{&aliasTypeString_0, 0, false},
{aliasTypeString_1, 1, false},
{&aliasTypeString_1, 1, false},
{aliasTypeString_8d15, 8.15, false},
{&aliasTypeString_8d15, 8.15, false},
{aliasTypeString_8d15_minus, -8.15, false},
{&aliasTypeString_8d15_minus, -8.15, false},
{aliasTypeBool_true, 1, false},
{&aliasTypeBool_true, 1, false},
{aliasTypeBool_false, 0, false},
{&aliasTypeBool_false, 0, false},
{aliasTypeInt0, 0, false},
{&aliasTypeInt0, 0, false},
{aliasTypeInt1, 1, false},
{&aliasTypeInt1, 1, false},
{aliasTypeString0, 0, false},
{&aliasTypeString0, 0, false},
{aliasTypeString1, 1, false},
{&aliasTypeString1, 1, false},
{aliasTypeString8d15, 8.15, false},
{&aliasTypeString8d15, 8.15, false},
{aliasTypeString8d15Minus, -8.15, false},
{&aliasTypeString8d15Minus, -8.15, false},
{aliasTypeBool4True, 1, false},
{&aliasTypeBool4True, 1, false},
{aliasTypeBool4False, 0, false},
{&aliasTypeBool4False, 0, false},

// errors
{"10a", 0, true},
Expand Down
2 changes: 1 addition & 1 deletion int.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func convInt64(val interface{}) (int64, error) {
case int8:
return int64(vv), nil
case uint:
if strconv.IntSize == 64 && vv > math.MaxInt64 {
if strconv.IntSize == 32 && vv > math.MaxInt32 {
return 0, errConvFail
}
return int64(vv), nil
Expand Down
Loading

0 comments on commit fac4223

Please sign in to comment.