unit-testsuites.cpp 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. // __ _____ _____ _____
  2. // __| | __| | | | JSON for Modern C++ (supporting code)
  3. // | | |__ | | | | | | version 3.11.2
  4. // |_____|_____|_____|_|___| https://github.com/nlohmann/json
  5. //
  6. // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
  7. // SPDX-License-Identifier: MIT
  8. #include "doctest_compatibility.h"
  9. #include <nlohmann/json.hpp>
  10. using nlohmann::json;
  11. #include <fstream>
  12. #include "make_test_data_available.hpp"
  13. TEST_CASE("compliance tests from json.org")
  14. {
  15. // test cases are from https://json.org/JSON_checker/
  16. SECTION("expected failures")
  17. {
  18. for (const auto* filename :
  19. {
  20. //TEST_DATA_DIRECTORY "/json_tests/fail1.json",
  21. TEST_DATA_DIRECTORY "/json_tests/fail2.json",
  22. TEST_DATA_DIRECTORY "/json_tests/fail3.json",
  23. TEST_DATA_DIRECTORY "/json_tests/fail4.json",
  24. TEST_DATA_DIRECTORY "/json_tests/fail5.json",
  25. TEST_DATA_DIRECTORY "/json_tests/fail6.json",
  26. TEST_DATA_DIRECTORY "/json_tests/fail7.json",
  27. TEST_DATA_DIRECTORY "/json_tests/fail8.json",
  28. TEST_DATA_DIRECTORY "/json_tests/fail9.json",
  29. TEST_DATA_DIRECTORY "/json_tests/fail10.json",
  30. TEST_DATA_DIRECTORY "/json_tests/fail11.json",
  31. TEST_DATA_DIRECTORY "/json_tests/fail12.json",
  32. TEST_DATA_DIRECTORY "/json_tests/fail13.json",
  33. TEST_DATA_DIRECTORY "/json_tests/fail14.json",
  34. TEST_DATA_DIRECTORY "/json_tests/fail15.json",
  35. TEST_DATA_DIRECTORY "/json_tests/fail16.json",
  36. TEST_DATA_DIRECTORY "/json_tests/fail17.json",
  37. //TEST_DATA_DIRECTORY "/json_tests/fail18.json",
  38. TEST_DATA_DIRECTORY "/json_tests/fail19.json",
  39. TEST_DATA_DIRECTORY "/json_tests/fail20.json",
  40. TEST_DATA_DIRECTORY "/json_tests/fail21.json",
  41. TEST_DATA_DIRECTORY "/json_tests/fail22.json",
  42. TEST_DATA_DIRECTORY "/json_tests/fail23.json",
  43. TEST_DATA_DIRECTORY "/json_tests/fail24.json",
  44. TEST_DATA_DIRECTORY "/json_tests/fail25.json",
  45. TEST_DATA_DIRECTORY "/json_tests/fail26.json",
  46. TEST_DATA_DIRECTORY "/json_tests/fail27.json",
  47. TEST_DATA_DIRECTORY "/json_tests/fail28.json",
  48. TEST_DATA_DIRECTORY "/json_tests/fail29.json",
  49. TEST_DATA_DIRECTORY "/json_tests/fail30.json",
  50. TEST_DATA_DIRECTORY "/json_tests/fail31.json",
  51. TEST_DATA_DIRECTORY "/json_tests/fail32.json",
  52. TEST_DATA_DIRECTORY "/json_tests/fail33.json"
  53. })
  54. {
  55. CAPTURE(filename)
  56. std::ifstream f(filename);
  57. json _;
  58. CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
  59. }
  60. }
  61. SECTION("no failures with trailing literals (relaxed)")
  62. {
  63. // these tests fail above, because the parser does not end on EOF;
  64. // they succeed when the operator>> is used, because it does not
  65. // have this constraint
  66. for (const auto* filename :
  67. {
  68. TEST_DATA_DIRECTORY "/json_tests/fail7.json",
  69. TEST_DATA_DIRECTORY "/json_tests/fail8.json",
  70. TEST_DATA_DIRECTORY "/json_tests/fail10.json",
  71. })
  72. {
  73. CAPTURE(filename)
  74. std::ifstream f(filename);
  75. json j;
  76. CHECK_NOTHROW(f >> j);
  77. }
  78. }
  79. SECTION("expected passes")
  80. {
  81. for (const auto* filename :
  82. {
  83. TEST_DATA_DIRECTORY "/json_tests/pass1.json",
  84. TEST_DATA_DIRECTORY "/json_tests/pass2.json",
  85. TEST_DATA_DIRECTORY "/json_tests/pass3.json"
  86. })
  87. {
  88. CAPTURE(filename)
  89. std::ifstream f(filename);
  90. json j;
  91. CHECK_NOTHROW(f >> j);
  92. }
  93. }
  94. }
  95. TEST_CASE("compliance tests from nativejson-benchmark")
  96. {
  97. // test cases from https://github.com/miloyip/nativejson-benchmark/blob/master/src/main.cpp
  98. SECTION("doubles")
  99. {
  100. auto TEST_DOUBLE = [](const std::string & json_string, const double expected)
  101. {
  102. CAPTURE(json_string)
  103. CAPTURE(expected)
  104. CHECK(json::parse(json_string)[0].get<double>() == Approx(expected));
  105. };
  106. TEST_DOUBLE("[0.0]", 0.0);
  107. TEST_DOUBLE("[-0.0]", -0.0);
  108. TEST_DOUBLE("[1.0]", 1.0);
  109. TEST_DOUBLE("[-1.0]", -1.0);
  110. TEST_DOUBLE("[1.5]", 1.5);
  111. TEST_DOUBLE("[-1.5]", -1.5);
  112. TEST_DOUBLE("[3.1416]", 3.1416);
  113. TEST_DOUBLE("[1E10]", 1E10);
  114. TEST_DOUBLE("[1e10]", 1e10);
  115. TEST_DOUBLE("[1E+10]", 1E+10);
  116. TEST_DOUBLE("[1E-10]", 1E-10);
  117. TEST_DOUBLE("[-1E10]", -1E10);
  118. TEST_DOUBLE("[-1e10]", -1e10);
  119. TEST_DOUBLE("[-1E+10]", -1E+10);
  120. TEST_DOUBLE("[-1E-10]", -1E-10);
  121. TEST_DOUBLE("[1.234E+10]", 1.234E+10);
  122. TEST_DOUBLE("[1.234E-10]", 1.234E-10);
  123. TEST_DOUBLE("[1.79769e+308]", 1.79769e+308);
  124. TEST_DOUBLE("[2.22507e-308]", 2.22507e-308);
  125. TEST_DOUBLE("[-1.79769e+308]", -1.79769e+308);
  126. TEST_DOUBLE("[-2.22507e-308]", -2.22507e-308);
  127. TEST_DOUBLE("[4.9406564584124654e-324]", 4.9406564584124654e-324); // minimum denormal
  128. TEST_DOUBLE("[2.2250738585072009e-308]", 2.2250738585072009e-308); // Max subnormal double
  129. TEST_DOUBLE("[2.2250738585072014e-308]", 2.2250738585072014e-308); // Min normal positive double
  130. TEST_DOUBLE("[1.7976931348623157e+308]", 1.7976931348623157e+308); // Max double
  131. TEST_DOUBLE("[1e-10000]", 0.0); // must underflow
  132. TEST_DOUBLE("[18446744073709551616]",
  133. 18446744073709551616.0); // 2^64 (max of uint64_t + 1, force to use double)
  134. TEST_DOUBLE("[-9223372036854775809]",
  135. -9223372036854775809.0); // -2^63 - 1(min of int64_t + 1, force to use double)
  136. TEST_DOUBLE("[0.9868011474609375]",
  137. 0.9868011474609375); // https://github.com/miloyip/rapidjson/issues/120
  138. TEST_DOUBLE("[123e34]", 123e34); // Fast Path Cases In Disguise
  139. TEST_DOUBLE("[45913141877270640000.0]", 45913141877270640000.0);
  140. TEST_DOUBLE("[2.2250738585072011e-308]",
  141. 2.2250738585072011e-308);
  142. //TEST_DOUBLE("[1e-00011111111111]", 0.0);
  143. //TEST_DOUBLE("[-1e-00011111111111]", -0.0);
  144. TEST_DOUBLE("[1e-214748363]", 0.0);
  145. TEST_DOUBLE("[1e-214748364]", 0.0);
  146. //TEST_DOUBLE("[1e-21474836311]", 0.0);
  147. TEST_DOUBLE("[0.017976931348623157e+310]", 1.7976931348623157e+308); // Max double in another form
  148. // Since
  149. // abs((2^-1022 - 2^-1074) - 2.2250738585072012e-308) = 3.109754131239141401123495768877590405345064751974375599... ¡Á 10^-324
  150. // abs((2^-1022) - 2.2250738585072012e-308) = 1.830902327173324040642192159804623318305533274168872044... ¡Á 10 ^ -324
  151. // So 2.2250738585072012e-308 should round to 2^-1022 = 2.2250738585072014e-308
  152. TEST_DOUBLE("[2.2250738585072012e-308]",
  153. 2.2250738585072014e-308);
  154. // More closer to normal/subnormal boundary
  155. // boundary = 2^-1022 - 2^-1075 = 2.225073858507201136057409796709131975934819546351645648... ¡Á 10^-308
  156. TEST_DOUBLE("[2.22507385850720113605740979670913197593481954635164564e-308]",
  157. 2.2250738585072009e-308);
  158. TEST_DOUBLE("[2.22507385850720113605740979670913197593481954635164565e-308]",
  159. 2.2250738585072014e-308);
  160. // 1.0 is in (1.0 - 2^-54, 1.0 + 2^-53)
  161. // 1.0 - 2^-54 = 0.999999999999999944488848768742172978818416595458984375
  162. TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984375]", 1.0); // round to even
  163. TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984374]",
  164. 0.99999999999999989); // previous double
  165. TEST_DOUBLE("[0.999999999999999944488848768742172978818416595458984376]", 1.0); // next double
  166. // 1.0 + 2^-53 = 1.00000000000000011102230246251565404236316680908203125
  167. TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203125]", 1.0); // round to even
  168. TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203124]", 1.0); // previous double
  169. TEST_DOUBLE("[1.00000000000000011102230246251565404236316680908203126]",
  170. 1.00000000000000022); // next double
  171. // Numbers from https://github.com/floitsch/double-conversion/blob/master/test/cctest/test-strtod.cc
  172. TEST_DOUBLE("[72057594037927928.0]", 72057594037927928.0);
  173. TEST_DOUBLE("[72057594037927936.0]", 72057594037927936.0);
  174. TEST_DOUBLE("[72057594037927932.0]", 72057594037927936.0);
  175. TEST_DOUBLE("[7205759403792793199999e-5]", 72057594037927928.0);
  176. TEST_DOUBLE("[7205759403792793200001e-5]", 72057594037927936.0);
  177. TEST_DOUBLE("[9223372036854774784.0]", 9223372036854774784.0);
  178. TEST_DOUBLE("[9223372036854775808.0]", 9223372036854775808.0);
  179. TEST_DOUBLE("[9223372036854775296.0]", 9223372036854775808.0);
  180. TEST_DOUBLE("[922337203685477529599999e-5]", 9223372036854774784.0);
  181. TEST_DOUBLE("[922337203685477529600001e-5]", 9223372036854775808.0);
  182. TEST_DOUBLE("[10141204801825834086073718800384]", 10141204801825834086073718800384.0);
  183. TEST_DOUBLE("[10141204801825835211973625643008]", 10141204801825835211973625643008.0);
  184. TEST_DOUBLE("[10141204801825834649023672221696]", 10141204801825835211973625643008.0);
  185. TEST_DOUBLE("[1014120480182583464902367222169599999e-5]", 10141204801825834086073718800384.0);
  186. TEST_DOUBLE("[1014120480182583464902367222169600001e-5]", 10141204801825835211973625643008.0);
  187. TEST_DOUBLE("[5708990770823838890407843763683279797179383808]",
  188. 5708990770823838890407843763683279797179383808.0);
  189. TEST_DOUBLE("[5708990770823839524233143877797980545530986496]",
  190. 5708990770823839524233143877797980545530986496.0);
  191. TEST_DOUBLE("[5708990770823839207320493820740630171355185152]",
  192. 5708990770823839524233143877797980545530986496.0);
  193. TEST_DOUBLE("[5708990770823839207320493820740630171355185151999e-3]",
  194. 5708990770823838890407843763683279797179383808.0);
  195. TEST_DOUBLE("[5708990770823839207320493820740630171355185152001e-3]",
  196. 5708990770823839524233143877797980545530986496.0);
  197. {
  198. std::string n1e308(312, '0'); // '1' followed by 308 '0'
  199. n1e308[0] = '[';
  200. n1e308[1] = '1';
  201. n1e308[310] = ']';
  202. n1e308[311] = '\0';
  203. TEST_DOUBLE(n1e308, 1E308);
  204. }
  205. // Cover trimming
  206. TEST_DOUBLE(
  207. "[2.22507385850720113605740979670913197593481954635164564802342610972482222202107694551652952390813508"
  208. "7914149158913039621106870086438694594645527657207407820621743379988141063267329253552286881372149012"
  209. "9811224514518898490572223072852551331557550159143974763979834118019993239625482890171070818506906306"
  210. "6665599493827577257201576306269066333264756530000924588831643303777979186961204949739037782970490505"
  211. "1080609940730262937128958950003583799967207254304360284078895771796150945516748243471030702609144621"
  212. "5722898802581825451803257070188608721131280795122334262883686223215037756666225039825343359745688844"
  213. "2390026549819838548794829220689472168983109969836584681402285424333066033985088644580400103493397042"
  214. "7567186443383770486037861622771738545623065874679014086723327636718751234567890123456789012345678901"
  215. "e-308]",
  216. 2.2250738585072014e-308);
  217. }
  218. SECTION("strings")
  219. {
  220. auto TEST_STRING = [](const std::string & json_string, const std::string & expected)
  221. {
  222. CAPTURE(json_string)
  223. CAPTURE(expected)
  224. CHECK(json::parse(json_string)[0].get<std::string>() == expected);
  225. };
  226. TEST_STRING("[\"\"]", "");
  227. TEST_STRING("[\"Hello\"]", "Hello");
  228. TEST_STRING(R"(["Hello\nWorld"])", "Hello\nWorld");
  229. //TEST_STRING("[\"Hello\\u0000World\"]", "Hello\0World");
  230. TEST_STRING(R"(["\"\\/\b\f\n\r\t"])", "\"\\/\b\f\n\r\t");
  231. TEST_STRING(R"(["\u0024"])", "$"); // Dollar sign U+0024
  232. TEST_STRING(R"(["\u00A2"])", "\xC2\xA2"); // Cents sign U+00A2
  233. TEST_STRING(R"(["\u20AC"])", "\xE2\x82\xAC"); // Euro sign U+20AC
  234. TEST_STRING(R"(["\uD834\uDD1E"])", "\xF0\x9D\x84\x9E"); // G clef sign U+1D11E
  235. }
  236. SECTION("roundtrip")
  237. {
  238. // test cases are from https://github.com/miloyip/nativejson-benchmark/tree/master/test/data/roundtrip
  239. for (const auto* filename :
  240. {
  241. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip01.json",
  242. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip02.json",
  243. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip03.json",
  244. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip04.json",
  245. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip05.json",
  246. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip06.json",
  247. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip07.json",
  248. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip08.json",
  249. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip09.json",
  250. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip10.json",
  251. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip11.json",
  252. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip12.json",
  253. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip13.json",
  254. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip14.json",
  255. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip15.json",
  256. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip16.json",
  257. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip17.json",
  258. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip18.json",
  259. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip19.json",
  260. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip20.json",
  261. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip21.json",
  262. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip22.json",
  263. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip23.json",
  264. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip24.json",
  265. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip25.json",
  266. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip26.json",
  267. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip27.json",
  268. //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip28.json", // incompatible with roundtrip24
  269. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip29.json",
  270. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip30.json",
  271. TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip31.json"
  272. //TEST_DATA_DIRECTORY "/json_roundtrip/roundtrip32.json" // same as roundtrip31
  273. })
  274. {
  275. CAPTURE(filename)
  276. std::ifstream f(filename);
  277. std::string json_string( (std::istreambuf_iterator<char>(f) ),
  278. (std::istreambuf_iterator<char>()) );
  279. CAPTURE(json_string)
  280. const json j = json::parse(json_string);
  281. CHECK(j.dump() == json_string);
  282. }
  283. }
  284. }
  285. TEST_CASE("test suite from json-test-suite")
  286. {
  287. SECTION("read all sample.json")
  288. {
  289. // read a file with all unicode characters stored as single-character
  290. // strings in a JSON array
  291. std::ifstream f(TEST_DATA_DIRECTORY "/json_testsuite/sample.json");
  292. json j;
  293. CHECK_NOTHROW(f >> j);
  294. // the array has 3 elements
  295. CHECK(j.size() == 3);
  296. }
  297. }
  298. TEST_CASE("json.org examples")
  299. {
  300. // here, we list all JSON values from https://json.org/example
  301. SECTION("1.json")
  302. {
  303. std::ifstream f(TEST_DATA_DIRECTORY "/json.org/1.json");
  304. json j;
  305. CHECK_NOTHROW(f >> j);
  306. }
  307. SECTION("2.json")
  308. {
  309. std::ifstream f(TEST_DATA_DIRECTORY "/json.org/2.json");
  310. json j;
  311. CHECK_NOTHROW(f >> j);
  312. }
  313. SECTION("3.json")
  314. {
  315. std::ifstream f(TEST_DATA_DIRECTORY "/json.org/3.json");
  316. json j;
  317. CHECK_NOTHROW(f >> j);
  318. }
  319. SECTION("4.json")
  320. {
  321. std::ifstream f(TEST_DATA_DIRECTORY "/json.org/4.json");
  322. json j;
  323. CHECK_NOTHROW(f >> j);
  324. }
  325. SECTION("5.json")
  326. {
  327. std::ifstream f(TEST_DATA_DIRECTORY "/json.org/5.json");
  328. json j;
  329. CHECK_NOTHROW(f >> j);
  330. }
  331. SECTION("FILE 1.json")
  332. {
  333. const std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen(TEST_DATA_DIRECTORY "/json.org/1.json", "r"), &std::fclose);
  334. json _;
  335. CHECK_NOTHROW(_ = json::parse(f.get()));
  336. }
  337. SECTION("FILE 2.json")
  338. {
  339. const std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen(TEST_DATA_DIRECTORY "/json.org/2.json", "r"), &std::fclose);
  340. json _;
  341. CHECK_NOTHROW(_ = json::parse(f.get()));
  342. }
  343. SECTION("FILE 3.json")
  344. {
  345. const std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen(TEST_DATA_DIRECTORY "/json.org/3.json", "r"), &std::fclose);
  346. json _;
  347. CHECK_NOTHROW(_ = json::parse(f.get()));
  348. }
  349. SECTION("FILE 4.json")
  350. {
  351. const std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen(TEST_DATA_DIRECTORY "/json.org/4.json", "r"), &std::fclose);
  352. json _;
  353. CHECK_NOTHROW(_ = json::parse(f.get()));
  354. }
  355. SECTION("FILE 5.json")
  356. {
  357. const std::unique_ptr<std::FILE, decltype(&std::fclose)> f(std::fopen(TEST_DATA_DIRECTORY "/json.org/5.json", "r"), &std::fclose);
  358. json _;
  359. CHECK_NOTHROW(_ = json::parse(f.get()));
  360. }
  361. }
  362. TEST_CASE("RFC 8259 examples")
  363. {
  364. // here, we list all JSON values from the RFC 8259 document
  365. SECTION("7. Strings")
  366. {
  367. CHECK(json::parse("\"\\u005C\"") == json("\\"));
  368. CHECK(json::parse("\"\\uD834\\uDD1E\"") == json("𝄞"));
  369. CHECK(json::parse("\"𝄞\"") == json("𝄞"));
  370. }
  371. SECTION("8.3 String Comparison")
  372. {
  373. CHECK(json::parse("\"a\\b\"") == json::parse("\"a\u005Cb\""));
  374. }
  375. SECTION("13 Examples")
  376. {
  377. {
  378. const auto* json_contents = R"(
  379. {
  380. "Image": {
  381. "Width": 800,
  382. "Height": 600,
  383. "Title": "View from 15th Floor",
  384. "Thumbnail": {
  385. "Url": "http://www.example.com/image/481989943",
  386. "Height": 125,
  387. "Width": 100
  388. },
  389. "Animated" : false,
  390. "IDs": [116, 943, 234, 38793]
  391. }
  392. }
  393. )";
  394. CHECK_NOTHROW(json(json_contents));
  395. }
  396. {
  397. const auto* json_contents = R"(
  398. [
  399. {
  400. "precision": "zip",
  401. "Latitude": 37.7668,
  402. "Longitude": -122.3959,
  403. "Address": "",
  404. "City": "SAN FRANCISCO",
  405. "State": "CA",
  406. "Zip": "94107",
  407. "Country": "US"
  408. },
  409. {
  410. "precision": "zip",
  411. "Latitude": 37.371991,
  412. "Longitude": -122.026020,
  413. "Address": "",
  414. "City": "SUNNYVALE",
  415. "State": "CA",
  416. "Zip": "94085",
  417. "Country": "US"
  418. }
  419. ])";
  420. CHECK_NOTHROW(json(json_contents));
  421. }
  422. CHECK(json::parse("\"Hello world!\"") == json("Hello world!"));
  423. CHECK(json::parse("42") == json(42));
  424. CHECK(json::parse("true") == json(true));
  425. }
  426. }
  427. TEST_CASE("nst's JSONTestSuite")
  428. {
  429. SECTION("test_parsing")
  430. {
  431. SECTION("y")
  432. {
  433. for (const auto* filename :
  434. {
  435. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_arraysWithSpaces.json",
  436. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty-string.json",
  437. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_empty.json",
  438. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_ending_with_newline.json",
  439. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_false.json",
  440. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_heterogeneous.json",
  441. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_null.json",
  442. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_1_and_newline.json",
  443. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_leading_space.json",
  444. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_several_null.json",
  445. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_array_with_trailing_space.json",
  446. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number.json",
  447. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e+1.json",
  448. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_0e1.json",
  449. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_after_space.json",
  450. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_close_to_zero.json",
  451. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_double_huge_neg_exp.json",
  452. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_int_with_exp.json",
  453. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_minus_zero.json",
  454. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_int.json",
  455. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_one.json",
  456. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_negative_zero.json",
  457. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e.json",
  458. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_neg_exp.json",
  459. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_capital_e_pos_exp.json",
  460. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_exponent.json",
  461. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_fraction_exponent.json",
  462. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_exp.json",
  463. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_exponent.json",
  464. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_underflow.json",
  465. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_int.json",
  466. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_simple_real.json",
  467. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_neg_int.json",
  468. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_too_big_pos_int.json",
  469. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_very_big_negative_int.json",
  470. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
  471. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_basic.json",
  472. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
  473. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key_and_value.json",
  474. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty.json",
  475. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_empty_key.json",
  476. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_escaped_null_in_key.json",
  477. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_extreme_numbers.json",
  478. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
  479. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_simple.json",
  480. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_string_unicode.json",
  481. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_with_newlines.json",
  482. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
  483. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_UTF-16_Surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
  484. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pair.json",
  485. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_accepted_surrogate_pairs.json",
  486. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_allowed_escapes.json",
  487. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_and_u_escaped_zero.json",
  488. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_backslash_doublequotes.json",
  489. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_comments.json",
  490. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_a.json",
  491. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_double_escape_n.json",
  492. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_control_character.json",
  493. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_escaped_noncharacter.json",
  494. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array.json",
  495. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_in_array_with_leading_space.json",
  496. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_last_surrogates_1_and_2.json",
  497. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_newline_uescaped.json",
  498. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
  499. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+1FFFF.json",
  500. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
  501. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_null_escape.json",
  502. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_one-byte-utf-8.json",
  503. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_pi.json",
  504. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_simple_ascii.json",
  505. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_space.json",
  506. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_three-byte-utf-8.json",
  507. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_two-byte-utf-8.json",
  508. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2028_line_sep.json",
  509. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_u+2029_par_sep.json",
  510. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_uEscape.json",
  511. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unescaped_char_delete.json",
  512. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode.json",
  513. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicodeEscapedBackslash.json",
  514. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_2.json",
  515. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
  516. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
  517. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_unicode_escaped_double_quote.json",
  518. // TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf16.json",
  519. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_utf8.json",
  520. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_string_with_del_character.json",
  521. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_false.json",
  522. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_int.json",
  523. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_negative_real.json",
  524. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_null.json",
  525. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_string.json",
  526. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_lonely_true.json",
  527. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_string_empty.json",
  528. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_trailing_newline.json",
  529. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_true_in_array.json",
  530. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_structure_whitespace_array.json"
  531. }
  532. )
  533. {
  534. CAPTURE(filename)
  535. std::ifstream f(filename);
  536. json j;
  537. CHECK_NOTHROW(f >> j);
  538. }
  539. }
  540. SECTION("n")
  541. {
  542. for (const auto* filename :
  543. {
  544. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_1_true_without_comma.json",
  545. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_a_invalid_utf8.json",
  546. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_colon_instead_of_comma.json",
  547. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
  548. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_and_number.json",
  549. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_comma.json",
  550. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_double_extra_comma.json",
  551. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json",
  552. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_comma.json",
  553. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete.json",
  554. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_incomplete_invalid_value.json",
  555. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_inner_array_no_comma.json",
  556. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_invalid_utf8.json",
  557. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_items_separated_by_semicolon.json",
  558. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_comma.json",
  559. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_just_minus.json",
  560. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_missing_value.json",
  561. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_newlines_unclosed.json",
  562. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_comma.json",
  563. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_number_and_several_commas.json",
  564. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_spaces_vertical_tab_formfeed.json",
  565. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_star_inside.json",
  566. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed.json",
  567. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_trailing_comma.json",
  568. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_new_lines.json",
  569. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_unclosed_with_object_inside.json",
  570. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_false.json",
  571. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_null.json",
  572. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_incomplete_true.json",
  573. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_++.json",
  574. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+1.json",
  575. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_+Inf.json",
  576. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-01.json",
  577. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-1.0..json",
  578. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-2..json",
  579. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_-NaN.json",
  580. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.-1.json",
  581. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_.2e-3.json",
  582. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.1.2.json",
  583. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e+.json",
  584. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.3e.json",
  585. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0.e1.json",
  586. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E+.json",
  587. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0_capital_E.json",
  588. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e+.json",
  589. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_0e.json",
  590. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e+.json",
  591. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e-.json",
  592. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1.0e.json",
  593. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1_000.json",
  594. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_1eE2.json",
  595. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e+3.json",
  596. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e-3.json",
  597. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_2.e3.json",
  598. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_9.e+.json",
  599. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_Inf.json",
  600. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_NaN.json",
  601. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_U+FF11_fullwidth_digit_one.json",
  602. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_expression.json",
  603. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_1_digit.json",
  604. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_hex_2_digits.json",
  605. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_infinity.json",
  606. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid+-.json",
  607. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-negative-real.json",
  608. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-bigger-int.json",
  609. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-exponent.json",
  610. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_invalid-utf-8-in-int.json",
  611. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_infinity.json",
  612. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_sign_with_trailing_garbage.json",
  613. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_minus_space_1.json",
  614. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_int_starting_with_zero.json",
  615. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_real_without_int_part.json",
  616. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_neg_with_garbage_at_end.json",
  617. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_garbage_after_e.json",
  618. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_with_invalid_utf8_after_e.json",
  619. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_real_without_fractional_part.json",
  620. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_starting_with_dot.json",
  621. //TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_then_00.json",
  622. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha.json",
  623. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_alpha_char.json",
  624. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_number_with_leading_zero.json",
  625. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bad_value.json",
  626. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_bracket_key.json",
  627. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_comma_instead_of_colon.json",
  628. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_double_colon.json",
  629. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_emoji.json",
  630. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_garbage_at_end.json",
  631. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_key_with_single_quotes.json",
  632. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_colon.json",
  633. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_key.json",
  634. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_semicolon.json",
  635. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_missing_value.json",
  636. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_no-colon.json",
  637. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key.json",
  638. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_non_string_key_but_huge_number_instead.json",
  639. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_pi_in_key_and_trailing_comma.json",
  640. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_repeated_null_null.json",
  641. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_several_trailing_commas.json",
  642. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_single_quote.json",
  643. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comma.json",
  644. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json",
  645. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json",
  646. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json",
  647. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json",
  648. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_two_commas_in_a_row.json",
  649. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unquoted_key.json",
  650. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_unterminated-value.json",
  651. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_single_string.json",
  652. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json",
  653. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_single_space.json",
  654. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u.json",
  655. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1.json",
  656. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape u1x.json",
  657. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_1_surrogate_then_escape.json",
  658. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF-16_incomplete_surrogate.json",
  659. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_UTF8_surrogate_U+D800.json",
  660. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_accentuated_char_no_quotes.json",
  661. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_backslash_00.json",
  662. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escape_x.json",
  663. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_backslash_bad.json",
  664. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_ctrl_char_tab.json",
  665. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_escaped_emoji.json",
  666. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escape.json",
  667. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_escaped_character.json",
  668. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_incomplete_surrogate_escape_invalid.json",
  669. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid-utf-8-in-escape.json",
  670. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_backslash_esc.json",
  671. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_unicode_escape.json",
  672. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf-8.json",
  673. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_invalid_utf8_after_escape.json",
  674. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_iso_latin_1.json",
  675. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_leading_uescaped_thinspace.json",
  676. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_lone_utf8_continuation_byte.json",
  677. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_no_quotes_with_bad_escape.json",
  678. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_2_bytes.json",
  679. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes.json",
  680. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_overlong_sequence_6_bytes_null.json",
  681. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_doublequote.json",
  682. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_quote.json",
  683. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_single_string_no_double_quotes.json",
  684. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_start_escape_unclosed.json",
  685. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_crtl_char.json",
  686. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_newline.json",
  687. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unescaped_tab.json",
  688. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_unicode_CapitalU.json",
  689. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json",
  690. //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_100000_opening_arrays.json",
  691. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3C.3E.json",
  692. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_3Cnull3E.json",
  693. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_U+2060_word_joined.json",
  694. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_UTF8_BOM_no_data.json",
  695. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json",
  696. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json",
  697. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_unclosed_string.json",
  698. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_ascii-unicode-identifier.json",
  699. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_capitalized_True.json",
  700. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json",
  701. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_comma_instead_of_closing_brace.json",
  702. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json",
  703. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_end_array.json",
  704. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_incomplete_UTF8_BOM.json",
  705. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-invalid-utf-8.json",
  706. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_lone-open-bracket.json",
  707. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_no_data.json",
  708. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_null-byte-outside-string.json",
  709. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json",
  710. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json",
  711. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_unclosed_no_value.json",
  712. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_comment.json",
  713. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json",
  714. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_apostrophe.json",
  715. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_comma.json",
  716. //!TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_object.json",
  717. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_object.json",
  718. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_open_string.json",
  719. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_array_string.json",
  720. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object.json",
  721. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_close_array.json",
  722. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_comma.json",
  723. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_array.json",
  724. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_open_string.json",
  725. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_object_string_with_apostrophes.json",
  726. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_open_open.json",
  727. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_point.json",
  728. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_single_star.json",
  729. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json",
  730. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_uescaped_LF_before_string.json",
  731. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array.json",
  732. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_partial_null.json",
  733. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_false.json",
  734. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_array_unfinished_true.json",
  735. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unclosed_object.json",
  736. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_unicode-identifier.json",
  737. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_U+2060_word_joiner.json",
  738. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_whitespace_formfeed.json"
  739. }
  740. )
  741. {
  742. CAPTURE(filename)
  743. std::ifstream f(filename);
  744. json _;
  745. CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
  746. }
  747. }
  748. SECTION("n -> y (relaxed)")
  749. {
  750. // these tests fail above, because the parser does not end on EOF;
  751. // they succeed when the operator>> is used, because it does not
  752. // have this constraint
  753. for (const auto* filename :
  754. {
  755. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_comma_after_close.json",
  756. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_array_extra_close.json",
  757. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment.json",
  758. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_open.json",
  759. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open.json",
  760. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_trailing_comment_slash_open_incomplete.json",
  761. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_object_with_trailing_garbage.json",
  762. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_string_with_trailing_garbage.json",
  763. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_trailing_garbage.json",
  764. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_array_with_extra_array_close.json",
  765. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_close_unopened_array.json",
  766. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_double_array.json",
  767. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_number_with_trailing_garbage.json",
  768. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_followed_by_closing_object.json",
  769. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_object_with_trailing_garbage.json",
  770. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/n_structure_trailing_#.json"
  771. }
  772. )
  773. {
  774. CAPTURE(filename)
  775. std::ifstream f(filename);
  776. json j;
  777. CHECK_NOTHROW(f >> j);
  778. }
  779. }
  780. SECTION("i -> y")
  781. {
  782. for (const auto* filename :
  783. {
  784. // we do not pose a limit on nesting
  785. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_500_nested_arrays.json",
  786. // we silently ignore BOMs
  787. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_structure_UTF-8_BOM_empty_object.json",
  788. // we accept and forward non-characters
  789. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+10FFFE_nonchar.json",
  790. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+1FFFE_nonchar.json",
  791. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FDD0_nonchar.json",
  792. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_unicode_U+FFFE_nonchar.json"
  793. }
  794. )
  795. {
  796. CAPTURE(filename)
  797. std::ifstream f(filename);
  798. json j;
  799. CHECK_NOTHROW(f >> j);
  800. }
  801. }
  802. // numbers that overflow during parsing
  803. SECTION("i/y -> n (out of range)")
  804. {
  805. for (const auto* filename :
  806. {
  807. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_neg_int_huge_exp.json",
  808. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_number_pos_double_huge_exp.json",
  809. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_huge_exp.json",
  810. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_neg_overflow.json",
  811. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_number_real_pos_overflow.json"
  812. }
  813. )
  814. {
  815. CAPTURE(filename)
  816. std::ifstream f(filename);
  817. json j;
  818. CHECK_THROWS_AS(f >> j, json::out_of_range&);
  819. }
  820. }
  821. SECTION("i -> n")
  822. {
  823. for (const auto* filename :
  824. {
  825. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_object_key_lone_2nd_surrogate.json",
  826. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
  827. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json",
  828. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_lonely_surrogate.json",
  829. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-16_invalid_surrogate.json",
  830. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_UTF-8_invalid_sequence.json",
  831. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json",
  832. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogate_pair.json",
  833. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_incomplete_surrogates_escape_valid.json",
  834. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_inverted_surrogates_U+1D11E.json",
  835. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_lone_second_surrogate.json",
  836. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_not_in_unicode_range.json",
  837. TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/i_string_truncated-utf-8.json"
  838. }
  839. )
  840. {
  841. CAPTURE(filename)
  842. std::ifstream f(filename);
  843. json j;
  844. CHECK_THROWS_AS(f >> j, json::parse_error&);
  845. }
  846. }
  847. }
  848. }
  849. TEST_CASE("nst's JSONTestSuite (2)")
  850. {
  851. SECTION("test_parsing")
  852. {
  853. SECTION("y")
  854. {
  855. for (const auto* filename :
  856. {
  857. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_arraysWithSpaces.json",
  858. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty-string.json",
  859. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_empty.json",
  860. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_ending_with_newline.json",
  861. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_false.json",
  862. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_heterogeneous.json",
  863. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_null.json",
  864. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_1_and_newline.json",
  865. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_leading_space.json",
  866. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_several_null.json",
  867. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_array_with_trailing_space.json",
  868. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number.json",
  869. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e+1.json",
  870. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_0e1.json",
  871. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_after_space.json",
  872. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_double_close_to_zero.json",
  873. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_int_with_exp.json",
  874. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_minus_zero.json",
  875. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_int.json",
  876. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_one.json",
  877. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_negative_zero.json",
  878. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e.json",
  879. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_neg_exp.json",
  880. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_capital_e_pos_exp.json",
  881. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_exponent.json",
  882. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_fraction_exponent.json",
  883. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_neg_exp.json",
  884. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_real_pos_exponent.json",
  885. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_int.json",
  886. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_number_simple_real.json",
  887. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object.json",
  888. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_basic.json",
  889. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key.json",
  890. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_duplicated_key_and_value.json",
  891. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty.json",
  892. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_empty_key.json",
  893. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_escaped_null_in_key.json",
  894. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_extreme_numbers.json",
  895. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_long_strings.json",
  896. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_simple.json",
  897. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_string_unicode.json",
  898. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_object_with_newlines.json",
  899. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_1_2_3_bytes_UTF-8_sequences.json",
  900. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pair.json",
  901. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_accepted_surrogate_pairs.json",
  902. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_allowed_escapes.json",
  903. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_and_u_escaped_zero.json",
  904. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_backslash_doublequotes.json",
  905. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_comments.json",
  906. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_a.json",
  907. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_double_escape_n.json",
  908. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_control_character.json",
  909. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_escaped_noncharacter.json",
  910. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array.json",
  911. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_in_array_with_leading_space.json",
  912. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_last_surrogates_1_and_2.json",
  913. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nbsp_uescaped.json",
  914. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+10FFFF.json",
  915. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_nonCharacterInUTF-8_U+FFFF.json",
  916. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_null_escape.json",
  917. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_one-byte-utf-8.json",
  918. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_pi.json",
  919. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_reservedCharacterInUTF-8_U+1BFFF.json",
  920. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_simple_ascii.json",
  921. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_space.json",
  922. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_surrogates_U+1D11E_MUSICAL_SYMBOL_G_CLEF.json",
  923. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_three-byte-utf-8.json",
  924. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_two-byte-utf-8.json",
  925. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2028_line_sep.json",
  926. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_u+2029_par_sep.json",
  927. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uEscape.json",
  928. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_uescaped_newline.json",
  929. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unescaped_char_delete.json",
  930. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode.json",
  931. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicodeEscapedBackslash.json",
  932. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_2.json",
  933. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+10FFFE_nonchar.json",
  934. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+1FFFE_nonchar.json",
  935. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+200B_ZERO_WIDTH_SPACE.json",
  936. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+2064_invisible_plus.json",
  937. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FDD0_nonchar.json",
  938. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_U+FFFE_nonchar.json",
  939. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_unicode_escaped_double_quote.json",
  940. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_utf8.json",
  941. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_string_with_del_character.json",
  942. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_false.json",
  943. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_int.json",
  944. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_negative_real.json",
  945. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_null.json",
  946. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_string.json",
  947. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_lonely_true.json",
  948. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_string_empty.json",
  949. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_trailing_newline.json",
  950. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_true_in_array.json",
  951. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/y_structure_whitespace_array.json"
  952. }
  953. )
  954. {
  955. CAPTURE(filename)
  956. std::ifstream f(filename);
  957. json _;
  958. CHECK_NOTHROW(_ = json::parse(f));
  959. std::ifstream f2(filename);
  960. CHECK(json::accept(f2));
  961. }
  962. }
  963. SECTION("n")
  964. {
  965. for (const auto* filename :
  966. {
  967. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_1_true_without_comma.json",
  968. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_a_invalid_utf8.json",
  969. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_colon_instead_of_comma.json",
  970. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_after_close.json",
  971. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_comma_and_number.json",
  972. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_comma.json",
  973. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_double_extra_comma.json",
  974. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_close.json",
  975. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_extra_comma.json",
  976. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete.json",
  977. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_incomplete_invalid_value.json",
  978. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_inner_array_no_comma.json",
  979. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_invalid_utf8.json",
  980. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_items_separated_by_semicolon.json",
  981. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_comma.json",
  982. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_just_minus.json",
  983. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_missing_value.json",
  984. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_newlines_unclosed.json",
  985. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_comma.json",
  986. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_number_and_several_commas.json",
  987. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_spaces_vertical_tab_formfeed.json",
  988. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_star_inside.json",
  989. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed.json",
  990. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_trailing_comma.json",
  991. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_new_lines.json",
  992. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_array_unclosed_with_object_inside.json",
  993. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_false.json",
  994. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_null.json",
  995. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_incomplete_true.json",
  996. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_multidigit_number_then_00.json",
  997. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_++.json",
  998. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+1.json",
  999. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_+Inf.json",
  1000. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-01.json",
  1001. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-1.0..json",
  1002. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-2..json",
  1003. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_-NaN.json",
  1004. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.-1.json",
  1005. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_.2e-3.json",
  1006. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.1.2.json",
  1007. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e+.json",
  1008. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.3e.json",
  1009. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0.e1.json",
  1010. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E+.json",
  1011. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0_capital_E.json",
  1012. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e+.json",
  1013. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_0e.json",
  1014. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e+.json",
  1015. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e-.json",
  1016. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1.0e.json",
  1017. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1_000.json",
  1018. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_1eE2.json",
  1019. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e+3.json",
  1020. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e-3.json",
  1021. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_2.e3.json",
  1022. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_9.e+.json",
  1023. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_Inf.json",
  1024. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_NaN.json",
  1025. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_U+FF11_fullwidth_digit_one.json",
  1026. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_expression.json",
  1027. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_1_digit.json",
  1028. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_hex_2_digits.json",
  1029. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_infinity.json",
  1030. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid+-.json",
  1031. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-negative-real.json",
  1032. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-bigger-int.json",
  1033. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-exponent.json",
  1034. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_invalid-utf-8-in-int.json",
  1035. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_infinity.json",
  1036. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_sign_with_trailing_garbage.json",
  1037. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_minus_space_1.json",
  1038. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_int_starting_with_zero.json",
  1039. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_real_without_int_part.json",
  1040. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_neg_with_garbage_at_end.json",
  1041. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_garbage_after_e.json",
  1042. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_with_invalid_utf8_after_e.json",
  1043. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_real_without_fractional_part.json",
  1044. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_starting_with_dot.json",
  1045. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha.json",
  1046. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_alpha_char.json",
  1047. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_number_with_leading_zero.json",
  1048. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bad_value.json",
  1049. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_bracket_key.json",
  1050. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_comma_instead_of_colon.json",
  1051. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_double_colon.json",
  1052. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_emoji.json",
  1053. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_garbage_at_end.json",
  1054. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_key_with_single_quotes.json",
  1055. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_lone_continuation_byte_in_key_and_trailing_comma.json",
  1056. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_colon.json",
  1057. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_key.json",
  1058. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_semicolon.json",
  1059. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_missing_value.json",
  1060. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_no-colon.json",
  1061. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key.json",
  1062. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_non_string_key_but_huge_number_instead.json",
  1063. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_repeated_null_null.json",
  1064. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_several_trailing_commas.json",
  1065. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_single_quote.json",
  1066. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comma.json",
  1067. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment.json",
  1068. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_open.json",
  1069. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open.json",
  1070. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_trailing_comment_slash_open_incomplete.json",
  1071. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_two_commas_in_a_row.json",
  1072. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unquoted_key.json",
  1073. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_unterminated-value.json",
  1074. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_single_string.json",
  1075. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_object_with_trailing_garbage.json",
  1076. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_single_space.json",
  1077. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape.json",
  1078. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u.json",
  1079. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1.json",
  1080. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_1_surrogate_then_escape_u1x.json",
  1081. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_accentuated_char_no_quotes.json",
  1082. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_backslash_00.json",
  1083. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escape_x.json",
  1084. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_backslash_bad.json",
  1085. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_ctrl_char_tab.json",
  1086. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_escaped_emoji.json",
  1087. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escape.json",
  1088. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_escaped_character.json",
  1089. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate.json",
  1090. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_incomplete_surrogate_escape_invalid.json",
  1091. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid-utf-8-in-escape.json",
  1092. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_backslash_esc.json",
  1093. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_unicode_escape.json",
  1094. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_invalid_utf8_after_escape.json",
  1095. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_leading_uescaped_thinspace.json",
  1096. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_no_quotes_with_bad_escape.json",
  1097. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_doublequote.json",
  1098. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_quote.json",
  1099. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_single_string_no_double_quotes.json",
  1100. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_start_escape_unclosed.json",
  1101. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_crtl_char.json",
  1102. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_newline.json",
  1103. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unescaped_tab.json",
  1104. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_unicode_CapitalU.json",
  1105. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_string_with_trailing_garbage.json",
  1106. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_U+2060_word_joined.json",
  1107. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_UTF8_BOM_no_data.json",
  1108. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_..json",
  1109. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_angle_bracket_null.json",
  1110. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_trailing_garbage.json",
  1111. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_extra_array_close.json",
  1112. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_array_with_unclosed_string.json",
  1113. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_ascii-unicode-identifier.json",
  1114. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_capitalized_True.json",
  1115. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_close_unopened_array.json",
  1116. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_comma_instead_of_closing_brace.json",
  1117. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_double_array.json",
  1118. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_end_array.json",
  1119. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_incomplete_UTF8_BOM.json",
  1120. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-invalid-utf-8.json",
  1121. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_lone-open-bracket.json",
  1122. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_no_data.json",
  1123. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_null-byte-outside-string.json",
  1124. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_number_with_trailing_garbage.json",
  1125. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_followed_by_closing_object.json",
  1126. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_unclosed_no_value.json",
  1127. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_comment.json",
  1128. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_object_with_trailing_garbage.json",
  1129. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_apostrophe.json",
  1130. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_comma.json",
  1131. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_object.json",
  1132. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_open_string.json",
  1133. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_string.json",
  1134. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object.json",
  1135. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_close_array.json",
  1136. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_comma.json",
  1137. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_array.json",
  1138. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_open_string.json",
  1139. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_object_string_with_apostrophes.json",
  1140. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_open.json",
  1141. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_eacute.json",
  1142. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_single_star.json",
  1143. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_trailing_#.json",
  1144. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_uescaped_LF_before_string.json",
  1145. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array.json",
  1146. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_partial_null.json",
  1147. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_false.json",
  1148. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_array_unfinished_true.json",
  1149. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unclosed_object.json",
  1150. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_unicode-identifier.json",
  1151. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_U+2060_word_joiner.json",
  1152. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_whitespace_formfeed.json"
  1153. }
  1154. )
  1155. {
  1156. CAPTURE(filename)
  1157. std::ifstream f(filename);
  1158. json _;
  1159. CHECK_THROWS_AS(_ = json::parse(f), json::parse_error&);
  1160. std::ifstream f2(filename);
  1161. CHECK(!json::accept(f2));
  1162. }
  1163. }
  1164. SECTION("n (previously overflowed)")
  1165. {
  1166. for (const auto* filename :
  1167. {
  1168. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_100000_opening_arrays.json",
  1169. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/n_structure_open_array_object.json"
  1170. }
  1171. )
  1172. {
  1173. CAPTURE(filename)
  1174. std::ifstream f(filename);
  1175. CHECK(!json::accept(f));
  1176. }
  1177. }
  1178. SECTION("i -> y")
  1179. {
  1180. for (const auto* filename :
  1181. {
  1182. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
  1183. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
  1184. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json",
  1185. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json",
  1186. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json",
  1187. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json",
  1188. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json",
  1189. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json",
  1190. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json",
  1191. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json",
  1192. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json",
  1193. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
  1194. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json",
  1195. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json",
  1196. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json",
  1197. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json",
  1198. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json",
  1199. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json",
  1200. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json",
  1201. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json",
  1202. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json",
  1203. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json",
  1204. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json",
  1205. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json",
  1206. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json",
  1207. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json",
  1208. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json",
  1209. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json",
  1210. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json",
  1211. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json",
  1212. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json",
  1213. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json",
  1214. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json",
  1215. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json",
  1216. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json"
  1217. }
  1218. )
  1219. {
  1220. CAPTURE(filename)
  1221. std::ifstream f(filename);
  1222. json _;
  1223. CHECK_NOTHROW(_ = json::parse(f));
  1224. std::ifstream f2(filename);
  1225. CHECK(json::accept(f2));
  1226. }
  1227. }
  1228. SECTION("i -> n")
  1229. {
  1230. for (const auto* filename :
  1231. {
  1232. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_double_huge_neg_exp.json",
  1233. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_huge_exp.json",
  1234. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_neg_int_huge_exp.json",
  1235. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_pos_double_huge_exp.json",
  1236. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_neg_overflow.json",
  1237. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_pos_overflow.json",
  1238. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_real_underflow.json",
  1239. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_neg_int.json",
  1240. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_too_big_pos_int.json",
  1241. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_number_very_big_negative_int.json",
  1242. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_object_key_lone_2nd_surrogate.json",
  1243. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_surrogate_but_2nd_missing.json",
  1244. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_1st_valid_surrogate_2nd_invalid.json",
  1245. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-16LE_with_BOM.json",
  1246. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF-8_invalid_sequence.json",
  1247. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_UTF8_surrogate_U+D800.json",
  1248. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_and_escape_valid.json",
  1249. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogate_pair.json",
  1250. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_incomplete_surrogates_escape_valid.json",
  1251. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_lonely_surrogate.json",
  1252. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_surrogate.json",
  1253. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_invalid_utf-8.json",
  1254. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_inverted_surrogates_U+1D11E.json",
  1255. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_iso_latin_1.json",
  1256. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_second_surrogate.json",
  1257. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_lone_utf8_continuation_byte.json",
  1258. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_not_in_unicode_range.json",
  1259. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_2_bytes.json",
  1260. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes.json",
  1261. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_overlong_sequence_6_bytes_null.json",
  1262. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_truncated-utf-8.json",
  1263. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16BE_no_BOM.json",
  1264. TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_string_utf16LE_no_BOM.json",
  1265. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_500_nested_arrays.json",
  1266. //TEST_DATA_DIRECTORY "/nst_json_testsuite2/test_parsing/i_structure_UTF-8_BOM_empty_object.json"
  1267. }
  1268. )
  1269. {
  1270. CAPTURE(filename)
  1271. std::ifstream f(filename);
  1272. json _;
  1273. CHECK_THROWS_AS(_ = json::parse(f), json::exception&); // could be parse_error or out_of_range
  1274. std::ifstream f2(filename);
  1275. CHECK(!json::accept(f2));
  1276. }
  1277. }
  1278. }
  1279. }
  1280. namespace
  1281. {
  1282. std::string trim(const std::string& str);
  1283. // from https://stackoverflow.com/a/25829178/266378
  1284. std::string trim(const std::string& str)
  1285. {
  1286. const size_t first = str.find_first_not_of(' ');
  1287. if (std::string::npos == first)
  1288. {
  1289. return str;
  1290. }
  1291. const size_t last = str.find_last_not_of(' ');
  1292. return str.substr(first, (last - first + 1));
  1293. }
  1294. } // namespace
  1295. TEST_CASE("Big List of Naughty Strings")
  1296. {
  1297. // test from https://github.com/minimaxir/big-list-of-naughty-strings
  1298. SECTION("parsing blns.json")
  1299. {
  1300. std::ifstream f(TEST_DATA_DIRECTORY "/big-list-of-naughty-strings/blns.json");
  1301. json j;
  1302. CHECK_NOTHROW(f >> j);
  1303. }
  1304. // check if parsed strings roundtrip
  1305. // https://www.reddit.com/r/cpp/comments/5qpbie/json_form_modern_c_version_210/dd12mpq/
  1306. SECTION("roundtripping")
  1307. {
  1308. std::ifstream f(TEST_DATA_DIRECTORY "/big-list-of-naughty-strings/blns.json");
  1309. std::string line;
  1310. // read lines one by one, bail out on error or eof
  1311. while (getline(f, line))
  1312. {
  1313. // trim whitespace
  1314. line = trim(line);
  1315. // remove trailing comma
  1316. line = line.substr(0, line.find_last_of(','));
  1317. // discard lines without at least two characters (quotes)
  1318. if (line.size() < 2)
  1319. {
  1320. continue;
  1321. }
  1322. // check roundtrip
  1323. CAPTURE(line)
  1324. const json j = json::parse(line);
  1325. CHECK(j.dump() == line);
  1326. }
  1327. }
  1328. }