aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/type_ut.cpp
blob: 74ba51b05ca8537e6f6faedcf02d16dd4155b0a3 (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
#include "type.h"

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

#include <util/charset/wide.h>

Y_UNIT_TEST_SUITE(TStringClassify) {
    Y_UNIT_TEST(TestIsSpace) {
        UNIT_ASSERT_EQUAL(IsSpace(" "), true);
        UNIT_ASSERT_EQUAL(IsSpace("\t\r\n"), true);
        UNIT_ASSERT_EQUAL(IsSpace(""), false);
        UNIT_ASSERT_EQUAL(IsSpace("   a"), false);
    }

    Y_UNIT_TEST(TestIsTrue) {
        UNIT_ASSERT(IsTrue("1"));
        UNIT_ASSERT(IsTrue("yes"));
        UNIT_ASSERT(IsTrue("YeS"));
        UNIT_ASSERT(IsTrue("on"));
        UNIT_ASSERT(IsTrue("true"));
        UNIT_ASSERT(IsTrue("t"));
        UNIT_ASSERT(IsTrue("da"));

        UNIT_ASSERT(!IsTrue(""));
        UNIT_ASSERT(!IsTrue("tr"));
        UNIT_ASSERT(!IsTrue("foobar"));
    }

    Y_UNIT_TEST(TestIsFalse) {
        UNIT_ASSERT(IsFalse("0"));
        UNIT_ASSERT(IsFalse("no"));
        UNIT_ASSERT(IsFalse("off"));
        UNIT_ASSERT(IsFalse("false"));
        UNIT_ASSERT(IsFalse("f"));
        UNIT_ASSERT(IsFalse("net"));

        UNIT_ASSERT(!IsFalse(""));
        UNIT_ASSERT(!IsFalse("fa"));
        UNIT_ASSERT(!IsFalse("foobar"));
    }

    Y_UNIT_TEST(TestIsNumber) {
        UNIT_ASSERT(IsNumber("0"));
        UNIT_ASSERT(IsNumber("12345678901234567890"));
        UNIT_ASSERT(!IsNumber("1234567890a"));
        UNIT_ASSERT(!IsNumber("12345xx67890a"));
        UNIT_ASSERT(!IsNumber("foobar"));
        UNIT_ASSERT(!IsNumber(""));

        UNIT_ASSERT(IsNumber(u"0"));
        UNIT_ASSERT(IsNumber(u"12345678901234567890"));
        UNIT_ASSERT(!IsNumber(u"1234567890a"));
        UNIT_ASSERT(!IsNumber(u"12345xx67890a"));
        UNIT_ASSERT(!IsNumber(u"foobar"));
    }

    Y_UNIT_TEST(TestIsHexNumber) {
        UNIT_ASSERT(IsHexNumber("0"));
        UNIT_ASSERT(IsHexNumber("aaaadddAAAAA"));
        UNIT_ASSERT(IsHexNumber("0123456789ABCDEFabcdef"));
        UNIT_ASSERT(IsHexNumber("12345678901234567890"));
        UNIT_ASSERT(IsHexNumber("1234567890a"));
        UNIT_ASSERT(!IsHexNumber("12345xx67890a"));
        UNIT_ASSERT(!IsHexNumber("foobar"));
        UNIT_ASSERT(!IsHexNumber(TString()));

        UNIT_ASSERT(IsHexNumber(u"0"));
        UNIT_ASSERT(IsHexNumber(u"aaaadddAAAAA"));
        UNIT_ASSERT(IsHexNumber(u"0123456789ABCDEFabcdef"));
        UNIT_ASSERT(IsHexNumber(u"12345678901234567890"));
        UNIT_ASSERT(IsHexNumber(u"1234567890a"));
        UNIT_ASSERT(!IsHexNumber(u"12345xx67890a"));
        UNIT_ASSERT(!IsHexNumber(u"foobar"));
        UNIT_ASSERT(!IsHexNumber(TUtf16String()));
    }
} // Y_UNIT_TEST_SUITE(TStringClassify)