aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/node/node_io_ut.cpp
blob: 90720cd3a1b325e0391301c68eedeff259074d2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "node_io.h"

#include <library/cpp/testing/unittest/registar.h>

#include <util/stream/mem.h>

using namespace NYson;

namespace {
    void GenerateDeepJson(TStringStream& stream, ui64 depth) {
        stream << "{\"key\":";
        for (ui32 i = 0; i < depth - 1; ++i) {
            stream << "[";
        }
        for (ui32 i = 0; i < depth - 1; ++i) {
            stream << "]";
        }
        stream << "}";
    }
}

Y_UNIT_TEST_SUITE(TestNodeFromJsonStringIterativeTest) {
    Y_UNIT_TEST(NoCrashOn1e5Brackets) {
        constexpr ui32 brackets = static_cast<ui32>(1e5);

        TStringStream jsonStream;
        GenerateDeepJson(jsonStream, brackets);

        UNIT_ASSERT_EXCEPTION(
            NYT::NodeFromJsonStringIterative(jsonStream.Str()),
            std::exception);
    }

    Y_UNIT_TEST(NoCrashOn1025Brackets) {
        constexpr ui32 brackets = 1025;

        TStringStream jsonStream;
        GenerateDeepJson(jsonStream, brackets);

        UNIT_ASSERT_EXCEPTION(
            NYT::NodeFromJsonStringIterative(jsonStream.Str()),
            std::exception);
    }

    Y_UNIT_TEST(NoErrorOn1024Brackets) {
        constexpr ui32 brackets = 1024;

        TStringStream jsonStream;
        GenerateDeepJson(jsonStream, brackets);

        UNIT_ASSERT_NO_EXCEPTION(NYT::NodeFromJsonStringIterative(jsonStream.Str()));
    }
}