filter.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2024, Benoit BLANCHON
  3. // MIT License
  4. #define ARDUINOJSON_ENABLE_COMMENTS 1
  5. #include <ArduinoJson.h>
  6. #include <catch.hpp>
  7. #include <sstream>
  8. #include <string>
  9. #include "Allocators.hpp"
  10. using ArduinoJson::detail::sizeofArray;
  11. using ArduinoJson::detail::sizeofObject;
  12. TEST_CASE("Filtering") {
  13. struct TestCase {
  14. const char* description;
  15. const char* input;
  16. const char* filter;
  17. uint8_t nestingLimit;
  18. DeserializationError error;
  19. const char* output;
  20. size_t memoryUsage;
  21. };
  22. TestCase testCases[] = {
  23. {
  24. "Input is object, filter is null", // description
  25. "{\"hello\":\"world\"}", // input
  26. "null", // filter
  27. 10, // nestingLimit
  28. DeserializationError::Ok, // error
  29. "null", // output
  30. 0, // memoryUsage
  31. },
  32. {
  33. "Input is object, filter is false",
  34. "{\"hello\":\"world\"}",
  35. "false",
  36. 10,
  37. DeserializationError::Ok,
  38. "null",
  39. 0,
  40. },
  41. {
  42. "Input is object, filter is true",
  43. "{\"abcdefg\":\"hijklmn\"}",
  44. "true",
  45. 10,
  46. DeserializationError::Ok,
  47. "{\"abcdefg\":\"hijklmn\"}",
  48. sizeofObject(1) + sizeofString("abcdefg") + sizeofString("hijklmn"),
  49. },
  50. {
  51. "Input is object, filter is empty object",
  52. "{\"hello\":\"world\"}",
  53. "{}",
  54. 10,
  55. DeserializationError::Ok,
  56. "{}",
  57. sizeofObject(0),
  58. },
  59. {
  60. "Input in an object, but filter wants an array",
  61. "{\"hello\":\"world\"}",
  62. "[]",
  63. 10,
  64. DeserializationError::Ok,
  65. "null",
  66. 0,
  67. },
  68. {
  69. "Member is a string, but filter wants an array",
  70. "{\"example\":\"example\"}",
  71. "{\"example\":[true]}",
  72. 10,
  73. DeserializationError::Ok,
  74. "{\"example\":null}",
  75. sizeofObject(1) + sizeofString("example"),
  76. },
  77. {
  78. "Member is a number, but filter wants an array",
  79. "{\"example\":42}",
  80. "{\"example\":[true]}",
  81. 10,
  82. DeserializationError::Ok,
  83. "{\"example\":null}",
  84. sizeofObject(1) + sizeofString("example"),
  85. },
  86. {
  87. "Input is an array, but filter wants an object",
  88. "[\"hello\",\"world\"]",
  89. "{}",
  90. 10,
  91. DeserializationError::Ok,
  92. "null",
  93. 0,
  94. },
  95. {
  96. "Input is a bool, but filter wants an object",
  97. "true",
  98. "{}",
  99. 10,
  100. DeserializationError::Ok,
  101. "null",
  102. 0,
  103. },
  104. {
  105. "Input is a string, but filter wants an object",
  106. "\"hello\"",
  107. "{}",
  108. 10,
  109. DeserializationError::Ok,
  110. "null",
  111. 0,
  112. },
  113. {
  114. "Skip an integer",
  115. "{\"an_integer\":666,example:42}",
  116. "{\"example\":true}",
  117. 10,
  118. DeserializationError::Ok,
  119. "{\"example\":42}",
  120. sizeofObject(1) + sizeofString("example"),
  121. },
  122. {
  123. "Skip a float",
  124. "{\"a_float\":12.34e-6,example:42}",
  125. "{\"example\":true}",
  126. 10,
  127. DeserializationError::Ok,
  128. "{\"example\":42}",
  129. sizeofObject(1) + sizeofString("example"),
  130. },
  131. {
  132. "Skip false",
  133. "{\"a_bool\":false,example:42}",
  134. "{\"example\":true}",
  135. 10,
  136. DeserializationError::Ok,
  137. "{\"example\":42}",
  138. sizeofObject(1) + sizeofString("example"),
  139. },
  140. {
  141. "Skip true",
  142. "{\"a_bool\":true,example:42}",
  143. "{\"example\":true}",
  144. 10,
  145. DeserializationError::Ok,
  146. "{\"example\":42}",
  147. sizeofObject(1) + sizeofString("example"),
  148. },
  149. {
  150. "Skip null",
  151. "{\"a_bool\":null,example:42}",
  152. "{\"example\":true}",
  153. 10,
  154. DeserializationError::Ok,
  155. "{\"example\":42}",
  156. sizeofObject(1) + sizeofString("example"),
  157. },
  158. {
  159. "Skip a double-quoted string",
  160. "{\"a_double_quoted_string\":\"hello\",example:42}",
  161. "{\"example\":true}",
  162. 10,
  163. DeserializationError::Ok,
  164. "{\"example\":42}",
  165. sizeofObject(1) + sizeofString("example"),
  166. },
  167. {
  168. "Skip a single-quoted string",
  169. "{\"a_single_quoted_string\":'hello',example:42}",
  170. "{\"example\":true}",
  171. 10,
  172. DeserializationError::Ok,
  173. "{\"example\":42}",
  174. sizeofObject(1) + sizeofString("example"),
  175. },
  176. {
  177. "Skip an empty array",
  178. "{\"an_empty_array\":[],example:42}",
  179. "{\"example\":true}",
  180. 10,
  181. DeserializationError::Ok,
  182. "{\"example\":42}",
  183. sizeofObject(1) + sizeofString("example"),
  184. },
  185. {
  186. "Skip an empty array with spaces in it",
  187. "{\"an_empty_array\":[\t],example:42}",
  188. "{\"example\":true}",
  189. 10,
  190. DeserializationError::Ok,
  191. "{\"example\":42}",
  192. sizeofObject(1) + sizeofString("example"),
  193. },
  194. {
  195. "Skip an array",
  196. "{\"an_array\":[1,2,3],example:42}",
  197. "{\"example\":true}",
  198. 10,
  199. DeserializationError::Ok,
  200. "{\"example\":42}",
  201. sizeofObject(1) + sizeofString("example"),
  202. },
  203. {
  204. "Skip an array with spaces in it",
  205. "{\"an_array\": [ 1 , 2 , 3 ] ,example:42}",
  206. "{\"example\":true}",
  207. 10,
  208. DeserializationError::Ok,
  209. "{\"example\":42}",
  210. sizeofObject(1) + sizeofString("example"),
  211. },
  212. {
  213. "Skip an empty nested object",
  214. "{\"an_empty_object\":{},example:42}",
  215. "{\"example\":true}",
  216. 10,
  217. DeserializationError::Ok,
  218. "{\"example\":42}",
  219. sizeofObject(1) + sizeofString("example"),
  220. },
  221. {
  222. "Skip an empty nested object with spaces in it",
  223. "{\"an_empty_object\":{ },example:42}",
  224. "{\"example\":true}",
  225. 10,
  226. DeserializationError::Ok,
  227. "{\"example\":42}",
  228. sizeofObject(1) + sizeofString("example"),
  229. },
  230. {
  231. "Skip a nested object",
  232. "{\"an_object\":{a:1,'b':2,\"c\":3},example:42}",
  233. "{\"example\":true}",
  234. 10,
  235. DeserializationError::Ok,
  236. "{\"example\":42}",
  237. sizeofObject(1) + sizeofString("example"),
  238. },
  239. {
  240. "Skip an object with spaces in it",
  241. "{\"an_object\" : { a : 1 , 'b' : 2 , \"c\" : 3 } ,example:42}",
  242. "{\"example\":true}",
  243. 10,
  244. DeserializationError::Ok,
  245. "{\"example\":42}",
  246. sizeofObject(1) + sizeofString("example"),
  247. },
  248. {
  249. "Skip a string in a nested object",
  250. "{\"an_integer\": 0,\"example\":{\"type\":\"int\",\"outcome\":42}}",
  251. "{\"example\":{\"outcome\":true}}",
  252. 10,
  253. DeserializationError::Ok,
  254. "{\"example\":{\"outcome\":42}}",
  255. 2 * sizeofObject(1) + 2 * sizeofString("example"),
  256. },
  257. {
  258. "wildcard",
  259. "{\"example\":{\"type\":\"int\",\"outcome\":42}}",
  260. "{\"*\":{\"outcome\":true}}",
  261. 10,
  262. DeserializationError::Ok,
  263. "{\"example\":{\"outcome\":42}}",
  264. 2 * sizeofObject(1) + 2 * sizeofString("example"),
  265. },
  266. {
  267. "exclusion filter (issue #1628)",
  268. "{\"example\":1,\"ignored\":2}",
  269. "{\"*\":true,\"ignored\":false}",
  270. 10,
  271. DeserializationError::Ok,
  272. "{\"example\":1}",
  273. sizeofObject(1) + sizeofString("example"),
  274. },
  275. {
  276. "only the first element of array counts",
  277. "[1,2,3]",
  278. "[true, false]",
  279. 10,
  280. DeserializationError::Ok,
  281. "[1,2,3]",
  282. sizeofArray(3),
  283. },
  284. {
  285. "only the first element of array counts",
  286. "[1,2,3]",
  287. "[false, true]",
  288. 10,
  289. DeserializationError::Ok,
  290. "[]",
  291. sizeofArray(0),
  292. },
  293. {
  294. "filter members of object in array",
  295. "[{\"example\":1,\"ignore\":2},{\"example\":3,\"ignore\":4}]",
  296. "[{\"example\":true}]",
  297. 10,
  298. DeserializationError::Ok,
  299. "[{\"example\":1},{\"example\":3}]",
  300. sizeofArray(2) + 2 * sizeofObject(1) + sizeofString("example"),
  301. },
  302. {
  303. "Unclosed single quote in skipped element",
  304. "[',2,3]",
  305. "[false,true]",
  306. 10,
  307. DeserializationError::IncompleteInput,
  308. "[]",
  309. sizeofArray(0),
  310. },
  311. {
  312. "Unclosed double quote in skipped element",
  313. "[\",2,3]",
  314. "[false,true]",
  315. 10,
  316. DeserializationError::IncompleteInput,
  317. "[]",
  318. sizeofArray(0),
  319. },
  320. {
  321. "Detect errors in skipped value",
  322. "[!,2,\\]",
  323. "[false]",
  324. 10,
  325. DeserializationError::InvalidInput,
  326. "[]",
  327. sizeofArray(0),
  328. },
  329. {
  330. "Detect incomplete string event if it's skipped",
  331. "\"ABC",
  332. "false",
  333. 10,
  334. DeserializationError::IncompleteInput,
  335. "null",
  336. 0,
  337. },
  338. {
  339. "Detect incomplete string event if it's skipped",
  340. "'ABC",
  341. "false",
  342. 10,
  343. DeserializationError::IncompleteInput,
  344. "null",
  345. 0,
  346. },
  347. {
  348. "Handle escaped quotes",
  349. "'A\\'BC'",
  350. "false",
  351. 10,
  352. DeserializationError::Ok,
  353. "null",
  354. 0,
  355. },
  356. {
  357. "Handle escaped quotes",
  358. "\"A\\\"BC\"",
  359. "false",
  360. 10,
  361. DeserializationError::Ok,
  362. "null",
  363. 0,
  364. },
  365. {
  366. "Detect incomplete string in presence of escaped quotes",
  367. "'A\\'BC",
  368. "false",
  369. 10,
  370. DeserializationError::IncompleteInput,
  371. "null",
  372. 0,
  373. },
  374. {
  375. "Detect incomplete string in presence of escaped quotes",
  376. "\"A\\\"BC",
  377. "false",
  378. 10,
  379. DeserializationError::IncompleteInput,
  380. "null",
  381. 0,
  382. },
  383. {
  384. "skip empty array",
  385. "[]",
  386. "false",
  387. 10,
  388. DeserializationError::Ok,
  389. "null",
  390. 0,
  391. },
  392. {
  393. "Skip empty array with spaces",
  394. " [ ] ",
  395. "false",
  396. 10,
  397. DeserializationError::Ok,
  398. "null",
  399. 0,
  400. },
  401. {
  402. "Bubble up element error even if array is skipped",
  403. "[1,'2,3]",
  404. "false",
  405. 10,
  406. DeserializationError::IncompleteInput,
  407. "null",
  408. 0,
  409. },
  410. {
  411. "Bubble up member error even if object is skipped",
  412. "{'hello':'worl}",
  413. "false",
  414. 10,
  415. DeserializationError::IncompleteInput,
  416. "null",
  417. 0,
  418. },
  419. {
  420. "Bubble up colon error even if object is skipped",
  421. "{'hello','world'}",
  422. "false",
  423. 10,
  424. DeserializationError::InvalidInput,
  425. "null",
  426. 0,
  427. },
  428. {
  429. "Bubble up key error even if object is skipped",
  430. "{'hello:1}",
  431. "false",
  432. 10,
  433. DeserializationError::IncompleteInput,
  434. "null",
  435. 0,
  436. },
  437. {
  438. "Detect invalid value in skipped object",
  439. "{'hello':!}",
  440. "false",
  441. 10,
  442. DeserializationError::InvalidInput,
  443. "null",
  444. 0,
  445. },
  446. {
  447. "Ignore invalid value in skipped object",
  448. "{'hello':\\}",
  449. "false",
  450. 10,
  451. DeserializationError::InvalidInput,
  452. "null",
  453. 0,
  454. },
  455. {
  456. "Check nesting limit even for ignored objects",
  457. "{}",
  458. "false",
  459. 0,
  460. DeserializationError::TooDeep,
  461. "null",
  462. 0,
  463. },
  464. {
  465. "Check nesting limit even for ignored objects",
  466. "{'hello':{}}",
  467. "false",
  468. 1,
  469. DeserializationError::TooDeep,
  470. "null",
  471. 0,
  472. },
  473. {
  474. "Check nesting limit even for ignored values in objects",
  475. "{'hello':{}}",
  476. "{}",
  477. 1,
  478. DeserializationError::TooDeep,
  479. "{}",
  480. sizeofObject(0),
  481. },
  482. {
  483. "Check nesting limit even for ignored arrays",
  484. "[]",
  485. "false",
  486. 0,
  487. DeserializationError::TooDeep,
  488. "null",
  489. 0,
  490. },
  491. {
  492. "Check nesting limit even for ignored arrays",
  493. "[[]]",
  494. "false",
  495. 1,
  496. DeserializationError::TooDeep,
  497. "null",
  498. 0,
  499. },
  500. {
  501. "Check nesting limit even for ignored values in arrays",
  502. "[[]]",
  503. "[]",
  504. 1,
  505. DeserializationError::TooDeep,
  506. "[]",
  507. sizeofArray(0),
  508. },
  509. {
  510. "Supports back-slash at the end of skipped string",
  511. "\"hell\\",
  512. "false",
  513. 1,
  514. DeserializationError::IncompleteInput,
  515. "null",
  516. 0,
  517. },
  518. {
  519. "Invalid comment at after an element in a skipped array",
  520. "[1/]",
  521. "false",
  522. 10,
  523. DeserializationError::InvalidInput,
  524. "null",
  525. 0,
  526. },
  527. {
  528. "Incomplete comment at after an element in a skipped array",
  529. "[1/*]",
  530. "false",
  531. 10,
  532. DeserializationError::IncompleteInput,
  533. "null",
  534. 0,
  535. },
  536. {
  537. "Missing comma in a skipped array",
  538. "[1 2]",
  539. "false",
  540. 10,
  541. DeserializationError::InvalidInput,
  542. "null",
  543. 0,
  544. },
  545. {
  546. "Invalid comment at the beginning of array",
  547. "[/1]",
  548. "[false]",
  549. 10,
  550. DeserializationError::InvalidInput,
  551. "[]",
  552. sizeofArray(0),
  553. },
  554. {
  555. "Incomplete comment at the begining of an array",
  556. "[/*]",
  557. "[false]",
  558. 10,
  559. DeserializationError::IncompleteInput,
  560. "[]",
  561. sizeofArray(0),
  562. },
  563. {
  564. "Invalid comment before key",
  565. "{/1:2}",
  566. "{}",
  567. 10,
  568. DeserializationError::InvalidInput,
  569. "{}",
  570. sizeofObject(0),
  571. },
  572. {
  573. "Incomplete comment before key",
  574. "{/*:2}",
  575. "{}",
  576. 10,
  577. DeserializationError::IncompleteInput,
  578. "{}",
  579. sizeofObject(0),
  580. },
  581. {
  582. "Invalid comment after key",
  583. "{\"example\"/1:2}",
  584. "{}",
  585. 10,
  586. DeserializationError::InvalidInput,
  587. "{}",
  588. sizeofObject(0),
  589. },
  590. {
  591. "Incomplete comment after key",
  592. "{\"example\"/*:2}",
  593. "{}",
  594. 10,
  595. DeserializationError::IncompleteInput,
  596. "{}",
  597. sizeofObject(0),
  598. },
  599. {
  600. "Invalid comment after colon",
  601. "{\"example\":/12}",
  602. "{}",
  603. 10,
  604. DeserializationError::InvalidInput,
  605. "{}",
  606. sizeofObject(0),
  607. },
  608. {
  609. "Incomplete comment after colon",
  610. "{\"example\":/*2}",
  611. "{}",
  612. 10,
  613. DeserializationError::IncompleteInput,
  614. "{}",
  615. sizeofObject(0),
  616. },
  617. {
  618. "Comment next to an integer",
  619. "{\"ignore\":1//,\"example\":2\n}",
  620. "{\"example\":true}",
  621. 10,
  622. DeserializationError::Ok,
  623. "{}",
  624. sizeofObject(0),
  625. },
  626. {
  627. "Invalid comment after opening brace of a skipped object",
  628. "{/1:2}",
  629. "false",
  630. 10,
  631. DeserializationError::InvalidInput,
  632. "null",
  633. 0,
  634. },
  635. {
  636. "Incomplete after opening brace of a skipped object",
  637. "{/*:2}",
  638. "false",
  639. 10,
  640. DeserializationError::IncompleteInput,
  641. "null",
  642. 0,
  643. },
  644. {
  645. "Invalid comment after key of a skipped object",
  646. "{\"example\"/:2}",
  647. "false",
  648. 10,
  649. DeserializationError::InvalidInput,
  650. "null",
  651. 0,
  652. },
  653. {
  654. "Incomplete comment after key of a skipped object",
  655. "{\"example\"/*:2}",
  656. "false",
  657. 10,
  658. DeserializationError::IncompleteInput,
  659. "null",
  660. 0,
  661. },
  662. {
  663. "Invalid comment after value in a skipped object",
  664. "{\"example\":2/}",
  665. "false",
  666. 10,
  667. DeserializationError::InvalidInput,
  668. "null",
  669. 0,
  670. },
  671. {
  672. "Incomplete comment after value of a skipped object",
  673. "{\"example\":2/*}",
  674. "false",
  675. 10,
  676. DeserializationError::IncompleteInput,
  677. "null",
  678. 0,
  679. },
  680. {
  681. "Incomplete comment after comma in skipped object",
  682. "{\"example\":2,/*}",
  683. "false",
  684. 10,
  685. DeserializationError::IncompleteInput,
  686. "null",
  687. 0,
  688. },
  689. };
  690. for (auto& tc : testCases) {
  691. SECTION(tc.description) {
  692. SpyingAllocator spy;
  693. JsonDocument filter;
  694. JsonDocument doc(&spy);
  695. REQUIRE(deserializeJson(filter, tc.filter) == DeserializationError::Ok);
  696. CHECK(deserializeJson(
  697. doc, tc.input, DeserializationOption::Filter(filter),
  698. DeserializationOption::NestingLimit(tc.nestingLimit)) ==
  699. tc.error);
  700. CHECK(doc.as<std::string>() == tc.output);
  701. doc.shrinkToFit();
  702. CHECK(spy.allocatedBytes() == tc.memoryUsage);
  703. }
  704. }
  705. }
  706. TEST_CASE("Overloads") {
  707. JsonDocument doc;
  708. JsonDocument filter;
  709. using namespace DeserializationOption;
  710. // deserializeJson(..., Filter)
  711. SECTION("const char*, Filter") {
  712. deserializeJson(doc, "{}", Filter(filter));
  713. }
  714. SECTION("const char*, size_t, Filter") {
  715. deserializeJson(doc, "{}", 2, Filter(filter));
  716. }
  717. SECTION("const std::string&, Filter") {
  718. deserializeJson(doc, std::string("{}"), Filter(filter));
  719. }
  720. SECTION("std::istream&, Filter") {
  721. std::stringstream s("{}");
  722. deserializeJson(doc, s, Filter(filter));
  723. }
  724. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  725. SECTION("char[n], Filter") {
  726. size_t i = 4;
  727. char vla[i];
  728. strcpy(vla, "{}");
  729. deserializeJson(doc, vla, Filter(filter));
  730. }
  731. #endif
  732. // deserializeJson(..., Filter, NestingLimit)
  733. SECTION("const char*, Filter, NestingLimit") {
  734. deserializeJson(doc, "{}", Filter(filter), NestingLimit(5));
  735. }
  736. SECTION("const char*, size_t, Filter, NestingLimit") {
  737. deserializeJson(doc, "{}", 2, Filter(filter), NestingLimit(5));
  738. }
  739. SECTION("const std::string&, Filter, NestingLimit") {
  740. deserializeJson(doc, std::string("{}"), Filter(filter), NestingLimit(5));
  741. }
  742. SECTION("std::istream&, Filter, NestingLimit") {
  743. std::stringstream s("{}");
  744. deserializeJson(doc, s, Filter(filter), NestingLimit(5));
  745. }
  746. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  747. SECTION("char[n], Filter, NestingLimit") {
  748. size_t i = 4;
  749. char vla[i];
  750. strcpy(vla, "{}");
  751. deserializeJson(doc, vla, Filter(filter), NestingLimit(5));
  752. }
  753. #endif
  754. // deserializeJson(..., NestingLimit, Filter)
  755. SECTION("const char*, NestingLimit, Filter") {
  756. deserializeJson(doc, "{}", NestingLimit(5), Filter(filter));
  757. }
  758. SECTION("const char*, size_t, NestingLimit, Filter") {
  759. deserializeJson(doc, "{}", 2, NestingLimit(5), Filter(filter));
  760. }
  761. SECTION("const std::string&, NestingLimit, Filter") {
  762. deserializeJson(doc, std::string("{}"), NestingLimit(5), Filter(filter));
  763. }
  764. SECTION("std::istream&, NestingLimit, Filter") {
  765. std::stringstream s("{}");
  766. deserializeJson(doc, s, NestingLimit(5), Filter(filter));
  767. }
  768. #ifdef HAS_VARIABLE_LENGTH_ARRAY
  769. SECTION("char[n], NestingLimit, Filter") {
  770. size_t i = 4;
  771. char vla[i];
  772. strcpy(vla, "{}");
  773. deserializeJson(doc, vla, NestingLimit(5), Filter(filter));
  774. }
  775. #endif
  776. }
  777. TEST_CASE("shrink filter") {
  778. JsonDocument doc;
  779. SpyingAllocator spy;
  780. JsonDocument filter(&spy);
  781. filter["a"] = true;
  782. spy.clearLog();
  783. deserializeJson(doc, "{}", DeserializationOption::Filter(filter));
  784. REQUIRE(spy.log() == AllocatorLog{
  785. Reallocate(sizeofPool(), sizeofObject(1)),
  786. });
  787. }