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

Function TestAddSQLNullBool

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

Source from the content-addressed store, hash-verified

1014}
1015
1016func TestAddSQLNullBool(t *testing.T) {
1017 t.Run(
1018 "AddSQLNullBool",
1019 func(t *testing.T) {
1020 testCases := []struct {
1021 name string
1022 sqlNullBool sql.NullBool
1023 baseJSON string
1024 expectedResult string
1025 err bool
1026 }{
1027 {
1028 name: "it should encode a null string",
1029 sqlNullBool: sql.NullBool{
1030 Bool: true,
1031 },
1032 baseJSON: "[",
1033 expectedResult: `[true`,
1034 },
1035 {
1036 name: "it should encode a null string",
1037 sqlNullBool: sql.NullBool{
1038 Bool: true,
1039 },
1040 baseJSON: "[",
1041 expectedResult: `[true`,
1042 },
1043 {
1044 name: "it should encode a null string",
1045 sqlNullBool: sql.NullBool{
1046 Bool: false,
1047 },
1048 baseJSON: "[",
1049 expectedResult: `[false`,
1050 },
1051 }
1052
1053 for _, testCase := range testCases {
1054 t.Run(testCase.name, func(t *testing.T) {
1055 var b strings.Builder
1056 enc := NewEncoder(&b)
1057 enc.writeString(testCase.baseJSON)
1058 enc.AddSQLNullBool(&testCase.sqlNullBool)
1059 enc.Write()
1060 assert.Equal(t, testCase.expectedResult, b.String())
1061
1062 var b2 strings.Builder
1063 enc = NewEncoder(&b2)
1064 enc.writeString(testCase.baseJSON)
1065 enc.SQLNullBool(&testCase.sqlNullBool)
1066 enc.Write()
1067 assert.Equal(t, testCase.expectedResult, b2.String())
1068 })
1069 }
1070 },
1071 )
1072 t.Run(
1073 "AddSQLNullBoolKeyOmitEmpty, is should encode a sql.NullBool",

Callers

nothing calls this directly

Calls 8

writeStringMethod · 0.95
AddSQLNullBoolMethod · 0.95
WriteMethod · 0.95
SQLNullBoolMethod · 0.95
SQLNullBoolOmitEmptyMethod · 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…