Skip to content

Commit 811cc78

Browse files
author
James Cor
committed
number tests
1 parent d6c2f7f commit 811cc78

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

sql/types/number_test.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,27 @@ func TestNumberConvertRound(t *testing.T) {
252252
inRange sql.ConvertInRange
253253
}{
254254
// Boolean, Int8, Uint8, ... all use convertToInt64
255+
{
256+
typ: Int64,
257+
inp: "",
258+
exp: int64(0),
259+
err: false,
260+
inRange: sql.InRange,
261+
},
262+
{
263+
typ: Int64,
264+
inp: " \t",
265+
exp: int64(0),
266+
err: false,
267+
inRange: sql.InRange,
268+
},
269+
{
270+
typ: Int64,
271+
inp: "!@#$%^&*()",
272+
exp: int64(0),
273+
err: true,
274+
inRange: sql.InRange,
275+
},
255276
{
256277
typ: Int64,
257278
inp: "1.1",
@@ -280,6 +301,77 @@ func TestNumberConvertRound(t *testing.T) {
280301
err: true,
281302
inRange: sql.InRange,
282303
},
304+
{
305+
typ: Int64,
306+
inp: ".123ABC",
307+
exp: int64(0),
308+
err: true,
309+
inRange: sql.InRange,
310+
},
311+
{
312+
typ: Int64,
313+
inp: "1.1.1",
314+
exp: int64(1),
315+
err: true,
316+
inRange: sql.InRange,
317+
},
318+
{
319+
typ: Int64,
320+
inp: "+1",
321+
exp: int64(1),
322+
err: false,
323+
inRange: sql.InRange,
324+
},
325+
{
326+
typ: Int64,
327+
inp: "-1",
328+
exp: int64(-1),
329+
err: false,
330+
inRange: sql.InRange,
331+
},
332+
{
333+
typ: Int64,
334+
inp: "+ 1",
335+
exp: int64(0),
336+
err: true,
337+
inRange: sql.InRange,
338+
},
339+
{
340+
typ: Int64,
341+
inp: "- 1",
342+
exp: int64(0),
343+
err: true,
344+
inRange: sql.InRange,
345+
},
346+
{
347+
typ: Int64,
348+
inp: "+-+-1",
349+
exp: int64(0),
350+
err: false,
351+
inRange: sql.InRange,
352+
},
353+
354+
{
355+
typ: Uint64,
356+
inp: "",
357+
exp: uint64(0),
358+
err: false,
359+
inRange: sql.InRange,
360+
},
361+
{
362+
typ: Uint64,
363+
inp: " \t",
364+
exp: uint64(0),
365+
err: false,
366+
inRange: sql.InRange,
367+
},
368+
{
369+
typ: Uint64,
370+
inp: "!@#$%^&*()",
371+
exp: uint64(0),
372+
err: true,
373+
inRange: sql.InRange,
374+
},
283375
{
284376
typ: Uint64,
285377
inp: "1.1",
@@ -308,6 +400,55 @@ func TestNumberConvertRound(t *testing.T) {
308400
err: true,
309401
inRange: sql.InRange,
310402
},
403+
{
404+
typ: Uint64,
405+
inp: ".123ABC",
406+
exp: uint64(0),
407+
err: true,
408+
inRange: sql.InRange,
409+
},
410+
{
411+
typ: Uint64,
412+
inp: "1.1.1",
413+
exp: uint64(1),
414+
err: true,
415+
inRange: sql.InRange,
416+
},
417+
{
418+
typ: Uint64,
419+
inp: "+1",
420+
exp: uint64(1),
421+
err: false,
422+
inRange: sql.InRange,
423+
},
424+
{
425+
typ: Uint64,
426+
inp: "-1",
427+
exp: uint64(math.MaxUint64),
428+
err: false,
429+
inRange: sql.OutOfRange,
430+
},
431+
{
432+
typ: Uint64,
433+
inp: "+ 1",
434+
exp: uint64(0),
435+
err: true,
436+
inRange: sql.InRange,
437+
},
438+
{
439+
typ: Uint64,
440+
inp: "- 1",
441+
exp: uint64(0),
442+
err: true,
443+
inRange: sql.InRange,
444+
},
445+
{
446+
typ: Uint64,
447+
inp: "+-+-1",
448+
exp: uint64(0),
449+
err: false,
450+
inRange: sql.InRange,
451+
},
311452
}
312453

313454
for _, test := range tests {

0 commit comments

Comments
 (0)