aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/mkql_string_util_ut.cpp
blob: 9826ee0ee1029ea424bcc45d320294be82fe634b (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "mkql_alloc.h"
#include "mkql_string_util.h"

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

using namespace NYql;
using namespace NKikimr::NMiniKQL;

Y_UNIT_TEST_SUITE(TMiniKQLStringUtils) {
    Y_UNIT_TEST(SubstringWithLargeOffset) {
        TScopedAlloc alloc(__LOCATION__);
        const auto big = MakeStringNotFilled(NUdf::TUnboxedValuePod::OffsetLimit << 1U);
        const auto sub0 = SubString(big, 1U, 42U);
        const auto sub1 = SubString(big, NUdf::TUnboxedValuePod::OffsetLimit - 1U, 42U);
        const auto sub2 = SubString(big, NUdf::TUnboxedValuePod::OffsetLimit, 42U);

        UNIT_ASSERT(sub0.AsStringValue().Data() == sub1.AsStringValue().Data());
        UNIT_ASSERT(sub1.AsStringValue().Data() != sub2.AsStringValue().Data());
    }

    Y_UNIT_TEST(MakeStringWithPad) {
        TScopedAlloc alloc(__LOCATION__);

        {
            const auto buf= MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize - 1U, 1U);
            UNIT_ASSERT(buf.IsEmbedded());
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize - 1U);
        }

        {
            const auto buf= MakeStringNotFilled(NUdf::TUnboxedValuePod::InternalBufferSize, 1U);
            UNIT_ASSERT(buf.IsString());
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), NUdf::TUnboxedValuePod::InternalBufferSize);
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringValue().Size(), NUdf::TUnboxedValuePod::InternalBufferSize + 1U);
        }
    }

    Y_UNIT_TEST(MakeLargeString) {
        TScopedAlloc alloc(__LOCATION__);

        {
            const auto buf= MakeStringNotFilled(0xFFFFFFFFU);
            UNIT_ASSERT(buf.IsString());
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFFFU);
            const auto& value = buf.AsStringValue();
            UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFFFU);
            UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
        }

        {
            const auto buf= MakeStringNotFilled(0xFFFFFFF1U);
            UNIT_ASSERT(buf.IsString());
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF1U);
            const auto& value = buf.AsStringValue();
            UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF1U);
            UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0x100000000ULL);
        }

        {
            const auto buf= MakeStringNotFilled(0xFFFFFFF0U);
            UNIT_ASSERT(buf.IsString());
            UNIT_ASSERT_VALUES_EQUAL(buf.AsStringRef().Size(), 0xFFFFFFF0U);
            const auto& value = buf.AsStringValue();
            UNIT_ASSERT_VALUES_EQUAL(value.Size(), 0xFFFFFFF0U);
            UNIT_ASSERT_VALUES_EQUAL(value.Capacity(), 0xFFFFFFF0ULL);
        }
    }

    Y_UNIT_TEST(ConcatLargeString) {
        TScopedAlloc alloc(__LOCATION__);

        const NUdf::TUnboxedValue buf = MakeStringNotFilled(0x80000000U);
        try {
            ConcatStrings(buf, buf);
            UNIT_FAIL("No exception!");
        } catch (const yexception&) {}

        try {
            PrependString(buf.AsStringRef(), buf);
            UNIT_FAIL("No exception!");
        } catch (const yexception&) {}

        try {
            AppendString(buf, buf.AsStringRef());
            UNIT_FAIL("No exception!");
        } catch (const yexception&) {}
    }
}