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

Function TestAddSQLNullString

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

Source from the content-addressed store, hash-verified

181}
182
183func TestAddSQLNullString(t *testing.T) {
184 t.Run(
185 "AddSQLNullString",
186 func(t *testing.T) {
187 testCases := []struct {
188 name string
189 sqlNullString sql.NullString
190 baseJSON string
191 expectedResult string
192 err bool
193 }{
194 {
195 name: "it should encode a null string",
196 sqlNullString: sql.NullString{
197 String: "foo bar",
198 },
199 baseJSON: "[",
200 expectedResult: `["foo bar"`,
201 },
202 {
203 name: "it should encode a null string",
204 sqlNullString: sql.NullString{
205 String: "foo \t bar",
206 },
207 baseJSON: "[",
208 expectedResult: `["foo \t bar"`,
209 },
210 {
211 name: "it should encode a null string",
212 sqlNullString: sql.NullString{
213 String: "foo \t bar",
214 },
215 baseJSON: "[",
216 expectedResult: `["foo \t bar"`,
217 },
218 }
219
220 for _, testCase := range testCases {
221 t.Run(testCase.name, func(t *testing.T) {
222 var b strings.Builder
223 enc := NewEncoder(&b)
224 enc.writeString(testCase.baseJSON)
225 enc.AddSQLNullString(&testCase.sqlNullString)
226 enc.Write()
227 assert.Equal(t, testCase.expectedResult, b.String())
228
229 var b2 strings.Builder
230 enc = NewEncoder(&b2)
231 enc.writeString(testCase.baseJSON)
232 enc.SQLNullString(&testCase.sqlNullString)
233 enc.Write()
234 assert.Equal(t, testCase.expectedResult, b2.String())
235 })
236 }
237 },
238 )
239 t.Run(
240 "AddSQLNullStringKeyOmitEmpty, is should encode a sql.NullString",

Callers

nothing calls this directly

Calls 8

writeStringMethod · 0.95
AddSQLNullStringMethod · 0.95
WriteMethod · 0.95
SQLNullStringMethod · 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…