aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/case_insensitive_string/case_insensitive_string_ut.cpp
blob: 49f9c59c95b8a95c2ebb171357de62ab3aab41e9 (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
#include "case_insensitive_string.h"

#include <util/generic/string_ut.h>

class TCaseInsensitiveStringTest : public TTestBase, private TStringTestImpl<TCaseInsensitiveString, TTestData<char>> {
public:
    UNIT_TEST_SUITE(TCaseInsensitiveStringTest);
    UNIT_TEST(TestOperators);
    UNIT_TEST(TestOperatorsCI);

    UNIT_TEST_SUITE_END();
};

UNIT_TEST_SUITE_REGISTRATION(TCaseInsensitiveStringTest);

Y_UNIT_TEST_SUITE(TCaseInsensitiveStringTestEx) {
    Y_UNIT_TEST(BasicTString) {
        TCaseInsensitiveString foo("foo");
        TCaseInsensitiveString FOO("FOO");
        TCaseInsensitiveString Bar("Bar");
        TCaseInsensitiveString bAR("bAR");

        UNIT_ASSERT_EQUAL(foo, FOO);
        UNIT_ASSERT_EQUAL(Bar, bAR);

        constexpr TCaseInsensitiveStringBuf foobar("foobar");
        UNIT_ASSERT(foobar.StartsWith(foo));
        UNIT_ASSERT(foobar.StartsWith(FOO));
        UNIT_ASSERT(foobar.EndsWith(Bar));
        UNIT_ASSERT(foobar.EndsWith(bAR));
        UNIT_ASSERT(foobar.Contains(FOO));
        UNIT_ASSERT(foobar.Contains(Bar));
    }

    Y_UNIT_TEST(BasicStdString) {
        using TCaseInsensitiveStdString = std::basic_string<char, TCaseInsensitiveCharTraits>;
        using TCaseInsensitiveStringView = std::basic_string_view<char, TCaseInsensitiveCharTraits>;

        TCaseInsensitiveStdString foo("foo");
        TCaseInsensitiveStdString FOO("FOO");
        TCaseInsensitiveStdString Bar("Bar");
        TCaseInsensitiveStdString bAR("bAR");

        UNIT_ASSERT_EQUAL(foo, FOO);
        UNIT_ASSERT_EQUAL(Bar, bAR);

        constexpr TCaseInsensitiveStringView foobar("foobar");
        UNIT_ASSERT(foobar.starts_with(foo));
        UNIT_ASSERT(foobar.starts_with(FOO));
        UNIT_ASSERT(foobar.ends_with(Bar));
        UNIT_ASSERT(foobar.ends_with(bAR));
        //TODO: test contains after C++23
    }

/*
    Y_UNIT_TEST(TestSplit) {
        TCaseInsensitiveStringBuf input("splitAmeAbro");
        TVector<TCaseInsensitiveStringBuf> expected{"split", "me", "bro"};

        TVector<TCaseInsensitiveStringBuf> split = StringSplitter(input).Split('a');

        UNIT_ASSERT_VALUES_EQUAL(split, expected);
    }
*/
}