diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:44 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:44 +0300 |
commit | 59e19371de37995fcb36beb16cd6ec030af960bc (patch) | |
tree | fa68e36093ebff8b805462e9e6d331fe9d348214 /library/cpp/json/ut | |
parent | 89db6fe2fe2c32d2a832ddfeb04e8d078e301084 (diff) | |
download | ydb-59e19371de37995fcb36beb16cd6ec030af960bc.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json/ut')
-rw-r--r-- | library/cpp/json/ut/json_prettifier_ut.cpp | 92 | ||||
-rw-r--r-- | library/cpp/json/ut/json_reader_fast_ut.cpp | 186 | ||||
-rw-r--r-- | library/cpp/json/ut/json_reader_ut.cpp | 2 | ||||
-rw-r--r-- | library/cpp/json/ut/json_writer_ut.cpp | 60 |
4 files changed, 170 insertions, 170 deletions
diff --git a/library/cpp/json/ut/json_prettifier_ut.cpp b/library/cpp/json/ut/json_prettifier_ut.cpp index ae5f8dd81a..10946de93a 100644 --- a/library/cpp/json/ut/json_prettifier_ut.cpp +++ b/library/cpp/json/ut/json_prettifier_ut.cpp @@ -1,25 +1,25 @@ #include <library/cpp/json/json_prettifier.h> #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(JsonPrettifier) { Y_UNIT_TEST(PrettifyJsonShort) { - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson(""), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("null"), "null"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("true"), "true"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("false"), "false"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("1.5"), "1.5"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("test", false, 2, true), "'test'"); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]"), "[ ]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a]", false, 2), "[\n \"a\"\n]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a,b]", false, 2, true), "[\n 'a',\n 'b'\n]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{},b]", false, 2, true), "[\n { },\n 'b'\n]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a,{}]", false, 2, true), "[\n 'a',\n { }\n]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{},{}]"), "[\n { },\n { }\n]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v}", false, 2, true), "{\n 'k' : 'v'\n}"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson(""), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("null"), "null"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("true"), "true"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("false"), "false"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("1.5"), "1.5"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("test", false, 2, true), "'test'"); + + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]"), "[ ]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a]", false, 2), "[\n \"a\"\n]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a,b]", false, 2, true), "[\n 'a',\n 'b'\n]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{},b]", false, 2, true), "[\n { },\n 'b'\n]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[a,{}]", false, 2, true), "[\n 'a',\n { }\n]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{},{}]"), "[\n { },\n { }\n]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v}", false, 2, true), "{\n 'k' : 'v'\n}"); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("Test545", true, 2), "Test545"); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'null'", true, 2, true), "'null'"); @@ -45,7 +45,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " }\n" "]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,2,3]}", false, 2, true), + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,2,3]}", false, 2, true), "{\n" " 'k' : 'v',\n" " 'a' : 'b',\n" @@ -56,7 +56,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " ]\n" "}"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,{f:b},3],m:n}", false, 2, true), + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,{f:b},3],m:n}", false, 2, true), "{\n" " 'k' : 'v',\n" " 'a' : 'b',\n" @@ -69,7 +69,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " ],\n" " 'm' : 'n'\n" "}"); - + NJson::TJsonPrettifier prettifierMaxLevel1 = NJson::TJsonPrettifier::Prettifier(false, 2, true); prettifierMaxLevel1.MaxPaddingLevel = 1; UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel1.Prettify("{k:v,a:b,x:[1,{f:b},3],m:n}"), @@ -79,8 +79,8 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " 'x' : [ 1, { 'f' : 'b' }, 3 ],\n" " 'm' : 'n'\n" "}"); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}", true, 2), + + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}", true, 2), "{\n" " g : {\n" " x : {\n" @@ -108,8 +108,8 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " y : fff\n" " }\n" "}"); - } - + } + Y_UNIT_TEST(PrettifyJsonInvalid) { UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}"), ""); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}}"), ""); @@ -124,26 +124,26 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { } Y_UNIT_TEST(CompactifyJsonShort) { - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson(""), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("null"), "null"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("true"), "true"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("false"), "false"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("1.5"), "1.5"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("test", true), "test"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("test", false), "\"test\""); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[ ]"), "[]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n \"a\"\n]", true), "[a]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n 'a',\n 'b'\n]", true), "[a,b]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n { },\n 'b'\n]", true), "[{},b]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n 'a',\n { }\n]", true), "[a,{}]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n { },\n { }\n]", true), "[{},{}]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{ }"), "{}"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{\n 'k' : 'v'\n}", true), "{k:v}"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson(""), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("null"), "null"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("true"), "true"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("false"), "false"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("1.5"), "1.5"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("test", true), "test"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("test", false), "\"test\""); + + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[ ]"), "[]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n \"a\"\n]", true), "[a]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n 'a',\n 'b'\n]", true), "[a,b]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n { },\n 'b'\n]", true), "[{},b]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n 'a',\n { }\n]", true), "[a,{}]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n { },\n { }\n]", true), "[{},{}]"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{ }"), "{}"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{\n 'k' : 'v'\n}", true), "{k:v}"); } Y_UNIT_TEST(CompactifyJsonLong) { - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( "[\n" " {\n" " 'k' : 'v'\n" @@ -166,8 +166,8 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { "}", true), "{k:v,a:b,x:[1,2,3]}"); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( + + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( "{\n" " 'k' : 'v',\n" " 'a' : 'b',\n" @@ -182,8 +182,8 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { "}", true), "{k:v,a:b,x:[1,{f:b},3],m:n}"); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( + + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( "{\n" " g : {\n" " x : {\n" @@ -200,5 +200,5 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { "}", true), "{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"); - } + } } diff --git a/library/cpp/json/ut/json_reader_fast_ut.cpp b/library/cpp/json/ut/json_reader_fast_ut.cpp index 60dffc91c7..bc1a84b3a6 100644 --- a/library/cpp/json/ut/json_reader_fast_ut.cpp +++ b/library/cpp/json/ut/json_reader_fast_ut.cpp @@ -1,12 +1,12 @@ #include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_prettifier.h> #include <library/cpp/testing/unittest/registar.h> - + #include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h> #include <util/string/cast.h> -#include <util/string/printf.h> - -namespace NJson { +#include <util/string/printf.h> + +namespace NJson { namespace NTest { enum ETestEvent { E_NO_EVENT = 0, @@ -23,37 +23,37 @@ namespace NJson { E_STR, E_KEY }; - + struct TEvent { ETestEvent Type = E_NO_EVENT; - + i64 INum = 0; double DNum = 0; TString Str; - + TEvent(ETestEvent e = E_NO_EVENT) : Type(e) { } - + TEvent(double v, ETestEvent e) : Type(e) , DNum(v) { } - + TEvent(i64 v, ETestEvent e) : Type(e) , INum(v) { } - + TEvent(TStringBuf t, ETestEvent e) : Type(e) , Str(NEscJ::EscapeJ<true, false>(t)) { } - + TString ToString() const { switch (Type) { default: @@ -83,74 +83,74 @@ namespace NJson { } } }; - + using TEvents = TVector<TEvent>; - + struct TTestHandler : TJsonCallbacks { TEvents Events; - + bool OnOpenMap() override { Events.push_back(E_DICT_OPEN); return true; } - + bool OnCloseMap() override { Events.push_back(E_DICT_CLOSE); return true; } - + bool OnOpenArray() override { Events.push_back(E_ARR_OPEN); return true; } - + bool OnCloseArray() override { Events.push_back(E_ARR_CLOSE); return true; } - + bool OnNull() override { Events.push_back(E_NULL); return true; } - + bool OnBoolean(bool v) override { Events.push_back(TEvent((i64)v, E_BOOL)); return true; } - + bool OnInteger(long long v) override { Events.push_back(TEvent((i64)v, E_INT)); return true; } - + bool OnUInteger(unsigned long long v) override { return OnInteger(v); } - + bool OnDouble(double v) override { Events.push_back(TEvent(v, E_FLT)); return true; } - + bool OnString(const TStringBuf& v) override { Events.push_back(TEvent(v, E_STR)); return true; } - + bool OnMapKey(const TStringBuf& v) override { Events.push_back(TEvent(v, E_KEY)); return true; } - + void OnError(size_t, TStringBuf token) override { Events.push_back(TEvent(token, E_ERROR)); } - + void Assert(const TEvents& e, TString str) { try { UNIT_ASSERT_VALUES_EQUAL_C(e.size(), Events.size(), str); - + for (ui32 i = 0, sz = e.size(); i < sz; ++i) { UNIT_ASSERT_VALUES_EQUAL_C((int)e[i].Type, (int)Events[i].Type, Sprintf("'%s' %u", str.data(), i)); UNIT_ASSERT_VALUES_EQUAL_C(e[i].INum, Events[i].INum, Sprintf("'%s' %u", str.data(), i)); @@ -162,32 +162,32 @@ namespace NJson { for (const auto& event : Events) { Clog << event.ToString() << Endl; } - + throw; } - } + } }; - } -} - + } +} + class TFastJsonTest: public TTestBase { UNIT_TEST_SUITE(TFastJsonTest) - UNIT_TEST(TestParse) + UNIT_TEST(TestParse) UNIT_TEST(TestReadJsonFastTree) - UNIT_TEST(TestNoInlineComment) + UNIT_TEST(TestNoInlineComment) UNIT_TEST_SUITE_END(); -public: - template <bool accept> - void DoTestParse(TStringBuf json, ui32 amount, ...) { - using namespace NJson::NTest; - TEvents evs; - va_list vl; - va_start(vl, amount); - for (ui32 i = 0; i < amount; i++) { - ETestEvent e = (ETestEvent)va_arg(vl, int); - - switch ((int)e) { +public: + template <bool accept> + void DoTestParse(TStringBuf json, ui32 amount, ...) { + using namespace NJson::NTest; + TEvents evs; + va_list vl; + va_start(vl, amount); + for (ui32 i = 0; i < amount; i++) { + ETestEvent e = (ETestEvent)va_arg(vl, int); + + switch ((int)e) { case E_NO_EVENT: case E_DICT_OPEN: case E_DICT_CLOSE: @@ -227,40 +227,40 @@ public: evs.push_back(TEvent(TStringBuf(s), e)); break; } - } - } - va_end(vl); - - TTestHandler h; + } + } + va_end(vl); + + TTestHandler h; const bool res = ReadJsonFast(json, &h); UNIT_ASSERT_VALUES_EQUAL_C(res, accept, Sprintf("%s (%s)", ToString(json).data(), h.Events.back().Str.data())); h.Assert(evs, ToString(json)); - } - - void TestParse() { - using namespace NJson::NTest; - - DoTestParse<true>("", 0); - DoTestParse<true>(" \t \t ", 0); - DoTestParse<true>("a-b-c@аб_вгд909AБ", 1, E_STR, "a-b-c@аб_вгд909AБ"); - DoTestParse<true>("'я тестовая строка'", 1, E_STR, "я тестовая строка"); - DoTestParse<true>("\"я тестовая строка\"", 1, E_STR, "я тестовая строка"); - DoTestParse<true>("'\\xA\\xA\\xA'", 1, E_STR, "\n\n\n"); - DoTestParse<true>("12.15", 1, E_FLT, 12.15); - DoTestParse<true>("null", 1, E_NULL); - DoTestParse<true>("true", 1, E_BOOL, true); - DoTestParse<true>("false", 1, E_BOOL, false); - DoTestParse<true>("[]", 2, E_ARR_OPEN, E_ARR_CLOSE); - DoTestParse<true>("[ a ]", 3, E_ARR_OPEN, E_STR, "a", E_ARR_CLOSE); - DoTestParse<true>("[ a, b ]", 4, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE); - DoTestParse<true>("[a,b]", 4, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE); - DoTestParse<false>("[a,b][a,b]", 5, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE, E_ERROR, "invalid syntax at token: '['"); - DoTestParse<false>("[a,,b]", 3, E_ARR_OPEN, E_STR, "a", E_ERROR, "invalid syntax at token: ','"); - DoTestParse<true>("{ k : v }", 4, E_DICT_OPEN, E_KEY, "k", E_STR, "v", E_DICT_CLOSE); - DoTestParse<true>("{a:'\\b'/*comment*/, k /*comment*/\n : v }", 6, E_DICT_OPEN, E_KEY, "a", E_STR, "\b", E_KEY, "k", E_STR, "v", E_DICT_CLOSE); + } + + void TestParse() { + using namespace NJson::NTest; + + DoTestParse<true>("", 0); + DoTestParse<true>(" \t \t ", 0); + DoTestParse<true>("a-b-c@аб_вгд909AБ", 1, E_STR, "a-b-c@аб_вгд909AБ"); + DoTestParse<true>("'я тестовая строка'", 1, E_STR, "я тестовая строка"); + DoTestParse<true>("\"я тестовая строка\"", 1, E_STR, "я тестовая строка"); + DoTestParse<true>("'\\xA\\xA\\xA'", 1, E_STR, "\n\n\n"); + DoTestParse<true>("12.15", 1, E_FLT, 12.15); + DoTestParse<true>("null", 1, E_NULL); + DoTestParse<true>("true", 1, E_BOOL, true); + DoTestParse<true>("false", 1, E_BOOL, false); + DoTestParse<true>("[]", 2, E_ARR_OPEN, E_ARR_CLOSE); + DoTestParse<true>("[ a ]", 3, E_ARR_OPEN, E_STR, "a", E_ARR_CLOSE); + DoTestParse<true>("[ a, b ]", 4, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE); + DoTestParse<true>("[a,b]", 4, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE); + DoTestParse<false>("[a,b][a,b]", 5, E_ARR_OPEN, E_STR, "a", E_STR, "b", E_ARR_CLOSE, E_ERROR, "invalid syntax at token: '['"); + DoTestParse<false>("[a,,b]", 3, E_ARR_OPEN, E_STR, "a", E_ERROR, "invalid syntax at token: ','"); + DoTestParse<true>("{ k : v }", 4, E_DICT_OPEN, E_KEY, "k", E_STR, "v", E_DICT_CLOSE); + DoTestParse<true>("{a:'\\b'/*comment*/, k /*comment*/\n : v }", 6, E_DICT_OPEN, E_KEY, "a", E_STR, "\b", E_KEY, "k", E_STR, "v", E_DICT_CLOSE); DoTestParse<true>("{a:.15, k : v }", 6, E_DICT_OPEN, E_KEY, "a", E_FLT, .15, E_KEY, "k", E_STR, "v", E_DICT_CLOSE); DoTestParse<true>("[ a, -.1e+5, 1E-7]", 5, E_ARR_OPEN, E_STR, "a", E_FLT, -.1e+5, E_FLT, 1e-7, E_ARR_CLOSE); - DoTestParse<true>("{}", 2, E_DICT_OPEN, E_DICT_CLOSE); + DoTestParse<true>("{}", 2, E_DICT_OPEN, E_DICT_CLOSE); DoTestParse<true>("{ a : x, b : [ c, d, ] }", 9, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ARR_CLOSE, E_DICT_CLOSE); DoTestParse<false>("{ a : x, b : [ c, d,, ] }", 8, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ERROR, "invalid syntax at token: ','"); // DoTestParse<false>("{ a : x : y }", 4, E_DICT_OPEN @@ -271,14 +271,14 @@ public: // , E_KEY, "queries", E_DICT_OPEN // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE // , E_DICT_CLOSE, E_ERROR, ""); - DoTestParse<true>("'100x00'", 1, E_STR, "100x00"); - DoTestParse<true>("-1", 1, E_INT, -1); - DoTestParse<true>("-9223372036854775808", 1, E_LONG_LONG, (long long)Min<i64>()); - DoTestParse<false>("100x00", 1, E_ERROR, "invalid syntax at token: '100x'"); - DoTestParse<false>("100 200", 2, E_INT, 100, E_ERROR, "invalid syntax at token: '200'"); + DoTestParse<true>("'100x00'", 1, E_STR, "100x00"); + DoTestParse<true>("-1", 1, E_INT, -1); + DoTestParse<true>("-9223372036854775808", 1, E_LONG_LONG, (long long)Min<i64>()); + DoTestParse<false>("100x00", 1, E_ERROR, "invalid syntax at token: '100x'"); + DoTestParse<false>("100 200", 2, E_INT, 100, E_ERROR, "invalid syntax at token: '200'"); DoTestParse<true>("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}", 22, E_DICT_OPEN, E_KEY, "g", E_DICT_OPEN, E_KEY, "x", E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_KEY, "b", E_STR, "c", E_KEY, "e", E_STR, "f", E_DICT_CLOSE, E_KEY, "q", E_DICT_OPEN, E_KEY, "x", E_STR, "y", E_DICT_CLOSE, E_DICT_CLOSE, E_KEY, "y", E_STR, "fff", E_DICT_CLOSE, E_DICT_CLOSE); - } - + } + void TestReadJsonFastTree() { const TString json = R"( { @@ -290,15 +290,15 @@ public: NJson::TJsonValue value; UNIT_ASSERT(!ReadJsonFastTree(json, &value)); } - - void TestNoInlineComment() { - using namespace NJson::NTest; - DoTestParse<false>("{\"a\":1}//d{\"b\":2}", 5, E_DICT_OPEN, E_KEY, "a", E_INT, 1, E_DICT_CLOSE, E_ERROR, "invalid syntax at token: '/'"); - DoTestParse<false>("{\"a\":1}//d{\"b\":2}\n", 5, E_DICT_OPEN, E_KEY, "a", E_INT, 1, E_DICT_CLOSE, E_ERROR, "invalid syntax at token: '/'"); - DoTestParse<false>("{\"a\":{//d{\"b\":2}\n}}", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); - DoTestParse<false>("{\"a\":{//d{\"b\":2}}}\n", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); - DoTestParse<false>("{\"a\":{//d{\"b\":2}}}", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); - } -}; - -UNIT_TEST_SUITE_REGISTRATION(TFastJsonTest) + + void TestNoInlineComment() { + using namespace NJson::NTest; + DoTestParse<false>("{\"a\":1}//d{\"b\":2}", 5, E_DICT_OPEN, E_KEY, "a", E_INT, 1, E_DICT_CLOSE, E_ERROR, "invalid syntax at token: '/'"); + DoTestParse<false>("{\"a\":1}//d{\"b\":2}\n", 5, E_DICT_OPEN, E_KEY, "a", E_INT, 1, E_DICT_CLOSE, E_ERROR, "invalid syntax at token: '/'"); + DoTestParse<false>("{\"a\":{//d{\"b\":2}\n}}", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); + DoTestParse<false>("{\"a\":{//d{\"b\":2}}}\n", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); + DoTestParse<false>("{\"a\":{//d{\"b\":2}}}", 4, E_DICT_OPEN, E_KEY, "a", E_DICT_OPEN, E_ERROR, "invalid syntax at token: '/'"); + } +}; + +UNIT_TEST_SUITE_REGISTRATION(TFastJsonTest) diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp index cd31afa0b8..92435e52a4 100644 --- a/library/cpp/json/ut/json_reader_ut.cpp +++ b/library/cpp/json/ut/json_reader_ut.cpp @@ -230,7 +230,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT(value.Has("test")); UNIT_ASSERT(!value["test"].IsInteger()); UNIT_ASSERT(value["test"].IsUInteger()); - UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), (i64)(Max<i64>() + 1ull)); + UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), (i64)(Max<i64>() + 1ull)); } // Max<i64>() + 1 } diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp index ca11d34dad..9bbd4e3f77 100644 --- a/library/cpp/json/ut/json_writer_ut.cpp +++ b/library/cpp/json/ut/json_writer_ut.cpp @@ -11,48 +11,48 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) { TString expected2 = expected1 + ",\"array\":[\"stroka\",false]"; TString expected3 = expected2 + "}"; - TStringStream out; + TStringStream out; - TJsonWriter json(&out, false); - json.OpenMap(); - json.Write("key1", (ui16)1); + TJsonWriter json(&out, false); + json.OpenMap(); + json.Write("key1", (ui16)1); json.WriteKey("key2"); json.Write((i32)2); - json.Write("key3", (ui64)3); + json.Write("key3", (ui64)3); UNIT_ASSERT(out.Empty()); - json.Flush(); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); + json.Flush(); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); - json.Write("array"); - json.OpenArray(); - json.Write("stroka"); - json.Write(false); - json.CloseArray(); + json.Write("array"); + json.OpenArray(); + json.Write("stroka"); + json.Write(false); + json.CloseArray(); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); - json.Flush(); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected1); + json.Flush(); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); - json.CloseMap(); + json.CloseMap(); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); - json.Flush(); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected3); - } + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected2); + json.Flush(); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected3); + } Y_UNIT_TEST(SimpleWriteValueTest) { TString expected = "{\"key1\":null,\"key2\":{\"subkey1\":[1,{\"subsubkey\":\"test2\"},null,true],\"subkey2\":\"test\"}}"; - TJsonValue v; - v["key1"] = JSON_NULL; - v["key2"]["subkey1"].AppendValue(1); - v["key2"]["subkey1"].AppendValue(JSON_MAP)["subsubkey"] = "test2"; - v["key2"]["subkey1"].AppendValue(JSON_NULL); - v["key2"]["subkey1"].AppendValue(true); - v["key2"]["subkey2"] = "test"; - TStringStream out; - WriteJson(&out, &v); - UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected); + TJsonValue v; + v["key1"] = JSON_NULL; + v["key2"]["subkey1"].AppendValue(1); + v["key2"]["subkey1"].AppendValue(JSON_MAP)["subsubkey"] = "test2"; + v["key2"]["subkey1"].AppendValue(JSON_NULL); + v["key2"]["subkey1"].AppendValue(true); + v["key2"]["subkey2"] = "test"; + TStringStream out; + WriteJson(&out, &v); + UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected); } Y_UNIT_TEST(FormatOutput) { |