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

Function TestAddSQLNullStringKey

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

Source from the content-addressed store, hash-verified

74}
75
76func TestAddSQLNullStringKey(t *testing.T) {
77 t.Run(
78 "AddSQLNullStringKey",
79 func(t *testing.T) {
80 testCases := []struct {
81 name string
82 sqlNullString sql.NullString
83 baseJSON string
84 expectedResult string
85 err bool
86 }{
87 {
88 name: "it should encode a null string",
89 sqlNullString: sql.NullString{
90 String: "foo bar",
91 },
92 baseJSON: "{",
93 expectedResult: `{"foo":"foo bar"`,
94 },
95 {
96 name: "it should encode a null string",
97 sqlNullString: sql.NullString{
98 String: "foo \t bar",
99 },
100 baseJSON: "{",
101 expectedResult: `{"foo":"foo \t bar"`,
102 },
103 {
104 name: "it should encode a null string",
105 sqlNullString: sql.NullString{
106 String: "foo \t bar",
107 },
108 baseJSON: "{",
109 expectedResult: `{"foo":"foo \t bar"`,
110 },
111 }
112
113 for _, testCase := range testCases {
114 t.Run(testCase.name, func(t *testing.T) {
115 var b strings.Builder
116 enc := NewEncoder(&b)
117 enc.writeString(testCase.baseJSON)
118 enc.AddSQLNullStringKey("foo", &testCase.sqlNullString)
119 enc.Write()
120 assert.Equal(t, testCase.expectedResult, b.String())
121
122 var b2 strings.Builder
123 enc = NewEncoder(&b2)
124 enc.writeString(testCase.baseJSON)
125 enc.SQLNullStringKey("foo", &testCase.sqlNullString)
126 enc.Write()
127 assert.Equal(t, testCase.expectedResult, b2.String())
128 })
129 }
130 },
131 )
132 t.Run(
133 "AddSQLNullStringKeyOmitEmpty, is should encode a sql.NullString",

Callers

nothing calls this directly

Calls 8

writeStringMethod · 0.95
AddSQLNullStringKeyMethod · 0.95
WriteMethod · 0.95
SQLNullStringKeyMethod · 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…