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/scheme/ut_utils | |
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/scheme/ut_utils')
-rw-r--r-- | library/cpp/scheme/ut_utils/scheme_ut_utils.cpp | 70 | ||||
-rw-r--r-- | library/cpp/scheme/ut_utils/scheme_ut_utils.h | 68 | ||||
-rw-r--r-- | library/cpp/scheme/ut_utils/ya.make | 24 |
3 files changed, 81 insertions, 81 deletions
diff --git a/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp index 0bbdab10e8..b520eceab5 100644 --- a/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp +++ b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp @@ -1,44 +1,44 @@ -#include "scheme_ut_utils.h" - +#include "scheme_ut_utils.h" + #include <library/cpp/colorizer/colors.h> - -#include <util/stream/str.h> - -namespace NSc { - namespace NUt { - NSc::TValue AssertFromJson(TStringBuf val) { - try { - return TValue::FromJsonThrow(val); - } catch (const TSchemeParseException& e) { - TStringStream s; - NColorizer::TColors colors; + +#include <util/stream/str.h> + +namespace NSc { + namespace NUt { + NSc::TValue AssertFromJson(TStringBuf val) { + try { + return TValue::FromJsonThrow(val); + } catch (const TSchemeParseException& e) { + TStringStream s; + NColorizer::TColors colors; s << "\n" << colors.YellowColor() << "Reason:" << colors.OldColor() << "\n" << e.Reason; s << "\n" << colors.YellowColor() << "Where:" << colors.OldColor() << "\n" << val.SubStr(0, e.Offset) << colors.RedColor() << val.SubStr(e.Offset) << colors.OldColor() << "\n"; - UNIT_FAIL_IMPL("could not parse json", s.Str()); - return NSc::Null(); - } catch (const yexception& e) { - TStringStream s; + UNIT_FAIL_IMPL("could not parse json", s.Str()); + return NSc::Null(); + } catch (const yexception& e) { + TStringStream s; s << '\n' << val; - UNIT_FAIL_IMPL("could not parse json", s.Str()); - return NSc::Null(); - } - } - - void AssertScheme(const TValue& expected, const TValue& actual) { - UNIT_ASSERT_JSON_EQ_JSON(actual, expected); - } - - void AssertSchemeJson(TStringBuf expected, const NSc::TValue& actual) { - UNIT_ASSERT_JSON_EQ_JSON(actual, expected); - } - - void AssertJsonJson(TStringBuf expected, TStringBuf actual) { - UNIT_ASSERT_JSON_EQ_JSON(actual, expected); - } - } -} + UNIT_FAIL_IMPL("could not parse json", s.Str()); + return NSc::Null(); + } + } + + void AssertScheme(const TValue& expected, const TValue& actual) { + UNIT_ASSERT_JSON_EQ_JSON(actual, expected); + } + + void AssertSchemeJson(TStringBuf expected, const NSc::TValue& actual) { + UNIT_ASSERT_JSON_EQ_JSON(actual, expected); + } + + void AssertJsonJson(TStringBuf expected, TStringBuf actual) { + UNIT_ASSERT_JSON_EQ_JSON(actual, expected); + } + } +} diff --git a/library/cpp/scheme/ut_utils/scheme_ut_utils.h b/library/cpp/scheme/ut_utils/scheme_ut_utils.h index eb3ea15b2a..fe04641370 100644 --- a/library/cpp/scheme/ut_utils/scheme_ut_utils.h +++ b/library/cpp/scheme/ut_utils/scheme_ut_utils.h @@ -1,29 +1,29 @@ -#pragma once - +#pragma once + #include <library/cpp/json/json_prettifier.h> #include <library/cpp/scheme/scheme.h> #include <library/cpp/json/json_value.h> #include <library/cpp/json/json_writer.h> #include <library/cpp/testing/unittest/registar.h> #include <util/string/cast.h> - -namespace NSc { - namespace NUt { - TValue AssertFromJson(TStringBuf json); - + +namespace NSc { + namespace NUt { + TValue AssertFromJson(TStringBuf json); + inline TString NormalizeJson(const NSc::TValue& sc) { - return sc.ToJson(true); - } - + return sc.ToJson(true); + } + inline TString NormalizeJson(const NJson::TJsonValue& sc) { - return NJson::WriteJson(sc, false, true, false); - } - - template <class TStr> + return NJson::WriteJson(sc, false, true, false); + } + + template <class TStr> inline TString NormalizeJson(const TStr& val) { - return AssertFromJson(val).ToJson(true); - } - + return AssertFromJson(val).ToJson(true); + } + #define UNIT_ASSERT_JSON_EQ_JSON_C(A, B, c) \ do { \ const TString _a = NSc::NUt::NormalizeJson(A); \ @@ -34,22 +34,22 @@ namespace NSc { Sprintf("%s\n!=\n%s\n%s\n%s", _a.data(), _b.data(), \ ::NUnitTest::ColoredDiff(NJson::PrettifyJson(_a), NJson::PrettifyJson(_b), " \t\n,:\"{}[]").data(), ToString(c).data())); \ } \ - } while (false) - -#define UNIT_ASSERT_JSON_EQ_JSON(A, B) UNIT_ASSERT_JSON_EQ_JSON_C(A, B, "") - + } while (false) + +#define UNIT_ASSERT_JSON_EQ_JSON(A, B) UNIT_ASSERT_JSON_EQ_JSON_C(A, B, "") + inline TString DumpJson(const TValue& json) { - return NJson::CompactifyJson(json.ToJson(true), true, true); - } - - // deprecated + return NJson::CompactifyJson(json.ToJson(true), true, true); + } + + // deprecated inline TString DumpJsonVS(const TValue& expected, const TValue& fact) { - return DumpJson(expected) + "(expected) != (fact)" + DumpJson(fact); - } - - void AssertScheme(const TValue& expected, const TValue& real); - void AssertSchemeJson(TStringBuf expected, const TValue& real); - void AssertJsonJson(TStringBuf expected, TStringBuf real); - - } -} + return DumpJson(expected) + "(expected) != (fact)" + DumpJson(fact); + } + + void AssertScheme(const TValue& expected, const TValue& real); + void AssertSchemeJson(TStringBuf expected, const TValue& real); + void AssertJsonJson(TStringBuf expected, TStringBuf real); + + } +} diff --git a/library/cpp/scheme/ut_utils/ya.make b/library/cpp/scheme/ut_utils/ya.make index 7661262e1b..cfa7387a94 100644 --- a/library/cpp/scheme/ut_utils/ya.make +++ b/library/cpp/scheme/ut_utils/ya.make @@ -1,16 +1,16 @@ -LIBRARY() - -OWNER(velavokr) - -SRCS( - scheme_ut_utils.cpp -) - -PEERDIR( +LIBRARY() + +OWNER(velavokr) + +SRCS( + scheme_ut_utils.cpp +) + +PEERDIR( library/cpp/colorizer library/cpp/json library/cpp/scheme library/cpp/testing/unittest -) - -END() +) + +END() |