node_io_ut.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "node_io.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/stream/mem.h>
  4. using namespace NYson;
  5. namespace {
  6. void GenerateDeepJson(TStringStream& stream, ui64 depth) {
  7. stream << "{\"key\":";
  8. for (ui32 i = 0; i < depth - 1; ++i) {
  9. stream << "[";
  10. }
  11. for (ui32 i = 0; i < depth - 1; ++i) {
  12. stream << "]";
  13. }
  14. stream << "}";
  15. }
  16. }
  17. Y_UNIT_TEST_SUITE(TestNodeFromJsonStringIterativeTest) {
  18. Y_UNIT_TEST(NoCrashOn1e5Brackets) {
  19. constexpr ui32 brackets = static_cast<ui32>(1e5);
  20. TStringStream jsonStream;
  21. GenerateDeepJson(jsonStream, brackets);
  22. UNIT_ASSERT_EXCEPTION(
  23. NYT::NodeFromJsonStringIterative(jsonStream.Str()),
  24. std::exception);
  25. }
  26. Y_UNIT_TEST(NoCrashOn1025Brackets) {
  27. constexpr ui32 brackets = 1025;
  28. TStringStream jsonStream;
  29. GenerateDeepJson(jsonStream, brackets);
  30. UNIT_ASSERT_EXCEPTION(
  31. NYT::NodeFromJsonStringIterative(jsonStream.Str()),
  32. std::exception);
  33. }
  34. Y_UNIT_TEST(NoErrorOn1024Brackets) {
  35. constexpr ui32 brackets = 1024;
  36. TStringStream jsonStream;
  37. GenerateDeepJson(jsonStream, brackets);
  38. UNIT_ASSERT_NO_EXCEPTION(NYT::NodeFromJsonStringIterative(jsonStream.Str()));
  39. }
  40. }