MCPcopy
hub / github.com/gogf/gf / Test_ConvertValueForLocal

Function Test_ConvertValueForLocal

contrib/drivers/pgsql/pgsql_z_unit_convert_test.go:167–383  ·  view source on GitHub ↗

Test_ConvertValueForLocal tests the ConvertValueForLocal method

(t *testing.T)

Source from the content-addressed store, hash-verified

165
166// Test_ConvertValueForLocal tests the ConvertValueForLocal method
167func Test_ConvertValueForLocal(t *testing.T) {
168 var (
169 ctx = context.Background()
170 driver = pgsql.Driver{}
171 )
172
173 gtest.C(t, func(t *gtest.T) {
174 // Test _int2 array conversion
175 result, err := driver.ConvertValueForLocal(ctx, "_int2", []byte(`{1,2,3}`))
176 t.AssertNil(err)
177 t.Assert(result, []int32{1, 2, 3})
178 })
179
180 gtest.C(t, func(t *gtest.T) {
181 // Test _int4 array conversion
182 result, err := driver.ConvertValueForLocal(ctx, "_int4", []byte(`{10,20,30}`))
183 t.AssertNil(err)
184 t.Assert(result, []int32{10, 20, 30})
185 })
186
187 gtest.C(t, func(t *gtest.T) {
188 // Test _int8 array conversion
189 result, err := driver.ConvertValueForLocal(ctx, "_int8", []byte(`{100,200,300}`))
190 t.AssertNil(err)
191 t.Assert(result, []int64{100, 200, 300})
192 })
193
194 gtest.C(t, func(t *gtest.T) {
195 // Test _float4 array conversion
196 result, err := driver.ConvertValueForLocal(ctx, "_float4", []byte(`{1.1,2.2,3.3}`))
197 t.AssertNil(err)
198 resultArr := result.([]float32)
199 t.Assert(len(resultArr), 3)
200 t.Assert(resultArr[0] > 1.0 && resultArr[0] < 1.2, true)
201 t.Assert(resultArr[1] > 2.1 && resultArr[1] < 2.3, true)
202 t.Assert(resultArr[2] > 3.2 && resultArr[2] < 3.4, true)
203 })
204
205 gtest.C(t, func(t *gtest.T) {
206 // Test _float8 array conversion
207 result, err := driver.ConvertValueForLocal(ctx, "_float8", []byte(`{1.11,2.22,3.33}`))
208 t.AssertNil(err)
209 resultArr := result.([]float64)
210 t.Assert(len(resultArr), 3)
211 t.Assert(resultArr[0] > 1.1 && resultArr[0] < 1.12, true)
212 t.Assert(resultArr[1] > 2.21 && resultArr[1] < 2.23, true)
213 t.Assert(resultArr[2] > 3.32 && resultArr[2] < 3.34, true)
214 })
215
216 gtest.C(t, func(t *gtest.T) {
217 // Test _bool array conversion
218 result, err := driver.ConvertValueForLocal(ctx, "_bool", []byte(`{t,f,t}`))
219 t.AssertNil(err)
220 t.Assert(result, []bool{true, false, true})
221 })
222
223 gtest.C(t, func(t *gtest.T) {
224 // Test _varchar array conversion

Callers

nothing calls this directly

Calls 6

CFunction · 0.92
AssertNilMethod · 0.80
AssertMethod · 0.80
AssertNEMethod · 0.80
ConvertValueForLocalMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…