File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -241,3 +241,42 @@ TEST_CASE("std::string") {
241
241
REQUIRE (sizeBefore == sizeAfter);
242
242
}
243
243
}
244
+
245
+ class NullString {};
246
+
247
+ namespace ArduinoJson {
248
+ namespace Internals {
249
+ template <>
250
+ struct StringTraits <NullString> {
251
+ typedef const char *duplicate_t ;
252
+
253
+ template <typename Buffer>
254
+ static duplicate_t duplicate (const NullString &, Buffer *) {
255
+ return NULL ;
256
+ }
257
+
258
+ static bool is_null (const NullString &) {
259
+ return true ;
260
+ }
261
+
262
+ static const bool has_append = false ;
263
+ static const bool has_equals = false ;
264
+ static const bool should_duplicate = true ;
265
+ };
266
+ } // namespace Internals
267
+ } // namespace ArduinoJson
268
+
269
+ TEST_CASE (" A String that returns null" ) {
270
+ DynamicJsonBuffer jb;
271
+
272
+ SECTION (" JsonBuffer_DontGrowWhenReusingKey" ) {
273
+ JsonObject &object = jb.createObject ();
274
+ std::string key (" hello" );
275
+
276
+ object[" hello" ] = NullString ();
277
+
278
+ std::string json;
279
+ object.printTo (json);
280
+ REQUIRE (json == " {\" hello\" :null}" );
281
+ }
282
+ }
You can’t perform that action at this time.
0 commit comments