github.com/blend/go-sdk@v1.20220411.3/validate/int8_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package validate 9 10 import ( 11 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func TestInt8Min(t *testing.T) { 17 assert := assert.New(t) 18 19 var verr error 20 var val int8 = 10 21 verr = Int8(&val).Min(1)() 22 assert.Nil(verr) 23 24 val = 10 25 verr = Int8(&val).Min(10)() 26 assert.Nil(verr) 27 28 verr = Int8(nil).Min(10)() 29 assert.NotNil(verr) 30 assert.Nil(ErrValue(verr)) 31 assert.Equal(ErrInt8Min, ErrCause(verr)) 32 33 val = 1 34 verr = Int8(&val).Min(10)() 35 assert.NotNil(verr) 36 assert.NotNil(ErrValue(verr)) 37 assert.Equal(ErrInt8Min, ErrCause(verr)) 38 39 val = 10 40 verr = Int8(&val).Min(10)() 41 assert.Nil(verr) 42 } 43 44 func TestInt8Max(t *testing.T) { 45 assert := assert.New(t) 46 47 var verr error 48 var val int8 = 1 49 verr = Int8(&val).Max(10)() 50 assert.Nil(verr) 51 52 verr = Int8(nil).Max(10)() 53 assert.Nil(verr) 54 55 val = 10 56 verr = Int8(&val).Max(10)() 57 assert.Nil(verr) 58 59 val = 11 60 verr = Int8(&val).Max(10)() 61 assert.NotNil(verr) 62 assert.NotNil(ErrValue(verr)) 63 assert.Equal(ErrInt8Max, ErrCause(verr)) 64 } 65 66 func TestInt8Between(t *testing.T) { 67 assert := assert.New(t) 68 69 var verr error 70 var val int8 = 5 71 verr = Int8(&val).Between(1, 10)() 72 assert.Nil(verr) 73 74 verr = Int8(nil).Between(5, 10)() 75 assert.NotNil(verr) 76 assert.Nil(ErrValue(verr)) 77 assert.Equal(ErrInt8Min, ErrCause(verr)) 78 79 val = 1 80 verr = Int8(&val).Between(5, 10)() 81 assert.NotNil(verr) 82 assert.Equal(1, ErrValue(verr)) 83 assert.Equal(ErrInt8Min, ErrCause(verr)) 84 85 val = 5 86 verr = Int8(&val).Between(5, 10)() 87 assert.Nil(verr) 88 89 val = 10 90 verr = Int8(&val).Between(5, 10)() 91 assert.Nil(verr) 92 93 val = 11 94 verr = Int8(&val).Between(5, 10)() 95 assert.NotNil(verr) 96 assert.Equal(11, ErrValue(verr)) 97 assert.Equal(ErrInt8Max, ErrCause(verr)) 98 } 99 100 func TestInt8Positive(t *testing.T) { 101 assert := assert.New(t) 102 103 var verr error 104 var val int8 = 5 105 verr = Int8(&val).Positive()() 106 assert.Nil(verr) 107 108 verr = Int8(nil).Positive()() 109 assert.NotNil(verr) 110 assert.Nil(ErrValue(verr)) 111 assert.Equal(ErrInt8Positive, ErrCause(verr)) 112 113 val = -5 114 verr = Int8(&val).Positive()() 115 assert.NotNil(verr) 116 assert.NotNil(ErrValue(verr)) 117 assert.Equal(ErrInt8Positive, ErrCause(verr)) 118 } 119 120 func TestInt8Negative(t *testing.T) { 121 assert := assert.New(t) 122 123 var verr error 124 var val int8 = -5 125 verr = Int8(&val).Negative()() 126 assert.Nil(verr) 127 128 verr = Int8(nil).Negative()() 129 assert.NotNil(verr) 130 assert.Nil(ErrValue(verr)) 131 assert.Equal(ErrInt8Negative, ErrCause(verr)) 132 133 val = 5 134 verr = Int8(&val).Negative()() 135 assert.NotNil(verr) 136 assert.NotNil(ErrValue(verr)) 137 assert.Equal(ErrInt8Negative, ErrCause(verr)) 138 } 139 140 func TestInt8Zero(t *testing.T) { 141 assert := assert.New(t) 142 143 var verr error 144 var val int8 = 0 145 verr = Int8(&val).Zero()() 146 assert.Nil(verr) 147 148 verr = Int8(nil).Zero()() 149 assert.NotNil(verr) 150 assert.Nil(ErrValue(verr)) 151 assert.Equal(ErrInt8Zero, ErrCause(verr)) 152 153 val = 5 154 verr = Int8(&val).Zero()() 155 assert.NotNil(verr) 156 assert.NotNil(ErrValue(verr)) 157 assert.Equal(ErrInt8Zero, ErrCause(verr)) 158 } 159 160 func TestInt8NotZero(t *testing.T) { 161 assert := assert.New(t) 162 163 var verr error 164 var val int8 = 5 165 verr = Int8(&val).NotZero()() 166 assert.Nil(verr) 167 168 verr = Int8(nil).NotZero()() 169 assert.NotNil(verr) 170 assert.Nil(ErrValue(verr)) 171 assert.Equal(ErrInt8NotZero, ErrCause(verr)) 172 173 val = 0 174 verr = Int8(&val).NotZero()() 175 assert.NotNil(verr) 176 assert.NotNil(ErrValue(verr)) 177 assert.Equal(ErrInt8NotZero, ErrCause(verr)) 178 }