scheme_ut_utils.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "scheme_ut_utils.h"
  2. #include <library/cpp/colorizer/colors.h>
  3. #include <util/stream/str.h>
  4. namespace NSc {
  5. namespace NUt {
  6. NSc::TValue AssertFromJson(TStringBuf val) {
  7. try {
  8. return TValue::FromJsonThrow(val);
  9. } catch (const TSchemeParseException& e) {
  10. TStringStream s;
  11. NColorizer::TColors colors;
  12. s << "\n"
  13. << colors.YellowColor() << "Reason:" << colors.OldColor() << "\n"
  14. << e.Reason;
  15. s << "\n"
  16. << colors.YellowColor() << "Where:" << colors.OldColor() << "\n"
  17. << val.SubStr(0, e.Offset) << colors.RedColor() << val.SubStr(e.Offset) << colors.OldColor() << "\n";
  18. UNIT_FAIL_IMPL("could not parse json", s.Str());
  19. return NSc::Null();
  20. } catch (const yexception& e) {
  21. TStringStream s;
  22. s << '\n'
  23. << val;
  24. UNIT_FAIL_IMPL("could not parse json", s.Str());
  25. return NSc::Null();
  26. }
  27. }
  28. void AssertScheme(const TValue& expected, const TValue& actual) {
  29. UNIT_ASSERT_JSON_EQ_JSON(actual, expected);
  30. }
  31. void AssertSchemeJson(TStringBuf expected, const NSc::TValue& actual) {
  32. UNIT_ASSERT_JSON_EQ_JSON(actual, expected);
  33. }
  34. void AssertJsonJson(TStringBuf expected, TStringBuf actual) {
  35. UNIT_ASSERT_JSON_EQ_JSON(actual, expected);
  36. }
  37. }
  38. }