MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestAddSQLNullInt64Key

Function TestAddSQLNullInt64Key

encode_sqlnull_test.go:353–458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

351}
352
353func TestAddSQLNullInt64Key(t *testing.T) {
354 t.Run(
355 "AddSQLNullInt64Key",
356 func(t *testing.T) {
357 testCases := []struct {
358 name string
359 sqlNullInt64 sql.NullInt64
360 baseJSON string
361 expectedResult string
362 err bool
363 }{
364 {
365 name: "it should encode a null string",
366 sqlNullInt64: sql.NullInt64{
367 Int64: 1,
368 },
369 baseJSON: "{",
370 expectedResult: `{"foo":1`,
371 },
372 {
373 name: "it should encode a null string",
374 sqlNullInt64: sql.NullInt64{
375 Int64: 2,
376 },
377 baseJSON: "{",
378 expectedResult: `{"foo":2`,
379 },
380 {
381 name: "it should encode a null string",
382 sqlNullInt64: sql.NullInt64{
383 Int64: 2,
384 },
385 baseJSON: "{",
386 expectedResult: `{"foo":2`,
387 },
388 }
389
390 for _, testCase := range testCases {
391 t.Run(testCase.name, func(t *testing.T) {
392 var b strings.Builder
393 enc := NewEncoder(&b)
394 enc.writeString(testCase.baseJSON)
395 enc.AddSQLNullInt64Key("foo", &testCase.sqlNullInt64)
396 enc.Write()
397 assert.Equal(t, testCase.expectedResult, b.String())
398
399 var b2 strings.Builder
400 enc = NewEncoder(&b2)
401 enc.writeString(testCase.baseJSON)
402 enc.SQLNullInt64Key("foo", &testCase.sqlNullInt64)
403 enc.Write()
404 assert.Equal(t, testCase.expectedResult, b2.String())
405 })
406 }
407 },
408 )
409 t.Run(
410 "AddSQLNullInt64KeyOmitEmpty, is should encode a sql.NullInt64",

Callers

nothing calls this directly

Calls 8

writeStringMethod · 0.95
AddSQLNullInt64KeyMethod · 0.95
WriteMethod · 0.95
SQLNullInt64KeyMethod · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…