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

Function TestAddSQLNullBoolKey

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

Source from the content-addressed store, hash-verified

907}
908
909func TestAddSQLNullBoolKey(t *testing.T) {
910 t.Run(
911 "AddSQLNullBoolKey",
912 func(t *testing.T) {
913 testCases := []struct {
914 name string
915 sqlNullBool sql.NullBool
916 baseJSON string
917 expectedResult string
918 err bool
919 }{
920 {
921 name: "it should encode a null string",
922 sqlNullBool: sql.NullBool{
923 Bool: true,
924 },
925 baseJSON: "{",
926 expectedResult: `{"foo":true`,
927 },
928 {
929 name: "it should encode a null string",
930 sqlNullBool: sql.NullBool{
931 Bool: false,
932 },
933 baseJSON: "{",
934 expectedResult: `{"foo":false`,
935 },
936 {
937 name: "it should encode a null string",
938 sqlNullBool: sql.NullBool{
939 Bool: true,
940 },
941 baseJSON: "{",
942 expectedResult: `{"foo":true`,
943 },
944 }
945
946 for _, testCase := range testCases {
947 t.Run(testCase.name, func(t *testing.T) {
948 var b strings.Builder
949 enc := NewEncoder(&b)
950 enc.writeString(testCase.baseJSON)
951 enc.AddSQLNullBoolKey("foo", &testCase.sqlNullBool)
952 enc.Write()
953 assert.Equal(t, testCase.expectedResult, b.String())
954
955 var b2 strings.Builder
956 enc = NewEncoder(&b2)
957 enc.writeString(testCase.baseJSON)
958 enc.SQLNullBoolKey("foo", &testCase.sqlNullBool)
959 enc.Write()
960 assert.Equal(t, testCase.expectedResult, b2.String())
961 })
962 }
963 },
964 )
965 t.Run(
966 "AddSQLNullBoolKeyOmitEmpty, is should encode a sql.NullBool",

Callers

nothing calls this directly

Calls 8

writeStringMethod · 0.95
AddSQLNullBoolKeyMethod · 0.95
WriteMethod · 0.95
SQLNullBoolKeyMethod · 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…