Merge remote-tracking branch 'upstream/develop' into develop
This commit is contained in:
commit
6bf93b3d06
112 changed files with 6858 additions and 3559 deletions
|
@ -26,14 +26,17 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
|
|||
"src/unit-iterators2.cpp"
|
||||
"src/unit-json_patch.cpp"
|
||||
"src/unit-json_pointer.cpp"
|
||||
"src/unit-meta.cpp"
|
||||
"src/unit-modifiers.cpp"
|
||||
"src/unit-msgpack.cpp"
|
||||
"src/unit-noexcept.cpp"
|
||||
"src/unit-pointer_access.cpp"
|
||||
"src/unit-readme.cpp"
|
||||
"src/unit-reference_access.cpp"
|
||||
"src/unit-regression.cpp"
|
||||
"src/unit-serialization.cpp"
|
||||
"src/unit-testsuites.cpp"
|
||||
"src/unit-udt.cpp"
|
||||
"src/unit-unicode.cpp"
|
||||
)
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ SOURCES = src/unit.cpp \
|
|||
src/unit-iterators2.cpp \
|
||||
src/unit-json_patch.cpp \
|
||||
src/unit-json_pointer.cpp \
|
||||
src/unit-meta.cpp \
|
||||
src/unit-modifiers.cpp \
|
||||
src/unit-msgpack.cpp \
|
||||
src/unit-pointer_access.cpp \
|
||||
|
@ -37,8 +38,8 @@ SOURCES = src/unit.cpp \
|
|||
src/unit-reference_access.cpp \
|
||||
src/unit-regression.cpp \
|
||||
src/unit-serialization.cpp \
|
||||
src/unit-unicode.cpp \
|
||||
src/unit-testsuites.cpp
|
||||
src/unit-testsuites.cpp \
|
||||
src/unit-unicode.cpp
|
||||
|
||||
OBJECTS = $(SOURCES:.cpp=.o)
|
||||
|
||||
|
@ -51,7 +52,7 @@ TESTCASES = $(patsubst src/unit-%.cpp,test-%,$(wildcard src/unit-*.cpp))
|
|||
all: $(TESTCASES)
|
||||
|
||||
clean:
|
||||
rm -fr json_unit $(OBJECTS) $(SOURCES:.cpp=.gcno) $(SOURCES:.cpp=.gcda) $(TESTCASES)
|
||||
rm -fr json_unit $(OBJECTS) $(SOURCES:.cpp=.gcno) $(SOURCES:.cpp=.gcda) $(TESTCASES) parse_afl_fuzzer parse_cbor_fuzzer parse_msgpack_fuzzer
|
||||
|
||||
##############################################################################
|
||||
# single test file
|
||||
|
@ -70,11 +71,11 @@ json_unit: $(OBJECTS) ../src/json.hpp thirdparty/catch/catch.hpp
|
|||
# individual test cases
|
||||
##############################################################################
|
||||
|
||||
test-%: src/unit-%.cpp ../src/json.hpp thirdparty/catch/catch.hpp
|
||||
test-%: src/unit-%.o src/unit.o ../src/json.hpp thirdparty/catch/catch.hpp
|
||||
@echo "[CXXLD] $@"
|
||||
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -DCATCH_CONFIG_MAIN $< -o $@
|
||||
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $< src/unit.o -o $@
|
||||
|
||||
TEST_PATTERN = "*"
|
||||
TEST_PATTERN ?= "*"
|
||||
TEST_PREFIX = ""
|
||||
check: $(TESTCASES)
|
||||
@cd .. ; for testcase in $(TESTCASES); do echo "Executing $$testcase..."; $(TEST_PREFIX)test/$$testcase $(TEST_PATTERN) || exit 1; done
|
||||
|
@ -84,13 +85,14 @@ check: $(TESTCASES)
|
|||
# fuzzer
|
||||
##############################################################################
|
||||
|
||||
FUZZER_ENGINE = src/fuzzer-driver_afl.cpp
|
||||
fuzzers: parse_afl_fuzzer parse_cbor_fuzzer parse_msgpack_fuzzer
|
||||
|
||||
parse_afl_fuzzer:
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) src/fuzzer-driver_afl.cpp src/fuzzer-parse_json.cpp -o $@
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(FUZZER_ENGINE) src/fuzzer-parse_json.cpp -o $@
|
||||
|
||||
parse_cbor_fuzzer:
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) src/fuzzer-driver_afl.cpp src/fuzzer-parse_cbor.cpp -o $@
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(FUZZER_ENGINE) src/fuzzer-parse_cbor.cpp -o $@
|
||||
|
||||
parse_msgpack_fuzzer:
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) src/fuzzer-driver_afl.cpp src/fuzzer-parse_msgpack.cpp -o $@
|
||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(FUZZER_ENGINE) src/fuzzer-parse_msgpack.cpp -o $@
|
||||
|
|
22
test/data/big-list-of-naughty-strings/LICENSE
Normal file
22
test/data/big-list-of-naughty-strings/LICENSE
Normal file
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Max Woolf
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
496
test/data/big-list-of-naughty-strings/blns.json
Normal file
496
test/data/big-list-of-naughty-strings/blns.json
Normal file
|
@ -0,0 +1,496 @@
|
|||
[
|
||||
"",
|
||||
"undefined",
|
||||
"undef",
|
||||
"null",
|
||||
"NULL",
|
||||
"(null)",
|
||||
"nil",
|
||||
"NIL",
|
||||
"true",
|
||||
"false",
|
||||
"True",
|
||||
"False",
|
||||
"TRUE",
|
||||
"FALSE",
|
||||
"None",
|
||||
"hasOwnProperty",
|
||||
"\\",
|
||||
"\\\\",
|
||||
"0",
|
||||
"1",
|
||||
"1.00",
|
||||
"$1.00",
|
||||
"1/2",
|
||||
"1E2",
|
||||
"1E02",
|
||||
"1E+02",
|
||||
"-1",
|
||||
"-1.00",
|
||||
"-$1.00",
|
||||
"-1/2",
|
||||
"-1E2",
|
||||
"-1E02",
|
||||
"-1E+02",
|
||||
"1/0",
|
||||
"0/0",
|
||||
"-2147483648/-1",
|
||||
"-9223372036854775808/-1",
|
||||
"0.00",
|
||||
"0..0",
|
||||
".",
|
||||
"0.0.0",
|
||||
"0,00",
|
||||
"0,,0",
|
||||
",",
|
||||
"0,0,0",
|
||||
"0.0/0",
|
||||
"1.0/0.0",
|
||||
"0.0/0.0",
|
||||
"1,0/0,0",
|
||||
"0,0/0,0",
|
||||
"--1",
|
||||
"-",
|
||||
"-.",
|
||||
"-,",
|
||||
"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",
|
||||
"NaN",
|
||||
"Infinity",
|
||||
"-Infinity",
|
||||
"INF",
|
||||
"1#INF",
|
||||
"-1#IND",
|
||||
"1#QNAN",
|
||||
"1#SNAN",
|
||||
"1#IND",
|
||||
"0x0",
|
||||
"0xffffffff",
|
||||
"0xffffffffffffffff",
|
||||
"0xabad1dea",
|
||||
"123456789012345678901234567890123456789",
|
||||
"1,000.00",
|
||||
"1 000.00",
|
||||
"1'000.00",
|
||||
"1,000,000.00",
|
||||
"1 000 000.00",
|
||||
"1'000'000.00",
|
||||
"1.000,00",
|
||||
"1 000,00",
|
||||
"1'000,00",
|
||||
"1.000.000,00",
|
||||
"1 000 000,00",
|
||||
"1'000'000,00",
|
||||
"01000",
|
||||
"08",
|
||||
"09",
|
||||
"2.2250738585072011e-308",
|
||||
",./;'[]\\-=",
|
||||
"<>?:\"{}|_+",
|
||||
"!@#$%^&*()`~",
|
||||
"Ω≈ç√∫˜µ≤≥÷",
|
||||
"åß∂ƒ©˙∆˚¬…æ",
|
||||
"œ∑´®†¥¨ˆøπ“‘",
|
||||
"¡™£¢∞§¶•ªº–≠",
|
||||
"¸˛Ç◊ı˜Â¯˘¿",
|
||||
"ÅÍÎÏ˝ÓÔÒÚÆ☃",
|
||||
"Œ„´‰ˇÁ¨ˆØ∏”’",
|
||||
"`⁄€‹›fifl‡°·‚—±",
|
||||
"⅛⅜⅝⅞",
|
||||
"ЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя",
|
||||
"٠١٢٣٤٥٦٧٨٩",
|
||||
"⁰⁴⁵",
|
||||
"₀₁₂",
|
||||
"⁰⁴⁵₀₁₂",
|
||||
"ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็ ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็ ด้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็็้้้้้้้้็็็็็้้้้้็็็็",
|
||||
"'",
|
||||
"\"",
|
||||
"''",
|
||||
"\"\"",
|
||||
"'\"'",
|
||||
"\"''''\"'\"",
|
||||
"\"'\"'\"''''\"",
|
||||
"<foo val=“bar” />",
|
||||
"<foo val=“bar” />",
|
||||
"<foo val=”bar“ />",
|
||||
"<foo val=`bar' />",
|
||||
"田中さんにあげて下さい",
|
||||
"パーティーへ行かないか",
|
||||
"和製漢語",
|
||||
"部落格",
|
||||
"사회과학원 어학연구소",
|
||||
"찦차를 타고 온 펲시맨과 쑛다리 똠방각하",
|
||||
"社會科學院語學研究所",
|
||||
"울란바토르",
|
||||
"𠜎𠜱𠝹𠱓𠱸𠲖𠳏",
|
||||
"ヽ༼ຈل͜ຈ༽ノ ヽ༼ຈل͜ຈ༽ノ ",
|
||||
"(。◕ ∀ ◕。)",
|
||||
"`ィ(´∀`∩",
|
||||
"__ロ(,_,*)",
|
||||
"・( ̄∀ ̄)・:*:",
|
||||
"゚・✿ヾ╲(。◕‿◕。)╱✿・゚",
|
||||
",。・:*:・゜’( ☻ ω ☻ )。・:*:・゜’",
|
||||
"(╯°□°)╯︵ ┻━┻) ",
|
||||
"(ノಥ益ಥ)ノ ┻━┻",
|
||||
"┬─┬ノ( º _ ºノ)",
|
||||
"( ͡° ͜ʖ ͡°)",
|
||||
"😍",
|
||||
"👩🏽",
|
||||
"👾 🙇 💁 🙅 🙆 🙋 🙎 🙍 ",
|
||||
"🐵 🙈 🙉 🙊",
|
||||
"❤️ 💔 💌 💕 💞 💓 💗 💖 💘 💝 💟 💜 💛 💚 💙",
|
||||
"✋🏿 💪🏿 👐🏿 🙌🏿 👏🏿 🙏🏿",
|
||||
"🚾 🆒 🆓 🆕 🆖 🆗 🆙 🏧",
|
||||
"0️⃣ 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟",
|
||||
"🇺🇸🇷🇺🇸 🇦🇫🇦🇲🇸 ",
|
||||
"🇺🇸🇷🇺🇸🇦🇫🇦🇲",
|
||||
"🇺🇸🇷🇺🇸🇦",
|
||||
"123",
|
||||
"١٢٣",
|
||||
"ثم نفس سقطت وبالتحديد،, جزيرتي باستخدام أن دنو. إذ هنا؟ الستار وتنصيب كان. أهّل ايطاليا، بريطانيا-فرنسا قد أخذ. سليمان، إتفاقية بين ما, يذكر الحدود أي بعد, معاملة بولندا، الإطلاق عل إيو.",
|
||||
"בְּרֵאשִׁית, בָּרָא אֱלֹהִים, אֵת הַשָּׁמַיִם, וְאֵת הָאָרֶץ",
|
||||
"הָיְתָהtestالصفحات التّحول",
|
||||
"﷽",
|
||||
"ﷺ",
|
||||
"مُنَاقَشَةُ سُبُلِ اِسْتِخْدَامِ اللُّغَةِ فِي النُّظُمِ الْقَائِمَةِ وَفِيم يَخُصَّ التَّطْبِيقَاتُ الْحاسُوبِيَّةُ، ",
|
||||
"",
|
||||
" ",
|
||||
"",
|
||||
" ",
|
||||
"",
|
||||
"␣",
|
||||
"␢",
|
||||
"␡",
|
||||
"test",
|
||||
"test",
|
||||
"
test
",
|
||||
"testtest",
|
||||
"test",
|
||||
"Ṱ̺̺̕o͞ ̷i̲̬͇̪͙n̝̗͕v̟̜̘̦͟o̶̙̰̠kè͚̮̺̪̹̱̤ ̖t̝͕̳̣̻̪͞h̼͓̲̦̳̘̲e͇̣̰̦̬͎ ̢̼̻̱̘h͚͎͙̜̣̲ͅi̦̲̣̰̤v̻͍e̺̭̳̪̰-m̢iͅn̖̺̞̲̯̰d̵̼̟͙̩̼̘̳ ̞̥̱̳̭r̛̗̘e͙p͠r̼̞̻̭̗e̺̠̣͟s̘͇̳͍̝͉e͉̥̯̞̲͚̬͜ǹ̬͎͎̟̖͇̤t͍̬̤͓̼̭͘ͅi̪̱n͠g̴͉ ͏͉ͅc̬̟h͡a̫̻̯͘o̫̟̖͍̙̝͉s̗̦̲.̨̹͈̣",
|
||||
"̡͓̞ͅI̗̘̦͝n͇͇͙v̮̫ok̲̫̙͈i̖͙̭̹̠̞n̡̻̮̣̺g̲͈͙̭͙̬͎ ̰t͔̦h̞̲e̢̤ ͍̬̲͖f̴̘͕̣è͖ẹ̥̩l͖͔͚i͓͚̦͠n͖͍̗͓̳̮g͍ ̨o͚̪͡f̘̣̬ ̖̘͖̟͙̮c҉͔̫͖͓͇͖ͅh̵̤̣͚͔á̗̼͕ͅo̼̣̥s̱͈̺̖̦̻͢.̛̖̞̠̫̰",
|
||||
"̗̺͖̹̯͓Ṯ̤͍̥͇͈h̲́e͏͓̼̗̙̼̣͔ ͇̜̱̠͓͍ͅN͕͠e̗̱z̘̝̜̺͙p̤̺̹͍̯͚e̠̻̠͜r̨̤͍̺̖͔̖̖d̠̟̭̬̝͟i̦͖̩͓͔̤a̠̗̬͉̙n͚͜ ̻̞̰͚ͅh̵͉i̳̞v̢͇ḙ͎͟-҉̭̩̼͔m̤̭̫i͕͇̝̦n̗͙ḍ̟ ̯̲͕͞ǫ̟̯̰̲͙̻̝f ̪̰̰̗̖̭̘͘c̦͍̲̞͍̩̙ḥ͚a̮͎̟̙͜ơ̩̹͎s̤.̝̝ ҉Z̡̖̜͖̰̣͉̜a͖̰͙̬͡l̲̫̳͍̩g̡̟̼̱͚̞̬ͅo̗͜.̟",
|
||||
"̦H̬̤̗̤͝e͜ ̜̥̝̻͍̟́w̕h̖̯͓o̝͙̖͎̱̮ ҉̺̙̞̟͈W̷̼̭a̺̪͍į͈͕̭͙̯̜t̶̼̮s̘͙͖̕ ̠̫̠B̻͍͙͉̳ͅe̵h̵̬͇̫͙i̹͓̳̳̮͎̫̕n͟d̴̪̜̖ ̰͉̩͇͙̲͞ͅT͖̼͓̪͢h͏͓̮̻e̬̝̟ͅ ̤̹̝W͙̞̝͔͇͝ͅa͏͓͔̹̼̣l̴͔̰̤̟͔ḽ̫.͕",
|
||||
"Z̮̞̠͙͔ͅḀ̗̞͈̻̗Ḷ͙͎̯̹̞͓G̻O̭̗̮",
|
||||
"˙ɐnbᴉlɐ ɐuƃɐɯ ǝɹolop ʇǝ ǝɹoqɐl ʇn ʇunpᴉpᴉɔuᴉ ɹodɯǝʇ poɯsnᴉǝ op pǝs 'ʇᴉlǝ ƃuᴉɔsᴉdᴉpɐ ɹnʇǝʇɔǝsuoɔ 'ʇǝɯɐ ʇᴉs ɹolop ɯnsdᴉ ɯǝɹo˥",
|
||||
"00˙Ɩ$-",
|
||||
"The quick brown fox jumps over the lazy dog",
|
||||
"𝐓𝐡𝐞 𝐪𝐮𝐢𝐜𝐤 𝐛𝐫𝐨𝐰𝐧 𝐟𝐨𝐱 𝐣𝐮𝐦𝐩𝐬 𝐨𝐯𝐞𝐫 𝐭𝐡𝐞 𝐥𝐚𝐳𝐲 𝐝𝐨𝐠",
|
||||
"𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌",
|
||||
"𝑻𝒉𝒆 𝒒𝒖𝒊𝒄𝒌 𝒃𝒓𝒐𝒘𝒏 𝒇𝒐𝒙 𝒋𝒖𝒎𝒑𝒔 𝒐𝒗𝒆𝒓 𝒕𝒉𝒆 𝒍𝒂𝒛𝒚 𝒅𝒐𝒈",
|
||||
"𝓣𝓱𝓮 𝓺𝓾𝓲𝓬𝓴 𝓫𝓻𝓸𝔀𝓷 𝓯𝓸𝔁 𝓳𝓾𝓶𝓹𝓼 𝓸𝓿𝓮𝓻 𝓽𝓱𝓮 𝓵𝓪𝔃𝔂 𝓭𝓸𝓰",
|
||||
"𝕋𝕙𝕖 𝕢𝕦𝕚𝕔𝕜 𝕓𝕣𝕠𝕨𝕟 𝕗𝕠𝕩 𝕛𝕦𝕞𝕡𝕤 𝕠𝕧𝕖𝕣 𝕥𝕙𝕖 𝕝𝕒𝕫𝕪 𝕕𝕠𝕘",
|
||||
"𝚃𝚑𝚎 𝚚𝚞𝚒𝚌𝚔 𝚋𝚛𝚘𝚠𝚗 𝚏𝚘𝚡 𝚓𝚞𝚖𝚙𝚜 𝚘𝚟𝚎𝚛 𝚝𝚑𝚎 𝚕𝚊𝚣𝚢 𝚍𝚘𝚐",
|
||||
"⒯⒣⒠ ⒬⒰⒤⒞⒦ ⒝⒭⒪⒲⒩ ⒡⒪⒳ ⒥⒰⒨⒫⒮ ⒪⒱⒠⒭ ⒯⒣⒠ ⒧⒜⒵⒴ ⒟⒪⒢",
|
||||
"<script>alert(123)</script>",
|
||||
"<script>alert('123');</script>",
|
||||
"<img src=x onerror=alert(123) />",
|
||||
"<svg><script>123<1>alert(123)</script> ",
|
||||
"\"><script>alert(123)</script>",
|
||||
"'><script>alert(123)</script>",
|
||||
"><script>alert(123)</script>",
|
||||
"</script><script>alert(123)</script>",
|
||||
"< / script >< script >alert(123)< / script >",
|
||||
" onfocus=JaVaSCript:alert(123) autofocus ",
|
||||
"\" onfocus=JaVaSCript:alert(123) autofocus ",
|
||||
"' onfocus=JaVaSCript:alert(123) autofocus ",
|
||||
"<script>alert(123)</script>",
|
||||
"<sc<script>ript>alert(123)</sc</script>ript>",
|
||||
"--><script>alert(123)</script>",
|
||||
"\";alert(123);t=\"",
|
||||
"';alert(123);t='",
|
||||
"JavaSCript:alert(123)",
|
||||
";alert(123);",
|
||||
"src=JaVaSCript:prompt(132)",
|
||||
"\"><script>alert(123);</script x=\"",
|
||||
"'><script>alert(123);</script x='",
|
||||
"><script>alert(123);</script x=",
|
||||
"\" autofocus onkeyup=\"javascript:alert(123)",
|
||||
"' autofocus onkeyup='javascript:alert(123)",
|
||||
"<script\\x20type=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x3Etype=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x0Dtype=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x09type=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x0Ctype=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x2Ftype=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"<script\\x0Atype=\"text/javascript\">javascript:alert(1);</script>",
|
||||
"'`\"><\\x3Cscript>javascript:alert(1)</script> ",
|
||||
"'`\"><\\x00script>javascript:alert(1)</script>",
|
||||
"ABC<div style=\"x\\x3Aexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:expression\\x5C(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:expression\\x00(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:exp\\x00ression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:exp\\x5Cression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x0Aexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x09expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE3\\x80\\x80expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x84expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xC2\\xA0expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x80expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x8Aexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x0Dexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x0Cexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x87expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xEF\\xBB\\xBFexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x20expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x88expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x00expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x8Bexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x86expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x85expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x82expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\x0Bexpression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x81expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x83expression(javascript:alert(1)\">DEF",
|
||||
"ABC<div style=\"x:\\xE2\\x80\\x89expression(javascript:alert(1)\">DEF",
|
||||
"<a href=\"\\x0Bjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x0Fjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xC2\\xA0javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x05javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE1\\xA0\\x8Ejavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x18javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x11javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x88javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x89javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x80javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x17javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x03javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x0Ejavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Ajavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x00javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x10javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x82javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x20javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x13javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x09javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x8Ajavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x14javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x19javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\xAFjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Fjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x81javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Djavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x87javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x07javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE1\\x9A\\x80javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x83javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x04javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x01javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x08javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x84javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x86javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE3\\x80\\x80javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x12javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x0Djavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x0Ajavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x0Cjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x15javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\xA8javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x16javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x02javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Bjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x06javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\xA9javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x80\\x85javascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Ejavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\xE2\\x81\\x9Fjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"\\x1Cjavascript:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"javascript\\x00:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"javascript\\x3A:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"javascript\\x09:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"javascript\\x0D:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"<a href=\"javascript\\x0A:javascript:alert(1)\" id=\"fuzzelement1\">test</a>",
|
||||
"`\"'><img src=xxx:x \\x0Aonerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x22onerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x0Bonerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x0Donerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x2Fonerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x09onerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x0Conerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x00onerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x27onerror=javascript:alert(1)>",
|
||||
"`\"'><img src=xxx:x \\x20onerror=javascript:alert(1)>",
|
||||
"\"`'><script>\\x3Bjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\x0Djavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xEF\\xBB\\xBFjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x81javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x84javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE3\\x80\\x80javascript:alert(1)</script>",
|
||||
"\"`'><script>\\x09javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x89javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x85javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x88javascript:alert(1)</script>",
|
||||
"\"`'><script>\\x00javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\xA8javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x8Ajavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE1\\x9A\\x80javascript:alert(1)</script>",
|
||||
"\"`'><script>\\x0Cjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\x2Bjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xF0\\x90\\x96\\x9Ajavascript:alert(1)</script>",
|
||||
"\"`'><script>-javascript:alert(1)</script>",
|
||||
"\"`'><script>\\x0Ajavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\xAFjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\x7Ejavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x87javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x81\\x9Fjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\xA9javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xC2\\x85javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xEF\\xBF\\xAEjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x83javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x8Bjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xEF\\xBF\\xBEjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x80javascript:alert(1)</script>",
|
||||
"\"`'><script>\\x21javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x82javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE2\\x80\\x86javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xE1\\xA0\\x8Ejavascript:alert(1)</script>",
|
||||
"\"`'><script>\\x0Bjavascript:alert(1)</script>",
|
||||
"\"`'><script>\\x20javascript:alert(1)</script>",
|
||||
"\"`'><script>\\xC2\\xA0javascript:alert(1)</script>",
|
||||
"<img \\x00src=x onerror=\"alert(1)\">",
|
||||
"<img \\x47src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x11src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x12src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x47src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x10src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x13src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x32src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x47src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img\\x11src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x47src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x34src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x39src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img \\x00src=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x09=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x10=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x13=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x32=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x12=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x11=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x00=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src\\x47=x onerror=\"javascript:alert(1)\">",
|
||||
"<img src=x\\x09onerror=\"javascript:alert(1)\">",
|
||||
"<img src=x\\x10onerror=\"javascript:alert(1)\">",
|
||||
"<img src=x\\x11onerror=\"javascript:alert(1)\">",
|
||||
"<img src=x\\x12onerror=\"javascript:alert(1)\">",
|
||||
"<img src=x\\x13onerror=\"javascript:alert(1)\">",
|
||||
"<img[a][b][c]src[d]=x[e]onerror=[f]\"alert(1)\">",
|
||||
"<img src=x onerror=\\x09\"javascript:alert(1)\">",
|
||||
"<img src=x onerror=\\x10\"javascript:alert(1)\">",
|
||||
"<img src=x onerror=\\x11\"javascript:alert(1)\">",
|
||||
"<img src=x onerror=\\x12\"javascript:alert(1)\">",
|
||||
"<img src=x onerror=\\x32\"javascript:alert(1)\">",
|
||||
"<img src=x onerror=\\x00\"javascript:alert(1)\">",
|
||||
"<a href=javascript:javascript:alert(1)>XXX</a>",
|
||||
"<img src=\"x` `<script>javascript:alert(1)</script>\"` `>",
|
||||
"<img src onerror /\" '\"= alt=javascript:alert(1)//\">",
|
||||
"<title onpropertychange=javascript:alert(1)></title><title title=>",
|
||||
"<a href=http://foo.bar/#x=`y></a><img alt=\"`><img src=x:x onerror=javascript:alert(1)></a>\">",
|
||||
"<!--[if]><script>javascript:alert(1)</script -->",
|
||||
"<!--[if<img src=x onerror=javascript:alert(1)//]> -->",
|
||||
"<script src=\"/\\%(jscript)s\"></script>",
|
||||
"<script src=\"\\\\%(jscript)s\"></script>",
|
||||
"<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">",
|
||||
"<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>",
|
||||
"<IMG SRC=# onmouseover=\"alert('xxs')\">",
|
||||
"<IMG SRC= onmouseover=\"alert('xxs')\">",
|
||||
"<IMG onmouseover=\"alert('xxs')\">",
|
||||
"<IMG SRC=javascript:alert('XSS')>",
|
||||
"<IMG SRC=javascript:alert('XSS')>",
|
||||
"<IMG SRC=javascript:alert('XSS')>",
|
||||
"<IMG SRC=\"jav ascript:alert('XSS');\">",
|
||||
"<IMG SRC=\"jav	ascript:alert('XSS');\">",
|
||||
"<IMG SRC=\"jav
ascript:alert('XSS');\">",
|
||||
"<IMG SRC=\"jav
ascript:alert('XSS');\">",
|
||||
"perl -e 'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";' > out",
|
||||
"<IMG SRC=\"  javascript:alert('XSS');\">",
|
||||
"<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>",
|
||||
"<BODY onload!#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>",
|
||||
"<SCRIPT/SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>",
|
||||
"<<SCRIPT>alert(\"XSS\");//<</SCRIPT>",
|
||||
"<SCRIPT SRC=http://ha.ckers.org/xss.js?< B >",
|
||||
"<SCRIPT SRC=//ha.ckers.org/.j>",
|
||||
"<IMG SRC=\"javascript:alert('XSS')\"",
|
||||
"<iframe src=http://ha.ckers.org/scriptlet.html <",
|
||||
"\\\";alert('XSS');//",
|
||||
"<u oncopy=alert()> Copy me</u>",
|
||||
"<i onwheel=alert(1)> Scroll over me </i>",
|
||||
"<plaintext>",
|
||||
"http://a/%%30%30",
|
||||
"</textarea><script>alert(123)</script>",
|
||||
"1;DROP TABLE users",
|
||||
"1'; DROP TABLE users-- 1",
|
||||
"' OR 1=1 -- 1",
|
||||
"' OR '1'='1",
|
||||
" ",
|
||||
"%",
|
||||
"_",
|
||||
"-",
|
||||
"--",
|
||||
"--version",
|
||||
"--help",
|
||||
"$USER",
|
||||
"/dev/null; touch /tmp/blns.fail ; echo",
|
||||
"`touch /tmp/blns.fail`",
|
||||
"$(touch /tmp/blns.fail)",
|
||||
"@{[system \"touch /tmp/blns.fail\"]}",
|
||||
"eval(\"puts 'hello world'\")",
|
||||
"System(\"ls -al /\")",
|
||||
"`ls -al /`",
|
||||
"Kernel.exec(\"ls -al /\")",
|
||||
"Kernel.exit(1)",
|
||||
"%x('ls -al /')",
|
||||
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><!DOCTYPE foo [ <!ELEMENT foo ANY ><!ENTITY xxe SYSTEM \"file:///etc/passwd\" >]><foo>&xxe;</foo>",
|
||||
"$HOME",
|
||||
"$ENV{'HOME'}",
|
||||
"%d",
|
||||
"%s",
|
||||
"{0}",
|
||||
"%*.*s",
|
||||
"../../../../../../../../../../../etc/passwd%00",
|
||||
"../../../../../../../../../../../etc/hosts",
|
||||
"() { 0; }; touch /tmp/blns.shellshock1.fail;",
|
||||
"() { _; } >_[$($())] { touch /tmp/blns.shellshock2.fail; }",
|
||||
"+++ATH0",
|
||||
"<<< %s(un='%s') = %u",
|
||||
"CON",
|
||||
"PRN",
|
||||
"AUX",
|
||||
"CLOCK$",
|
||||
"NUL",
|
||||
"A:",
|
||||
"ZZ:",
|
||||
"COM1",
|
||||
"LPT1",
|
||||
"LPT2",
|
||||
"LPT3",
|
||||
"COM2",
|
||||
"COM3",
|
||||
"COM4",
|
||||
"DCC SEND STARTKEYLOGGER 0 0 0",
|
||||
"Scunthorpe General Hospital",
|
||||
"Penistone Community Church",
|
||||
"Lightwater Country Park",
|
||||
"Jimmy Clitheroe",
|
||||
"Horniman Museum",
|
||||
"shitake mushrooms",
|
||||
"RomansInSussex.co.uk",
|
||||
"http://www.cum.qc.ca/",
|
||||
"Craig Cockburn, Software Specialist",
|
||||
"Linda Callahan",
|
||||
"Dr. Herman I. Libshitz",
|
||||
"magna cum laude",
|
||||
"Super Bowl XXX",
|
||||
"medieval erection of parapets",
|
||||
"evaluate",
|
||||
"mocha",
|
||||
"expression",
|
||||
"Arsenal canal",
|
||||
"classic",
|
||||
"Tyson Gay",
|
||||
"Dick Van Dyke",
|
||||
"basement",
|
||||
"If you're reading this, you've been in a coma for almost 20 years now. We're trying a new technique. We don't know where this message will end up in your dream, but we hope it works. Please wake up, we miss you.",
|
||||
"Roses are \u001b[0;31mred\u001b[0m, violets are \u001b[0;34mblue. Hope you enjoy terminal hue",
|
||||
"But now...\u001b[20Cfor my greatest trick...\u001b[8m",
|
||||
"The quic\b\b\b\b\b\bk brown fo\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007\u0007x... [Beeeep]",
|
||||
"Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗"
|
||||
]
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (fuzz test support)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
This file implements a driver for American Fuzzy Lop (afl-fuzz). It relies on
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (fuzz test support)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
This file implements a parser test suitable for fuzz testing. Given a byte
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (fuzz test support)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
This file implements a parser test suitable for fuzz testing. Given a byte
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (fuzz test support)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
This file implements a parser test suitable for fuzz testing. Given a byte
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -59,7 +59,7 @@ TEST_CASE("bad_alloc")
|
|||
bad_allocator>;
|
||||
|
||||
// creating an object should throw
|
||||
CHECK_THROWS_AS(bad_json j(bad_json::value_t::object), std::bad_alloc);
|
||||
CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ struct my_allocator : std::allocator<T>
|
|||
}
|
||||
else
|
||||
{
|
||||
::new(reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
::new (reinterpret_cast<void*>(p)) T(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,39 +141,27 @@ TEST_CASE("controlled bad_alloc")
|
|||
{
|
||||
next_construct_fails = false;
|
||||
auto t = my_json::value_t::object;
|
||||
auto clean_up = [](my_json::json_value & j)
|
||||
{
|
||||
my_allocator_clean_up(j.object);
|
||||
};
|
||||
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
SECTION("array")
|
||||
{
|
||||
next_construct_fails = false;
|
||||
auto t = my_json::value_t::array;
|
||||
auto clean_up = [](my_json::json_value & j)
|
||||
{
|
||||
my_allocator_clean_up(j.array);
|
||||
};
|
||||
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
SECTION("string")
|
||||
{
|
||||
next_construct_fails = false;
|
||||
auto t = my_json::value_t::string;
|
||||
auto clean_up = [](my_json::json_value & j)
|
||||
{
|
||||
my_allocator_clean_up(j.string);
|
||||
};
|
||||
CHECK_NOTHROW(my_json::json_value j(t); clean_up(j));
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json::json_value j(t), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
}
|
||||
|
@ -182,13 +170,9 @@ TEST_CASE("controlled bad_alloc")
|
|||
{
|
||||
next_construct_fails = false;
|
||||
my_json::string_t v("foo");
|
||||
auto clean_up = [](my_json::json_value & j)
|
||||
{
|
||||
my_allocator_clean_up(j.string);
|
||||
};
|
||||
CHECK_NOTHROW(my_json::json_value j(v); clean_up(j));
|
||||
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json::json_value j(v), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
|
||||
|
@ -222,9 +206,9 @@ TEST_CASE("controlled bad_alloc")
|
|||
{
|
||||
next_construct_fails = false;
|
||||
std::map<std::string, std::string> v {{"foo", "bar"}};
|
||||
CHECK_NOTHROW(my_json j(v));
|
||||
CHECK_NOTHROW(my_json(v));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json j(v), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json(v), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
|
||||
|
@ -232,18 +216,18 @@ TEST_CASE("controlled bad_alloc")
|
|||
{
|
||||
next_construct_fails = false;
|
||||
std::vector<std::string> v {"foo", "bar", "baz"};
|
||||
CHECK_NOTHROW(my_json j(v));
|
||||
CHECK_NOTHROW(my_json(v));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json j(v), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json(v), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
|
||||
SECTION("basic_json(const typename string_t::value_type*)")
|
||||
{
|
||||
next_construct_fails = false;
|
||||
CHECK_NOTHROW(my_json v("foo"));
|
||||
CHECK_NOTHROW(my_json("foo"));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json v("foo"), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json("foo"), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
|
||||
|
@ -251,9 +235,9 @@ TEST_CASE("controlled bad_alloc")
|
|||
{
|
||||
next_construct_fails = false;
|
||||
std::string s("foo");
|
||||
CHECK_NOTHROW(my_json v(s));
|
||||
CHECK_NOTHROW(my_json(s));
|
||||
next_construct_fails = true;
|
||||
CHECK_THROWS_AS(my_json v(s), std::bad_alloc);
|
||||
CHECK_THROWS_AS(my_json(s), std::bad_alloc);
|
||||
next_construct_fails = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -1187,7 +1187,7 @@ TEST_CASE("single CBOR roundtrip")
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CBOR regressions")
|
||||
TEST_CASE("CBOR regressions", "[!throws]")
|
||||
{
|
||||
SECTION("fuzz test results")
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -91,7 +91,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::null);
|
||||
json::const_iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.cbegin());
|
||||
CHECK((it == j.cbegin()));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
|
@ -99,7 +99,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::object);
|
||||
json::const_iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.cbegin());
|
||||
CHECK((it == j.cbegin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
|
@ -107,7 +107,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::array);
|
||||
json::const_iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.cbegin());
|
||||
CHECK((it == j.cbegin()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::null);
|
||||
json::const_iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.cend());
|
||||
CHECK((it == j.cend()));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
|
@ -126,7 +126,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::object);
|
||||
json::const_iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.cend());
|
||||
CHECK((it == j.cend()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
|
@ -134,7 +134,7 @@ TEST_CASE("const_iterator class")
|
|||
json j(json::value_t::array);
|
||||
json::const_iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.cend());
|
||||
CHECK((it == j.cend()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,48 +220,48 @@ TEST_CASE("const_iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it++;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
it++;
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it++;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
it++;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,48 +271,48 @@ TEST_CASE("const_iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
++it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
++it;
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
++it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
++it;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::const_iterator it = j.cbegin();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,46 +322,46 @@ TEST_CASE("const_iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it--;
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
it--;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,46 +371,46 @@ TEST_CASE("const_iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
--it;
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
--it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::const_iterator it = j.cend();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -75,7 +75,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::null);
|
||||
json::iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.begin());
|
||||
CHECK((it == j.begin()));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
|
@ -83,7 +83,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::object);
|
||||
json::iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.begin());
|
||||
CHECK((it == j.begin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
|
@ -91,7 +91,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::array);
|
||||
json::iterator it(&j);
|
||||
it.set_begin();
|
||||
CHECK(it == j.begin());
|
||||
CHECK((it == j.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::null);
|
||||
json::iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.end());
|
||||
CHECK((it == j.end()));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
|
@ -110,7 +110,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::object);
|
||||
json::iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.end());
|
||||
CHECK((it == j.end()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
|
@ -118,7 +118,7 @@ TEST_CASE("iterator class")
|
|||
json j(json::value_t::array);
|
||||
json::iterator it(&j);
|
||||
it.set_end();
|
||||
CHECK(it == j.end());
|
||||
CHECK((it == j.end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,48 +204,48 @@ TEST_CASE("iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it++;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
it++;
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it++;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
it++;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it++;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,48 +255,48 @@ TEST_CASE("iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
++it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
++it;
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
++it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
++it;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::iterator it = j.begin();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
++it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -306,46 +306,46 @@ TEST_CASE("iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
it--;
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
it--;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
it--;
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,46 +355,46 @@ TEST_CASE("iterator class")
|
|||
{
|
||||
json j(json::value_t::null);
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
}
|
||||
|
||||
SECTION("number")
|
||||
{
|
||||
json j(17);
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.primitive_iterator == 1);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 1));
|
||||
--it;
|
||||
CHECK(it.m_it.primitive_iterator == 0);
|
||||
CHECK((it.m_it.primitive_iterator.m_it == 0));
|
||||
--it;
|
||||
CHECK((it.m_it.primitive_iterator != 0 and it.m_it.primitive_iterator != 1));
|
||||
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
|
||||
}
|
||||
|
||||
SECTION("object")
|
||||
{
|
||||
json j({{"foo", "bar"}});
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin());
|
||||
CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
|
||||
}
|
||||
|
||||
SECTION("array")
|
||||
{
|
||||
json j({1, 2, 3, 4});
|
||||
json::iterator it = j.end();
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
--it;
|
||||
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin());
|
||||
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end());
|
||||
CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
|
||||
CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -38,86 +38,100 @@ TEST_CASE("lexer class")
|
|||
{
|
||||
SECTION("structural characters")
|
||||
{
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("["),
|
||||
1).scan() == json::lexer::token_type::begin_array);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("]"),
|
||||
1).scan() == json::lexer::token_type::end_array);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("{"),
|
||||
1).scan() == json::lexer::token_type::begin_object);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("}"),
|
||||
1).scan() == json::lexer::token_type::end_object);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(","),
|
||||
1).scan() == json::lexer::token_type::value_separator);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(":"),
|
||||
1).scan() == json::lexer::token_type::name_separator);
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("["),
|
||||
1).scan() == json::lexer::token_type::begin_array));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("]"),
|
||||
1).scan() == json::lexer::token_type::end_array));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("{"),
|
||||
1).scan() == json::lexer::token_type::begin_object));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("}"),
|
||||
1).scan() == json::lexer::token_type::end_object));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(","),
|
||||
1).scan() == json::lexer::token_type::value_separator));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(":"),
|
||||
1).scan() == json::lexer::token_type::name_separator));
|
||||
}
|
||||
|
||||
SECTION("literal names")
|
||||
{
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("null"),
|
||||
4).scan() == json::lexer::token_type::literal_null);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("true"),
|
||||
4).scan() == json::lexer::token_type::literal_true);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("false"),
|
||||
5).scan() == json::lexer::token_type::literal_false);
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("null"),
|
||||
4).scan() == json::lexer::token_type::literal_null));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("true"),
|
||||
4).scan() == json::lexer::token_type::literal_true));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("false"),
|
||||
5).scan() == json::lexer::token_type::literal_false));
|
||||
}
|
||||
|
||||
SECTION("numbers")
|
||||
{
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"),
|
||||
1).scan() == json::lexer::token_type::value_number);
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("0"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("2"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("3"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("4"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("5"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("6"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("7"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("8"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("9"),
|
||||
1).scan() == json::lexer::token_type::value_unsigned));
|
||||
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-0"),
|
||||
2).scan() == json::lexer::token_type::value_integer));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1"),
|
||||
2).scan() == json::lexer::token_type::value_integer));
|
||||
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1.1"),
|
||||
3).scan() == json::lexer::token_type::value_float));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("-1.1"),
|
||||
4).scan() == json::lexer::token_type::value_float));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("1E10"),
|
||||
4).scan() == json::lexer::token_type::value_float));
|
||||
}
|
||||
|
||||
SECTION("whitespace")
|
||||
{
|
||||
// result is end_of_input, because not token is following
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(" "),
|
||||
1).scan() == json::lexer::token_type::end_of_input);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\t"),
|
||||
1).scan() == json::lexer::token_type::end_of_input);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\n"),
|
||||
1).scan() == json::lexer::token_type::end_of_input);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\r"),
|
||||
1).scan() == json::lexer::token_type::end_of_input);
|
||||
CHECK(json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(" \t\n\r\n\t "),
|
||||
7).scan() == json::lexer::token_type::end_of_input);
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(" "),
|
||||
1).scan() == json::lexer::token_type::end_of_input));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\t"),
|
||||
1).scan() == json::lexer::token_type::end_of_input));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\n"),
|
||||
1).scan() == json::lexer::token_type::end_of_input));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>("\r"),
|
||||
1).scan() == json::lexer::token_type::end_of_input));
|
||||
CHECK((json::lexer(reinterpret_cast<const json::lexer::lexer_char_t*>(" \t\n\r\n\t "),
|
||||
7).scan() == json::lexer::token_type::end_of_input));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("token_type_name")
|
||||
{
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::uninitialized) == "<uninitialized>");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::literal_true) == "true literal");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::value_number) == "number literal");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::end_array) == "']'");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::end_object) == "'}'");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::name_separator) == "':'");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::value_separator) == "','");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::parse_error) == "<parse error>");
|
||||
CHECK(json::lexer::token_type_name(json::lexer::token_type::end_of_input) == "end of input");
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::uninitialized) == "<uninitialized>"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_true) == "true literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_false) == "false literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::literal_null) == "null literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_string) == "string literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_unsigned) == "number literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_integer) == "number literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_float) == "number literal"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_array) == "'['"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::begin_object) == "'{'"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::end_array) == "']'"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::end_object) == "'}'"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::name_separator) == "':'"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::value_separator) == "','"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::parse_error) == "<parse error>"));
|
||||
CHECK((json::lexer::token_type_name(json::lexer::token_type::end_of_input) == "end of input"));
|
||||
}
|
||||
|
||||
SECTION("parse errors on first character")
|
||||
|
@ -150,7 +164,7 @@ TEST_CASE("lexer class")
|
|||
case ('8'):
|
||||
case ('9'):
|
||||
{
|
||||
CHECK(res != json::lexer::token_type::parse_error);
|
||||
CHECK((res != json::lexer::token_type::parse_error));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -160,14 +174,14 @@ TEST_CASE("lexer class")
|
|||
case ('\n'):
|
||||
case ('\r'):
|
||||
{
|
||||
CHECK(res == json::lexer::token_type::end_of_input);
|
||||
CHECK((res == json::lexer::token_type::end_of_input));
|
||||
break;
|
||||
}
|
||||
|
||||
// anything else is not expected
|
||||
default:
|
||||
{
|
||||
CHECK(res == json::lexer::token_type::parse_error);
|
||||
CHECK((res == json::lexer::token_type::parse_error));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -101,6 +101,7 @@ TEST_CASE("parser class")
|
|||
CHECK_THROWS_WITH(json::parser("\"\b\"").parse(), "parse error - unexpected '\"'");
|
||||
// improve code coverage
|
||||
CHECK_THROWS_AS(json::parser("\uFF01").parse(), std::invalid_argument);
|
||||
CHECK_THROWS_AS(json::parser("[-4:1,]").parse(), std::invalid_argument);
|
||||
// unescaped control characters
|
||||
CHECK_THROWS_AS(json::parser("\"\x00\"").parse(), std::invalid_argument);
|
||||
CHECK_THROWS_AS(json::parser("\"\x01\"").parse(), std::invalid_argument);
|
||||
|
@ -269,6 +270,11 @@ TEST_CASE("parser class")
|
|||
}
|
||||
}
|
||||
|
||||
SECTION("overflow")
|
||||
{
|
||||
CHECK(json::parser("1.18973e+4932").parse() == json());
|
||||
}
|
||||
|
||||
SECTION("invalid numbers")
|
||||
{
|
||||
CHECK_THROWS_AS(json::parser("01").parse(), std::invalid_argument);
|
||||
|
@ -293,7 +299,7 @@ TEST_CASE("parser class")
|
|||
CHECK_THROWS_AS(json::parser("+0").parse(), std::invalid_argument);
|
||||
|
||||
CHECK_THROWS_WITH(json::parser("01").parse(),
|
||||
"parse error - unexpected number literal; expected end of input");
|
||||
"parse error - unexpected number literal");
|
||||
CHECK_THROWS_WITH(json::parser("--1").parse(), "parse error - unexpected '-'");
|
||||
CHECK_THROWS_WITH(json::parser("1.").parse(),
|
||||
"parse error - unexpected '.'; expected end of input");
|
||||
|
@ -596,6 +602,32 @@ TEST_CASE("parser class")
|
|||
"missing or wrong low surrogate");
|
||||
}
|
||||
|
||||
SECTION("tests found by mutate++")
|
||||
{
|
||||
// test case to make sure no comma preceeds the first key
|
||||
CHECK_THROWS_AS(json::parser("{,\"key\": false}").parse(), std::invalid_argument);
|
||||
// test case to make sure an object is properly closed
|
||||
CHECK_THROWS_AS(json::parser("[{\"key\": false true]").parse(), std::invalid_argument);
|
||||
|
||||
// test case to make sure the callback is properly evaluated after reading a key
|
||||
{
|
||||
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
|
||||
{
|
||||
if (event == json::parse_event_t::key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
json x = json::parse("{\"key\": false}", cb);
|
||||
CHECK(x == json::object());
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("callback function")
|
||||
{
|
||||
auto s_object = R"(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -912,7 +912,7 @@ TEST_CASE("constructors")
|
|||
|
||||
SECTION("array")
|
||||
{
|
||||
json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} , 13 };
|
||||
json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 };
|
||||
CHECK(j.type() == json::value_t::array);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -160,12 +160,30 @@ TEST_CASE("value conversion")
|
|||
{
|
||||
std::forward_list<json> a = j.get<std::forward_list<json>>();
|
||||
CHECK(json(a) == j);
|
||||
|
||||
CHECK_THROWS_AS(json(json::value_t::null).get<std::forward_list<json>>(), std::logic_error);
|
||||
CHECK_THROWS_WITH(json(json::value_t::null).get<std::forward_list<json>>(),
|
||||
"type must be array, but is null");
|
||||
}
|
||||
|
||||
SECTION("std::vector<json>")
|
||||
{
|
||||
std::vector<json> a = j.get<std::vector<json>>();
|
||||
CHECK(json(a) == j);
|
||||
|
||||
CHECK_THROWS_AS(json(json::value_t::null).get<std::vector<json>>(), std::logic_error);
|
||||
CHECK_THROWS_WITH(json(json::value_t::null).get<std::vector<json>>(),
|
||||
"type must be array, but is null");
|
||||
|
||||
#if not defined(JSON_NOEXCEPTION)
|
||||
SECTION("reserve is called on containers that supports it")
|
||||
{
|
||||
// making the call to from_json throw in order to check capacity
|
||||
std::vector<float> v;
|
||||
CHECK_THROWS_AS(nlohmann::from_json(j, v), std::logic_error);
|
||||
CHECK(v.capacity() == j.size());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SECTION("std::deque<json>")
|
||||
|
@ -184,6 +202,8 @@ TEST_CASE("value conversion")
|
|||
CHECK_THROWS_AS(json(json::value_t::number_unsigned).get<json::array_t>(), std::logic_error);
|
||||
CHECK_THROWS_AS(json(json::value_t::number_float).get<json::array_t>(), std::logic_error);
|
||||
|
||||
CHECK_THROWS_WITH(json(json::value_t::object).get<std::vector<int>>(),
|
||||
"type must be array, but is object");
|
||||
CHECK_THROWS_WITH(json(json::value_t::null).get<json::array_t>(),
|
||||
"type must be array, but is null");
|
||||
CHECK_THROWS_WITH(json(json::value_t::object).get<json::array_t>(),
|
||||
|
@ -952,14 +972,14 @@ TEST_CASE("value conversion")
|
|||
auto m5 = j5.get<std::list<std::string>>();
|
||||
}
|
||||
|
||||
//SECTION("std::forward_list")
|
||||
//{
|
||||
// auto m1 = j1.get<std::forward_list<int>>();
|
||||
// auto m2 = j2.get<std::forward_list<unsigned int>>();
|
||||
// auto m3 = j3.get<std::forward_list<double>>();
|
||||
// auto m4 = j4.get<std::forward_list<bool>>();
|
||||
// auto m5 = j5.get<std::forward_list<std::string>>();
|
||||
//}
|
||||
SECTION("std::forward_list")
|
||||
{
|
||||
auto m1 = j1.get<std::forward_list<int>>();
|
||||
auto m2 = j2.get<std::forward_list<unsigned int>>();
|
||||
auto m3 = j3.get<std::forward_list<double>>();
|
||||
auto m4 = j4.get<std::forward_list<bool>>();
|
||||
auto m5 = j5.get<std::forward_list<std::string>>();
|
||||
}
|
||||
|
||||
SECTION("std::vector")
|
||||
{
|
||||
|
@ -1004,6 +1024,8 @@ TEST_CASE("value conversion")
|
|||
CHECK_THROWS_AS((json().get<std::vector<json>>()), std::logic_error);
|
||||
CHECK_THROWS_AS((json().get<std::list<json>>()), std::logic_error);
|
||||
|
||||
// does type really must be an array? or it rather must not be null?
|
||||
// that's what I thought when other test like this one broke
|
||||
CHECK_THROWS_WITH((json().get<std::list<int>>()), "type must be array, but is null");
|
||||
CHECK_THROWS_WITH((json().get<std::vector<int>>()), "type must be array, but is null");
|
||||
CHECK_THROWS_WITH((json().get<std::vector<json>>()), "type must be array, but is null");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -298,25 +298,6 @@ TEST_CASE("element access 2")
|
|||
CHECK(j_const.value("/array"_json_pointer, json({10, 100})) == json({1, 2, 3}));
|
||||
}
|
||||
|
||||
SECTION("access non-existing value")
|
||||
{
|
||||
CHECK(j.value("/not/existing"_json_pointer, 2) == 2);
|
||||
CHECK(j.value("/not/existing"_json_pointer, 2u) == 2u);
|
||||
CHECK(j.value("/not/existing"_json_pointer, false) == false);
|
||||
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
|
||||
CHECK(j.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
|
||||
CHECK(j.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
|
||||
CHECK(j.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
|
||||
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 2u) == 2u);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, "bar") == "bar");
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
|
||||
}
|
||||
|
||||
SECTION("access on non-object type")
|
||||
{
|
||||
SECTION("null")
|
||||
|
@ -957,3 +938,37 @@ TEST_CASE("element access 2")
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("element access 2 (throwing tests)", "[!throws]")
|
||||
{
|
||||
SECTION("object")
|
||||
{
|
||||
json j = {{"integer", 1}, {"unsigned", 1u}, {"floating", 42.23}, {"null", nullptr}, {"string", "hello world"}, {"boolean", true}, {"object", json::object()}, {"array", {1, 2, 3}}};
|
||||
const json j_const = j;
|
||||
|
||||
SECTION("access specified element with default value")
|
||||
{
|
||||
SECTION("given a JSON pointer")
|
||||
{
|
||||
SECTION("access non-existing value")
|
||||
{
|
||||
CHECK(j.value("/not/existing"_json_pointer, 2) == 2);
|
||||
CHECK(j.value("/not/existing"_json_pointer, 2u) == 2u);
|
||||
CHECK(j.value("/not/existing"_json_pointer, false) == false);
|
||||
CHECK(j.value("/not/existing"_json_pointer, "bar") == "bar");
|
||||
CHECK(j.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
|
||||
CHECK(j.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
|
||||
CHECK(j.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
|
||||
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 2) == 2);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 2u) == 2u);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, false) == false);
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, "bar") == "bar");
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, 12.34) == Approx(12.34));
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, json({{"foo", "bar"}})) == json({{"foo", "bar"}}));
|
||||
CHECK(j_const.value("/not/existing"_json_pointer, json({10, 100})) == json({10, 100}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
40
test/src/unit-meta.cpp
Normal file
40
test/src/unit-meta.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "json.hpp"
|
||||
using nlohmann::json;
|
||||
|
||||
TEST_CASE("version information")
|
||||
{
|
||||
SECTION("version()")
|
||||
{
|
||||
CHECK(json::meta()["name"] == "JSON for Modern C++");
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
59
test/src/unit-noexcept.cpp
Normal file
59
test/src/unit-noexcept.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
Copyright (c) 2013-2017 Niels Lohmann <http://nlohmann.me>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "json.hpp"
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
enum test
|
||||
{
|
||||
};
|
||||
|
||||
struct pod {};
|
||||
struct pod_bis {};
|
||||
|
||||
void to_json(json&, pod) noexcept;
|
||||
void to_json(json&, pod_bis);
|
||||
void from_json(const json&, pod) noexcept;
|
||||
void from_json(const json&, pod_bis);
|
||||
static json j;
|
||||
|
||||
static_assert(noexcept(json{}), "");
|
||||
static_assert(noexcept(nlohmann::to_json(j, 2)), "");
|
||||
static_assert(noexcept(nlohmann::to_json(j, 2.5)), "");
|
||||
static_assert(noexcept(nlohmann::to_json(j, true)), "");
|
||||
static_assert(noexcept(nlohmann::to_json(j, test{})), "");
|
||||
static_assert(noexcept(nlohmann::to_json(j, pod{})), "");
|
||||
static_assert(not noexcept(nlohmann::to_json(j, pod_bis{})), "");
|
||||
static_assert(noexcept(json(2)), "");
|
||||
static_assert(noexcept(json(test{})), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
||||
static_assert(noexcept(j.get<pod>()), "");
|
||||
static_assert(not noexcept(j.get<pod_bis>()), "");
|
||||
static_assert(noexcept(json(pod{})), "");
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -63,10 +63,18 @@ TEST_CASE("regression tests")
|
|||
|
||||
SECTION("pull request #71 - handle enum type")
|
||||
{
|
||||
enum { t = 0 };
|
||||
enum { t = 0, u = 1};
|
||||
json j = json::array();
|
||||
j.push_back(t);
|
||||
|
||||
// maybe this is not the place to test this?
|
||||
json j2 = u;
|
||||
|
||||
auto anon_enum_value = j2.get<decltype(u)>();
|
||||
CHECK(u == anon_enum_value);
|
||||
|
||||
static_assert(std::is_same<decltype(anon_enum_value), decltype(u)>::value, "");
|
||||
|
||||
j.push_back(json::object(
|
||||
{
|
||||
{"game_type", t}
|
||||
|
@ -375,7 +383,7 @@ TEST_CASE("regression tests")
|
|||
};
|
||||
|
||||
// change locale to mess with decimal points
|
||||
std::locale::global(std::locale(std::locale(), new CommaDecimalSeparator));
|
||||
auto orig_locale = std::locale::global(std::locale(std::locale(), new CommaDecimalSeparator));
|
||||
|
||||
CHECK(j1a.dump() == "23.42");
|
||||
CHECK(j1b.dump() == "23.42");
|
||||
|
@ -399,8 +407,34 @@ TEST_CASE("regression tests")
|
|||
CHECK(j3c.dump() == "10000");
|
||||
//CHECK(j3b.dump() == "1E04"); // roundtrip error
|
||||
//CHECK(j3c.dump() == "1e04"); // roundtrip error
|
||||
|
||||
std::locale::global(orig_locale);
|
||||
}
|
||||
|
||||
SECTION("issue #379 - locale-independent str-to-num")
|
||||
{
|
||||
setlocale(LC_NUMERIC, "de_DE.UTF-8");
|
||||
|
||||
// disabled, because locale-specific beharivor is not
|
||||
// triggered in AppVeyor for some reason
|
||||
#ifndef _MSC_VER
|
||||
{
|
||||
// verify that strtod now uses commas as decimal-separator
|
||||
CHECK(std::strtod("3,14", nullptr) == 3.14);
|
||||
|
||||
// verify that strtod does not understand dots as decimal separator
|
||||
CHECK(std::strtod("3.14", nullptr) == 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
// verify that parsed correctly despite using strtod internally
|
||||
CHECK(json::parse("3.14").get<double>() == 3.14);
|
||||
|
||||
// check a different code path
|
||||
CHECK(json::parse("1.000000000000000000000000000000000000000000000000000000000000000000000000").get<double>() == 1.0);
|
||||
}
|
||||
|
||||
|
||||
SECTION("issue #233 - Can't use basic_json::iterator as a base iterator for std::move_iterator")
|
||||
{
|
||||
json source = {"a", "b", "c"};
|
||||
|
@ -681,4 +715,31 @@ TEST_CASE("regression tests")
|
|||
|
||||
#undef CHECK_TYPE
|
||||
}
|
||||
|
||||
SECTION("issue #416 - Use-of-uninitialized-value (OSS-Fuzz issue 377)")
|
||||
{
|
||||
// original test case
|
||||
std::vector<uint8_t> vec1
|
||||
{
|
||||
0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
|
||||
0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71,
|
||||
0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfa
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec1), std::out_of_range);
|
||||
|
||||
// related test case: double-precision
|
||||
std::vector<uint8_t> vec2
|
||||
{
|
||||
0x94, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa,
|
||||
0x3a, 0x96, 0x96, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4,
|
||||
0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0xb4, 0x71,
|
||||
0xb4, 0xb4, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0x3a,
|
||||
0x96, 0x96, 0xb4, 0xb4, 0xfa, 0x94, 0x94, 0x61,
|
||||
0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0x61, 0xfb
|
||||
};
|
||||
CHECK_THROWS_AS(json::from_cbor(vec2), std::out_of_range);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
@ -815,3 +815,57 @@ TEST_CASE("nst's JSONTestSuite")
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// from http://stackoverflow.com/a/25829178/266378
|
||||
std::string trim(const std::string& str)
|
||||
{
|
||||
size_t first = str.find_first_not_of(' ');
|
||||
if (std::string::npos == first)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
size_t last = str.find_last_not_of(' ');
|
||||
return str.substr(first, (last - first + 1));
|
||||
}
|
||||
|
||||
TEST_CASE("Big List of Naughty Strings")
|
||||
{
|
||||
// test from https://github.com/minimaxir/big-list-of-naughty-strings
|
||||
SECTION("parsing blns.json")
|
||||
{
|
||||
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
|
||||
json j;
|
||||
CHECK_NOTHROW(j << f);
|
||||
}
|
||||
|
||||
// check if parsed strings roundtrip
|
||||
// https://www.reddit.com/r/cpp/comments/5qpbie/json_form_modern_c_version_210/dd12mpq/
|
||||
SECTION("roundtripping")
|
||||
{
|
||||
std::ifstream f("test/data/big-list-of-naughty-strings/blns.json");
|
||||
|
||||
while (not f.eof())
|
||||
{
|
||||
// read line
|
||||
std::string line;
|
||||
getline(f, line);
|
||||
|
||||
// trim whitespace
|
||||
line = trim(line);
|
||||
|
||||
// remove trailing comma
|
||||
line = line.substr(0, line.find_last_of(","));
|
||||
|
||||
// discard lines without at least two characters (quotes)
|
||||
if (line.size() < 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// check roundtrip
|
||||
CAPTURE(line);
|
||||
json j = json::parse(line);
|
||||
CHECK(j.dump() == line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
680
test/src/unit-udt.cpp
Normal file
680
test/src/unit-udt.cpp
Normal file
|
@ -0,0 +1,680 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "json.hpp"
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
namespace udt
|
||||
{
|
||||
enum class country
|
||||
{
|
||||
china,
|
||||
france,
|
||||
russia
|
||||
};
|
||||
|
||||
struct age
|
||||
{
|
||||
int m_val;
|
||||
};
|
||||
|
||||
struct name
|
||||
{
|
||||
std::string m_val;
|
||||
};
|
||||
|
||||
struct address
|
||||
{
|
||||
std::string m_val;
|
||||
};
|
||||
|
||||
struct person
|
||||
{
|
||||
age m_age;
|
||||
name m_name;
|
||||
country m_country;
|
||||
};
|
||||
|
||||
struct contact
|
||||
{
|
||||
person m_person;
|
||||
address m_address;
|
||||
};
|
||||
|
||||
struct contact_book
|
||||
{
|
||||
name m_book_name;
|
||||
std::vector<contact> m_contacts;
|
||||
};
|
||||
}
|
||||
|
||||
// to_json methods
|
||||
namespace udt
|
||||
{
|
||||
// templates because of the custom_json tests (see below)
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, age a)
|
||||
{
|
||||
j = a.m_val;
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, const name& n)
|
||||
{
|
||||
j = n.m_val;
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, country c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case country::china:
|
||||
j = u8"中华人民共和国";
|
||||
return;
|
||||
case country::france:
|
||||
j = "France";
|
||||
return;
|
||||
case country::russia:
|
||||
j = u8"Российская Федерация";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, const person& p)
|
||||
{
|
||||
j = BasicJsonType{{"age", p.m_age}, {"name", p.m_name}, {"country", p.m_country}};
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const address& a)
|
||||
{
|
||||
j = a.m_val;
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const contact& c)
|
||||
{
|
||||
j = json{{"person", c.m_person}, {"address", c.m_address}};
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json& j, const contact_book& cb)
|
||||
{
|
||||
j = json{{"name", cb.m_book_name}, {"contacts", cb.m_contacts}};
|
||||
}
|
||||
|
||||
// operators
|
||||
bool operator==(age lhs, age rhs)
|
||||
{
|
||||
return lhs.m_val == rhs.m_val;
|
||||
}
|
||||
|
||||
bool operator==(const address& lhs, const address& rhs)
|
||||
{
|
||||
return lhs.m_val == rhs.m_val;
|
||||
}
|
||||
|
||||
bool operator==(const name& lhs, const name& rhs)
|
||||
{
|
||||
return lhs.m_val == rhs.m_val;
|
||||
}
|
||||
|
||||
bool operator==(const person& lhs, const person& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_name, lhs.m_age) == std::tie(rhs.m_name, rhs.m_age);
|
||||
}
|
||||
|
||||
bool operator==(const contact& lhs, const contact& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_person, lhs.m_address) ==
|
||||
std::tie(rhs.m_person, rhs.m_address);
|
||||
}
|
||||
|
||||
bool operator==(const contact_book& lhs, const contact_book& rhs)
|
||||
{
|
||||
return std::tie(lhs.m_book_name, lhs.m_contacts) ==
|
||||
std::tie(rhs.m_book_name, rhs.m_contacts);
|
||||
}
|
||||
}
|
||||
|
||||
// from_json methods
|
||||
namespace udt
|
||||
{
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, age& a)
|
||||
{
|
||||
a.m_val = j.template get<int>();
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, name& n)
|
||||
{
|
||||
n.m_val = j.template get<std::string>();
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, country& c)
|
||||
{
|
||||
const auto str = j.template get<std::string>();
|
||||
static const std::map<std::string, country> m =
|
||||
{
|
||||
{u8"中华人民共和国", country::china},
|
||||
{"France", country::france},
|
||||
{"Российская Федерация", country::russia}
|
||||
};
|
||||
|
||||
const auto it = m.find(str);
|
||||
// TODO test exceptions
|
||||
c = it->second;
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, person& p)
|
||||
{
|
||||
p.m_age = j["age"].template get<age>();
|
||||
p.m_name = j["name"].template get<name>();
|
||||
p.m_country = j["country"].template get<country>();
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, address& a)
|
||||
{
|
||||
a.m_val = j.get<std::string>();
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, contact& c)
|
||||
{
|
||||
c.m_person = j["person"].get<person>();
|
||||
c.m_address = j["address"].get<address>();
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, contact_book& cb)
|
||||
{
|
||||
cb.m_book_name = j["name"].get<name>();
|
||||
cb.m_contacts = j["contacts"].get<std::vector<contact>>();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("basic usage", "[udt]")
|
||||
{
|
||||
|
||||
// a bit narcissic maybe :) ?
|
||||
const udt::age a
|
||||
{
|
||||
23
|
||||
};
|
||||
const udt::name n{"theo"};
|
||||
const udt::country c{udt::country::france};
|
||||
const udt::person sfinae_addict{a, n, c};
|
||||
const udt::person senior_programmer{{42}, {u8"王芳"}, udt::country::china};
|
||||
const udt::address addr{"Paris"};
|
||||
const udt::contact cpp_programmer{sfinae_addict, addr};
|
||||
const udt::contact_book book{{"C++"}, {cpp_programmer, {senior_programmer, addr}}};
|
||||
|
||||
SECTION("conversion to json via free-functions")
|
||||
{
|
||||
CHECK(json(a) == json(23));
|
||||
CHECK(json(n) == json("theo"));
|
||||
CHECK(json(c) == json("France"));
|
||||
CHECK(json(sfinae_addict) == R"({"name":"theo", "age":23, "country":"France"})"_json);
|
||||
CHECK(json("Paris") == json(addr));
|
||||
CHECK(json(cpp_programmer) ==
|
||||
R"({"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"})"_json);
|
||||
|
||||
CHECK(
|
||||
json(book) ==
|
||||
u8R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json);
|
||||
|
||||
}
|
||||
|
||||
SECTION("conversion from json via free-functions")
|
||||
{
|
||||
const auto big_json =
|
||||
u8R"({"name":"C++", "contacts" : [{"person" : {"age":23, "name":"theo", "country":"France"}, "address":"Paris"}, {"person" : {"age":42, "country":"中华人民共和国", "name":"王芳"}, "address":"Paris"}]})"_json;
|
||||
SECTION("via explicit calls to get")
|
||||
{
|
||||
const auto parsed_book = big_json.get<udt::contact_book>();
|
||||
const auto book_name = big_json["name"].get<udt::name>();
|
||||
const auto contacts =
|
||||
big_json["contacts"].get<std::vector<udt::contact>>();
|
||||
const auto contact_json = big_json["contacts"].at(0);
|
||||
const auto contact = contact_json.get<udt::contact>();
|
||||
const auto person = contact_json["person"].get<udt::person>();
|
||||
const auto address = contact_json["address"].get<udt::address>();
|
||||
const auto age = contact_json["person"]["age"].get<udt::age>();
|
||||
const auto country =
|
||||
contact_json["person"]["country"].get<udt::country>();
|
||||
const auto name = contact_json["person"]["name"].get<udt::name>();
|
||||
|
||||
CHECK(age == a);
|
||||
CHECK(name == n);
|
||||
CHECK(country == c);
|
||||
CHECK(address == addr);
|
||||
CHECK(person == sfinae_addict);
|
||||
CHECK(contact == cpp_programmer);
|
||||
CHECK(contacts == book.m_contacts);
|
||||
CHECK(book_name == udt::name{"C++"});
|
||||
CHECK(book == parsed_book);
|
||||
}
|
||||
|
||||
SECTION("implicit conversions")
|
||||
{
|
||||
const udt::contact_book parsed_book = big_json;
|
||||
const udt::name book_name = big_json["name"];
|
||||
const std::vector<udt::contact> contacts = big_json["contacts"];
|
||||
const auto contact_json = big_json["contacts"].at(0);
|
||||
const udt::contact contact = contact_json;
|
||||
const udt::person person = contact_json["person"];
|
||||
const udt::address address = contact_json["address"];
|
||||
const udt::age age = contact_json["person"]["age"];
|
||||
const udt::country country = contact_json["person"]["country"];
|
||||
const udt::name name = contact_json["person"]["name"];
|
||||
|
||||
CHECK(age == a);
|
||||
CHECK(name == n);
|
||||
CHECK(country == c);
|
||||
CHECK(address == addr);
|
||||
CHECK(person == sfinae_addict);
|
||||
CHECK(contact == cpp_programmer);
|
||||
CHECK(contacts == book.m_contacts);
|
||||
CHECK(book_name == udt::name{"C++"});
|
||||
CHECK(book == parsed_book);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace udt
|
||||
{
|
||||
struct legacy_type
|
||||
{
|
||||
std::string number;
|
||||
};
|
||||
}
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <typename T>
|
||||
struct adl_serializer<std::shared_ptr<T>>
|
||||
{
|
||||
static void to_json(json& j, const std::shared_ptr<T>& opt)
|
||||
{
|
||||
if (opt)
|
||||
{
|
||||
j = *opt;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static void from_json(const json& j, std::shared_ptr<T>& opt)
|
||||
{
|
||||
if (j.is_null())
|
||||
{
|
||||
opt = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
opt.reset(new T(j.get<T>()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct adl_serializer<udt::legacy_type>
|
||||
{
|
||||
static void to_json(json& j, const udt::legacy_type& l)
|
||||
{
|
||||
j = std::stoi(l.number);
|
||||
}
|
||||
|
||||
static void from_json(const json& j, udt::legacy_type& l)
|
||||
{
|
||||
l.number = std::to_string(j.get<int>());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("adl_serializer specialization", "[udt]")
|
||||
{
|
||||
SECTION("partial specialization")
|
||||
{
|
||||
SECTION("to_json")
|
||||
{
|
||||
std::shared_ptr<udt::person> optPerson;
|
||||
|
||||
json j = optPerson;
|
||||
CHECK(j.is_null());
|
||||
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
|
||||
j = optPerson;
|
||||
CHECK_FALSE(j.is_null());
|
||||
|
||||
CHECK(j.get<udt::person>() == *optPerson);
|
||||
}
|
||||
|
||||
SECTION("from_json")
|
||||
{
|
||||
auto person = udt::person{{42}, {"John Doe"}, udt::country::russia};
|
||||
json j = person;
|
||||
|
||||
auto optPerson = j.get<std::shared_ptr<udt::person>>();
|
||||
REQUIRE(optPerson);
|
||||
CHECK(*optPerson == person);
|
||||
|
||||
j = nullptr;
|
||||
optPerson = j.get<std::shared_ptr<udt::person>>();
|
||||
CHECK(!optPerson);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("total specialization")
|
||||
{
|
||||
SECTION("to_json")
|
||||
{
|
||||
udt::legacy_type lt{"4242"};
|
||||
|
||||
json j = lt;
|
||||
CHECK(j.get<int>() == 4242);
|
||||
}
|
||||
|
||||
SECTION("from_json")
|
||||
{
|
||||
json j = 4242;
|
||||
auto lt = j.get<udt::legacy_type>();
|
||||
CHECK(lt.number == "4242");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <>
|
||||
struct adl_serializer<std::vector<float>>
|
||||
{
|
||||
using type = std::vector<float>;
|
||||
static void to_json(json& j, const type&)
|
||||
{
|
||||
j = "hijacked!";
|
||||
}
|
||||
|
||||
static void from_json(const json&, type& opt)
|
||||
{
|
||||
opt = {42.0, 42.0, 42.0};
|
||||
}
|
||||
|
||||
// preferred version
|
||||
static type from_json(const json&)
|
||||
{
|
||||
return {4.0, 5.0, 6.0};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("even supported types can be specialized", "[udt]")
|
||||
{
|
||||
json j = std::vector<float> {1.0, 2.0, 3.0};
|
||||
CHECK(j.dump() == R"("hijacked!")");
|
||||
auto f = j.get<std::vector<float>>();
|
||||
// the single argument from_json method is preferred
|
||||
CHECK((f == std::vector<float> {4.0, 5.0, 6.0}));
|
||||
}
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
template <typename T>
|
||||
struct adl_serializer<std::unique_ptr<T>>
|
||||
{
|
||||
static void to_json(json& j, const std::unique_ptr<T>& opt)
|
||||
{
|
||||
if (opt)
|
||||
{
|
||||
j = *opt;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// this is the overload needed for non-copyable types,
|
||||
static std::unique_ptr<T> from_json(const json& j)
|
||||
{
|
||||
if (j.is_null())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return std::unique_ptr<T>(new T(j.get<T>()));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("Non-copyable types", "[udt]")
|
||||
{
|
||||
SECTION("to_json")
|
||||
{
|
||||
std::unique_ptr<udt::person> optPerson;
|
||||
|
||||
json j = optPerson;
|
||||
CHECK(j.is_null());
|
||||
|
||||
optPerson.reset(new udt::person{{42}, {"John Doe"}, udt::country::russia});
|
||||
j = optPerson;
|
||||
CHECK_FALSE(j.is_null());
|
||||
|
||||
CHECK(j.get<udt::person>() == *optPerson);
|
||||
}
|
||||
|
||||
SECTION("from_json")
|
||||
{
|
||||
auto person = udt::person{{42}, {"John Doe"}, udt::country::russia};
|
||||
json j = person;
|
||||
|
||||
auto optPerson = j.get<std::unique_ptr<udt::person>>();
|
||||
REQUIRE(optPerson);
|
||||
CHECK(*optPerson == person);
|
||||
|
||||
j = nullptr;
|
||||
optPerson = j.get<std::unique_ptr<udt::person>>();
|
||||
CHECK(!optPerson);
|
||||
}
|
||||
}
|
||||
|
||||
// custom serializer - advanced usage
|
||||
// pack structs that are pod-types (but not scalar types)
|
||||
// relies on adl for any other type
|
||||
template <typename T, typename = void>
|
||||
struct pod_serializer
|
||||
{
|
||||
// use adl for non-pods, or scalar types
|
||||
template <
|
||||
typename BasicJsonType, typename U = T,
|
||||
typename std::enable_if <
|
||||
not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
|
||||
static void from_json(const BasicJsonType& j, U& t)
|
||||
{
|
||||
using nlohmann::from_json;
|
||||
from_json(j, t);
|
||||
}
|
||||
|
||||
// special behaviour for pods
|
||||
template <typename BasicJsonType, typename U = T,
|
||||
typename std::enable_if<
|
||||
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
|
||||
static void from_json(const BasicJsonType& j, U& t)
|
||||
{
|
||||
std::uint64_t value;
|
||||
// TODO The following block is no longer relevant in this serializer, make another one that shows the issue
|
||||
// the problem arises only when one from_json method is defined without any constraint
|
||||
//
|
||||
// Why cannot we simply use: j.get<std::uint64_t>() ?
|
||||
// Well, with the current experiment, the get method looks for a from_json
|
||||
// function, which we are currently defining!
|
||||
// This would end up in a stack overflow. Calling nlohmann::from_json is a
|
||||
// workaround (is it?).
|
||||
// I shall find a good way to avoid this once all constructors are converted
|
||||
// to free methods
|
||||
//
|
||||
// In short, constructing a json by constructor calls to_json
|
||||
// calling get calls from_json, for now, we cannot do this in custom
|
||||
// serializers
|
||||
nlohmann::from_json(j, value);
|
||||
auto bytes = static_cast<char*>(static_cast<void*>(&value));
|
||||
std::memcpy(&t, bytes, sizeof(value));
|
||||
}
|
||||
|
||||
template <
|
||||
typename BasicJsonType, typename U = T,
|
||||
typename std::enable_if <
|
||||
not(std::is_pod<U>::value and std::is_class<U>::value), int >::type = 0 >
|
||||
static void to_json(BasicJsonType& j, const T& t)
|
||||
{
|
||||
using nlohmann::to_json;
|
||||
to_json(j, t);
|
||||
}
|
||||
|
||||
template <typename BasicJsonType, typename U = T,
|
||||
typename std::enable_if<
|
||||
std::is_pod<U>::value and std::is_class<U>::value, int>::type = 0>
|
||||
static void to_json(BasicJsonType& j, const T& t) noexcept
|
||||
{
|
||||
auto bytes = static_cast< const unsigned char*>(static_cast<const void*>(&t));
|
||||
std::uint64_t value = bytes[0];
|
||||
for (auto i = 1; i < 8; ++i)
|
||||
value |= std::uint64_t{bytes[i]} << 8 * i;
|
||||
nlohmann::to_json(j, value);
|
||||
}
|
||||
};
|
||||
|
||||
namespace udt
|
||||
{
|
||||
struct small_pod
|
||||
{
|
||||
int begin;
|
||||
char middle;
|
||||
short end;
|
||||
};
|
||||
|
||||
struct non_pod
|
||||
{
|
||||
std::string s;
|
||||
};
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void to_json(BasicJsonType& j, const non_pod& np)
|
||||
{
|
||||
j = np.s;
|
||||
}
|
||||
|
||||
template <typename BasicJsonType>
|
||||
void from_json(const BasicJsonType& j, non_pod& np)
|
||||
{
|
||||
np.s = j.template get<std::string>();
|
||||
}
|
||||
|
||||
bool operator==(small_pod lhs, small_pod rhs) noexcept
|
||||
{
|
||||
return std::tie(lhs.begin, lhs.middle, lhs.end) ==
|
||||
std::tie(rhs.begin, rhs.middle, rhs.end);
|
||||
}
|
||||
|
||||
bool operator==(const non_pod& lhs, const non_pod& rhs) noexcept
|
||||
{
|
||||
return lhs.s == rhs.s;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, small_pod l)
|
||||
{
|
||||
return os << "begin: " << l.begin << ", middle: " << l.middle << ", end: " << l.end;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("custom serializer for pods", "[udt]")
|
||||
{
|
||||
using custom_json =
|
||||
nlohmann::basic_json<std::map, std::vector, std::string, bool,
|
||||
std::int64_t, std::uint64_t, double, std::allocator,
|
||||
pod_serializer>;
|
||||
|
||||
auto p = udt::small_pod{42, '/', 42};
|
||||
custom_json j = p;
|
||||
|
||||
auto p2 = j.get<udt::small_pod>();
|
||||
|
||||
CHECK(p == p2);
|
||||
|
||||
auto np = udt::non_pod{{"non-pod"}};
|
||||
custom_json j2 = np;
|
||||
auto np2 = j2.get<udt::non_pod>();
|
||||
CHECK(np == np2);
|
||||
}
|
||||
|
||||
template <typename T, typename>
|
||||
struct another_adl_serializer;
|
||||
|
||||
using custom_json = nlohmann::basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator, another_adl_serializer>;
|
||||
|
||||
template <typename T, typename>
|
||||
struct another_adl_serializer
|
||||
{
|
||||
static void from_json(const custom_json& j, T& t)
|
||||
{
|
||||
using nlohmann::from_json;
|
||||
from_json(j, t);
|
||||
}
|
||||
|
||||
static void to_json(custom_json& j, const T& t)
|
||||
{
|
||||
using nlohmann::to_json;
|
||||
to_json(j, t);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("custom serializer that does adl by default", "[udt]")
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
|
||||
auto me = udt::person{{23}, {"theo"}, udt::country::france};
|
||||
|
||||
json j = me;
|
||||
custom_json cj = me;
|
||||
|
||||
CHECK(j.dump() == cj.dump());
|
||||
|
||||
CHECK(me == j.get<udt::person>());
|
||||
CHECK(me == cj.get<udt::person>());
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
__ _____ _____ _____
|
||||
__| | __| | | | JSON for Modern C++ (test suite)
|
||||
| | |__ | | | | | | version 2.0.10
|
||||
| | |__ | | | | | | version 2.1.0
|
||||
|_____|_____|_____|_|___| https://github.com/nlohmann/json
|
||||
|
||||
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
|
|
1504
test/thirdparty/catch/catch.hpp
vendored
Executable file → Normal file
1504
test/thirdparty/catch/catch.hpp
vendored
Executable file → Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue