aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp/scheme/ut_utils/scheme_ut_utils.cpp')
-rw-r--r--library/cpp/scheme/ut_utils/scheme_ut_utils.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp
new file mode 100644
index 0000000000..0bbdab10e8
--- /dev/null
+++ b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp
@@ -0,0 +1,44 @@
+#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;
+ 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;
+ 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);
+ }
+ }
+}