aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/walk_ut.cpp
blob: 30a0c7c59e7234047c0c147b2c40ac9d68846a69 (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
#include "walk.h"

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

class TStringListInput: public IWalkInput {
public:
    TStringListInput(const TVector<TString>& data)
        : Data_(data)
        , Index_(0)
    {
    }

protected:
    size_t DoUnboundedNext(const void** ptr) override {
        if (Index_ >= Data_.size()) {
            return 0;
        }

        const TString& string = Data_[Index_++];

        *ptr = string.data();
        return string.size();
    }

private:
    const TVector<TString>& Data_;
    size_t Index_;
};

Y_UNIT_TEST_SUITE(TWalkTest) {
    Y_UNIT_TEST(ReadTo) {
        TVector<TString> data;
        data.push_back("111a");
        data.push_back("222b");
        data.push_back("333c");
        data.push_back("444d");
        data.push_back("555e");
        data.push_back("666f");

        TStringListInput input(data);

        TString tmp1 = input.ReadTo('c');
        UNIT_ASSERT_VALUES_EQUAL(tmp1, "111a222b333");

        char tmp2;
        input.Read(&tmp2, 1);
        UNIT_ASSERT_VALUES_EQUAL(tmp2, '4');

        TString tmp3 = input.ReadTo('6');
        UNIT_ASSERT_VALUES_EQUAL(tmp3, "44d555e");

        TString tmp4 = input.ReadAll();
        UNIT_ASSERT_VALUES_EQUAL(tmp4, "66f");
    }
}