diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/json/ut | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json/ut')
-rw-r--r-- | library/cpp/json/ut/json_prettifier_ut.cpp | 218 | ||||
-rw-r--r-- | library/cpp/json/ut/json_reader_fast_ut.cpp | 416 | ||||
-rw-r--r-- | library/cpp/json/ut/json_reader_ut.cpp | 80 | ||||
-rw-r--r-- | library/cpp/json/ut/json_writer_ut.cpp | 4 | ||||
-rw-r--r-- | library/cpp/json/ut/ya.make | 6 |
5 files changed, 362 insertions, 362 deletions
diff --git a/library/cpp/json/ut/json_prettifier_ut.cpp b/library/cpp/json/ut/json_prettifier_ut.cpp index e2b51be062..ae5f8dd81a 100644 --- a/library/cpp/json/ut/json_prettifier_ut.cpp +++ b/library/cpp/json/ut/json_prettifier_ut.cpp @@ -36,78 +36,78 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { Y_UNIT_TEST(PrettifyJsonLong) { UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{k:v},{a:b}]", false, 2, true), - "[\n" - " {\n" - " 'k' : 'v'\n" - " },\n" - " {\n" - " 'a' : 'b'\n" - " }\n" - "]"); + "[\n" + " {\n" + " 'k' : 'v'\n" + " },\n" + " {\n" + " 'a' : 'b'\n" + " }\n" + "]"); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,2,3]}", false, 2, true), - "{\n" - " 'k' : 'v',\n" - " 'a' : 'b',\n" - " 'x' : [\n" - " 1,\n" - " 2,\n" - " 3\n" - " ]\n" - "}"); + "{\n" + " 'k' : 'v',\n" + " 'a' : 'b',\n" + " 'x' : [\n" + " 1,\n" + " 2,\n" + " 3\n" + " ]\n" + "}"); 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" - " 'x' : [\n" - " 1,\n" - " {\n" - " 'f' : 'b'\n" - " },\n" - " 3\n" - " ],\n" - " 'm' : 'n'\n" - "}"); + "{\n" + " 'k' : 'v',\n" + " 'a' : 'b',\n" + " 'x' : [\n" + " 1,\n" + " {\n" + " 'f' : 'b'\n" + " },\n" + " 3\n" + " ],\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}"), - "{\n" - " 'k' : 'v',\n" - " 'a' : 'b',\n" - " 'x' : [ 1, { 'f' : 'b' }, 3 ],\n" - " 'm' : 'n'\n" - "}"); + "{\n" + " 'k' : 'v',\n" + " 'a' : 'b',\n" + " '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), - "{\n" - " g : {\n" - " x : {\n" - " a : {\n" - " b : c,\n" - " e : f\n" - " },\n" - " q : {\n" - " x : y\n" - " }\n" - " },\n" - " y : fff\n" - " }\n" - "}"); + "{\n" + " g : {\n" + " x : {\n" + " a : {\n" + " b : c,\n" + " e : f\n" + " },\n" + " q : {\n" + " x : y\n" + " }\n" + " },\n" + " y : fff\n" + " }\n" + "}"); NJson::TJsonPrettifier prettifierMaxLevel3 = NJson::TJsonPrettifier::Prettifier(true, 2); prettifierMaxLevel3.MaxPaddingLevel = 3; UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel3.Prettify("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"), - "{\n" - " g : {\n" - " x : {\n" - " a : { b : c, e : f },\n" - " q : { x : y }\n" - " },\n" - " y : fff\n" - " }\n" - "}"); + "{\n" + " g : {\n" + " x : {\n" + " a : { b : c, e : f },\n" + " q : { x : y }\n" + " },\n" + " y : fff\n" + " }\n" + "}"); } Y_UNIT_TEST(PrettifyJsonInvalid) { @@ -144,61 +144,61 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { Y_UNIT_TEST(CompactifyJsonLong) { UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( - "[\n" - " {\n" - " 'k' : 'v'\n" - " },\n" - " {\n" - " 'a' : 'b'\n" - " }\n" - "]", - true), - "[{k:v},{a:b}]"); + "[\n" + " {\n" + " 'k' : 'v'\n" + " },\n" + " {\n" + " 'a' : 'b'\n" + " }\n" + "]", + true), + "[{k:v},{a:b}]"); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( - "{\n" - " 'k' : 'v',\n" - " 'a' : 'b',\n" - " 'x' : [\n" - " 1,\n" - " 2,\n" - " 3\n" - " ]\n" - "}", - true), - "{k:v,a:b,x:[1,2,3]}"); + "{\n" + " 'k' : 'v',\n" + " 'a' : 'b',\n" + " 'x' : [\n" + " 1,\n" + " 2,\n" + " 3\n" + " ]\n" + "}", + true), + "{k:v,a:b,x:[1,2,3]}"); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( - "{\n" - " 'k' : 'v',\n" - " 'a' : 'b',\n" - " 'x' : [\n" - " 1,\n" - " {\n" - " 'f' : 'b'\n" - " },\n" - " 3\n" - " ],\n" - " 'm' : 'n'\n" - "}", - true), - "{k:v,a:b,x:[1,{f:b},3],m:n}"); + "{\n" + " 'k' : 'v',\n" + " 'a' : 'b',\n" + " 'x' : [\n" + " 1,\n" + " {\n" + " 'f' : 'b'\n" + " },\n" + " 3\n" + " ],\n" + " 'm' : 'n'\n" + "}", + true), + "{k:v,a:b,x:[1,{f:b},3],m:n}"); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( - "{\n" - " g : {\n" - " x : {\n" - " a : {\n" - " b : c,\n" - " e : f\n" - " },\n" - " q : {\n" - " x : y\n" - " }\n" - " },\n" - " y : fff\n" - " }\n" - "}", - true), - "{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"); + "{\n" + " g : {\n" + " x : {\n" + " a : {\n" + " b : c,\n" + " e : f\n" + " },\n" + " q : {\n" + " x : y\n" + " }\n" + " },\n" + " y : fff\n" + " }\n" + "}", + 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 4670975356..60dffc91c7 100644 --- a/library/cpp/json/ut/json_reader_fast_ut.cpp +++ b/library/cpp/json/ut/json_reader_fast_ut.cpp @@ -7,176 +7,176 @@ #include <util/string/printf.h> namespace NJson { - namespace NTest { - enum ETestEvent { - E_NO_EVENT = 0, - E_ERROR = 1, - E_DICT_OPEN, - E_DICT_CLOSE, - E_ARR_OPEN, - E_ARR_CLOSE, - E_NULL, - E_BOOL, - E_FLT, - E_INT, - E_LONG_LONG, - 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: - return "YOUFAILED"; - case E_ERROR: + namespace NTest { + enum ETestEvent { + E_NO_EVENT = 0, + E_ERROR = 1, + E_DICT_OPEN, + E_DICT_CLOSE, + E_ARR_OPEN, + E_ARR_CLOSE, + E_NULL, + E_BOOL, + E_FLT, + E_INT, + E_LONG_LONG, + 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: + return "YOUFAILED"; + case E_ERROR: return Sprintf("error: %s", Str.data()); - case E_DICT_OPEN: - return "{"; - case E_DICT_CLOSE: - return "}"; - case E_ARR_OPEN: - return "["; - case E_ARR_CLOSE: - return "]"; - case E_NULL: - return "null"; - case E_BOOL: - return INum ? "true" : "false"; - case E_INT: - return ::ToString(INum); - case E_FLT: - return ::ToString(DNum); - case E_STR: + case E_DICT_OPEN: + return "{"; + case E_DICT_CLOSE: + return "}"; + case E_ARR_OPEN: + return "["; + case E_ARR_CLOSE: + return "]"; + case E_NULL: + return "null"; + case E_BOOL: + return INum ? "true" : "false"; + case E_INT: + return ::ToString(INum); + case E_FLT: + return ::ToString(DNum); + case E_STR: return Sprintf("%s", Str.data()); - case E_KEY: + case E_KEY: return Sprintf("key: %s", Str.data()); - } - } - }; - - 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) { + } + } + }; + + 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)); UNIT_ASSERT_VALUES_EQUAL_C(e[i].DNum, Events[i].DNum, Sprintf("'%s' %u", str.data(), i)); UNIT_ASSERT_VALUES_EQUAL_C(e[i].Str, Events[i].Str, Sprintf("'%s' %u", str.data(), i)); - } - } catch (const yexception&) { - Clog << "Exception at '" << str << "'" << Endl; - for (const auto& event : Events) { - Clog << event.ToString() << Endl; - } - - throw; - } + } + } catch (const yexception&) { + Clog << "Exception at '" << str << "'" << Endl; + for (const auto& event : Events) { + Clog << event.ToString() << Endl; + } + + throw; + } } - }; + }; } } -class TFastJsonTest: public TTestBase { - UNIT_TEST_SUITE(TFastJsonTest) +class TFastJsonTest: public TTestBase { + UNIT_TEST_SUITE(TFastJsonTest) UNIT_TEST(TestParse) UNIT_TEST(TestReadJsonFastTree) UNIT_TEST(TestNoInlineComment) - UNIT_TEST_SUITE_END(); - + UNIT_TEST_SUITE_END(); + public: template <bool accept> void DoTestParse(TStringBuf json, ui32 amount, ...) { @@ -188,45 +188,45 @@ public: ETestEvent e = (ETestEvent)va_arg(vl, int); switch ((int)e) { - case E_NO_EVENT: - case E_DICT_OPEN: - case E_DICT_CLOSE: - case E_ARR_OPEN: - case E_ARR_CLOSE: - case E_NULL: - evs.push_back(e); - break; - case E_BOOL: { - bool v = va_arg(vl, int); - evs.push_back(TEvent((i64)v, E_BOOL)); - break; - } - case E_INT: { - i64 i = va_arg(vl, int); - evs.push_back(TEvent(i, E_INT)); - break; - } - case E_LONG_LONG: { - i64 i = va_arg(vl, long long); - evs.push_back(TEvent(i, E_INT)); - break; - } - case E_FLT: { - double f = va_arg(vl, double); - evs.push_back(TEvent(f, E_FLT)); - break; - } - case E_STR: { - const char* s = va_arg(vl, const char*); - evs.push_back(TEvent(TStringBuf(s), E_STR)); - break; - } - case E_KEY: - case E_ERROR: { - const char* s = va_arg(vl, const char*); - evs.push_back(TEvent(TStringBuf(s), e)); - break; - } + case E_NO_EVENT: + case E_DICT_OPEN: + case E_DICT_CLOSE: + case E_ARR_OPEN: + case E_ARR_CLOSE: + case E_NULL: + evs.push_back(e); + break; + case E_BOOL: { + bool v = va_arg(vl, int); + evs.push_back(TEvent((i64)v, E_BOOL)); + break; + } + case E_INT: { + i64 i = va_arg(vl, int); + evs.push_back(TEvent(i, E_INT)); + break; + } + case E_LONG_LONG: { + i64 i = va_arg(vl, long long); + evs.push_back(TEvent(i, E_INT)); + break; + } + case E_FLT: { + double f = va_arg(vl, double); + evs.push_back(TEvent(f, E_FLT)); + break; + } + case E_STR: { + const char* s = va_arg(vl, const char*); + evs.push_back(TEvent(TStringBuf(s), E_STR)); + break; + } + case E_KEY: + case E_ERROR: { + const char* s = va_arg(vl, const char*); + evs.push_back(TEvent(TStringBuf(s), e)); + break; + } } } va_end(vl); @@ -258,25 +258,25 @@ public: 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>("{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>("{ 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 - // , E_KEY, "a", E_STR, "x" - // , E_ERROR - // , ":"); - // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN - // , E_KEY, "queries", E_DICT_OPEN - // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE - // , E_DICT_CLOSE, E_ERROR, ""); + 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 + // , E_KEY, "a", E_STR, "x" + // , E_ERROR + // , ":"); + // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN + // , 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>("{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); + 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() { diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp index 958ed19730..cd31afa0b8 100644 --- a/library/cpp/json/ut/json_reader_ut.cpp +++ b/library/cpp/json/ut/json_reader_ut.cpp @@ -7,12 +7,12 @@ using namespace NJson; class TReformatCallbacks: public TJsonCallbacks { - TJsonWriter& Writer; - + TJsonWriter& Writer; + public: - TReformatCallbacks(TJsonWriter& writer) - : Writer(writer) - { + TReformatCallbacks(TJsonWriter& writer) + : Writer(writer) + { } bool OnBoolean(bool val) override { @@ -30,7 +30,7 @@ public: return true; } - bool OnString(const TStringBuf& val) override { + bool OnString(const TStringBuf& val) override { Writer.Write(val); return true; } @@ -60,7 +60,7 @@ public: return true; } - bool OnMapKey(const TStringBuf& val) override { + bool OnMapKey(const TStringBuf& val) override { Writer.Write(val); return true; } @@ -145,7 +145,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT_VALUES_EQUAL(value["array"].GetStringRobust(), "[1,2,3,\"TString\"]"); UNIT_ASSERT_VALUES_EQUAL(value["null value"].GetStringRobust(), "null"); - const TJsonValue::TArray* array; + const TJsonValue::TArray* array; UNIT_ASSERT(GetArrayPointer(value, "array", &array)); UNIT_ASSERT_VALUES_EQUAL(value["array"].GetArray().size(), array->size()); UNIT_ASSERT_VALUES_EQUAL(value["array"][0].GetInteger(), (*array)[0].GetInteger()); @@ -353,7 +353,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 0.0); UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), static_cast<double>(Max<ui64>())); } // Max<ui64>() - } // TJsonDoubleTest + } // TJsonDoubleTest Y_UNIT_TEST(TJsonInvalidTest) { { @@ -397,34 +397,34 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) { UNIT_ASSERT_VALUES_EQUAL("", v.GetMap().begin()->second.GetString()); } } - - -static const TString YANDEX_STREAMING_JSON("{\"a\":1}//d{\"b\":2}"); - - -Y_UNIT_TEST_SUITE(TCompareReadJsonFast) { - Y_UNIT_TEST(NoEndl) { - NJson::TJsonValue parsed; - - bool success = NJson::ReadJsonTree(YANDEX_STREAMING_JSON, &parsed, false); - bool fast_success = NJson::ReadJsonFastTree(YANDEX_STREAMING_JSON, &parsed, false); - UNIT_ASSERT(success == fast_success); - } - Y_UNIT_TEST(WithEndl) { - NJson::TJsonValue parsed1; - NJson::TJsonValue parsed2; - - bool success = NJson::ReadJsonTree(YANDEX_STREAMING_JSON + "\n", &parsed1, false); - bool fast_success = NJson::ReadJsonFastTree(YANDEX_STREAMING_JSON + "\n", &parsed2, false); - - UNIT_ASSERT_VALUES_EQUAL(success, fast_success); - } - Y_UNIT_TEST(NoQuotes) { - TString streamingJson = "{a:1}"; - NJson::TJsonValue parsed; - - bool success = NJson::ReadJsonTree(streamingJson, &parsed, false); - bool fast_success = NJson::ReadJsonFastTree(streamingJson, &parsed, false); - UNIT_ASSERT(success != fast_success); - } -} + + +static const TString YANDEX_STREAMING_JSON("{\"a\":1}//d{\"b\":2}"); + + +Y_UNIT_TEST_SUITE(TCompareReadJsonFast) { + Y_UNIT_TEST(NoEndl) { + NJson::TJsonValue parsed; + + bool success = NJson::ReadJsonTree(YANDEX_STREAMING_JSON, &parsed, false); + bool fast_success = NJson::ReadJsonFastTree(YANDEX_STREAMING_JSON, &parsed, false); + UNIT_ASSERT(success == fast_success); + } + Y_UNIT_TEST(WithEndl) { + NJson::TJsonValue parsed1; + NJson::TJsonValue parsed2; + + bool success = NJson::ReadJsonTree(YANDEX_STREAMING_JSON + "\n", &parsed1, false); + bool fast_success = NJson::ReadJsonFastTree(YANDEX_STREAMING_JSON + "\n", &parsed2, false); + + UNIT_ASSERT_VALUES_EQUAL(success, fast_success); + } + Y_UNIT_TEST(NoQuotes) { + TString streamingJson = "{a:1}"; + NJson::TJsonValue parsed; + + bool success = NJson::ReadJsonTree(streamingJson, &parsed, false); + bool fast_success = NJson::ReadJsonFastTree(streamingJson, &parsed, false); + UNIT_ASSERT(success != fast_success); + } +} diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp index 0fe747d704..ca11d34dad 100644 --- a/library/cpp/json/ut/json_writer_ut.cpp +++ b/library/cpp/json/ut/json_writer_ut.cpp @@ -8,7 +8,7 @@ using namespace NJson; Y_UNIT_TEST_SUITE(TJsonWriterTest) { Y_UNIT_TEST(SimpleWriteTest) { TString expected1 = "{\"key1\":1,\"key2\":2,\"key3\":3"; - TString expected2 = expected1 + ",\"array\":[\"stroka\",false]"; + TString expected2 = expected1 + ",\"array\":[\"stroka\",false]"; TString expected3 = expected2 + "}"; TStringStream out; @@ -120,7 +120,7 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) { WriteJson(&out, &v); UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected); } // 18446744073709551615 - } // SimpleUnsignedIntegerWriteTest + } // SimpleUnsignedIntegerWriteTest Y_UNIT_TEST(WriteOptionalTest) { { diff --git a/library/cpp/json/ut/ya.make b/library/cpp/json/ut/ya.make index 5f3a2d8510..8e0362d84b 100644 --- a/library/cpp/json/ut/ya.make +++ b/library/cpp/json/ut/ya.make @@ -2,10 +2,10 @@ OWNER(velavokr) UNITTEST_FOR(library/cpp/json) -PEERDIR( +PEERDIR( library/cpp/string_utils/relaxed_escaper -) - +) + SRCS( json_reader_fast_ut.cpp json_reader_ut.cpp |