(t *testing.T)
| 181 | } |
| 182 | |
| 183 | func 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", |
nothing calls this directly
no test coverage detected
searching dependent graphs…