summaryrefslogtreecommitdiff
path: root/test/text/tagged_string.test.cpp
blob: e22284541cbdeb3ffee95c6afd2dc9971259c30a (plain)
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

#include <mbgl/test/util.hpp>

#include <mbgl/text/tagged_string.hpp>

using namespace mbgl;

TEST(TaggedString, Trim) {
    TaggedString basic(u" \t\ntrim that and not this  \n\t", SectionOptions(1.0f, {}));
    basic.trim();
    EXPECT_EQ(basic.rawText(), u"trim that and not this");
    
    TaggedString twoSections;
    twoSections.addTextSection(u" \t\ntrim that", 1.5f, {});
    twoSections.addTextSection(u" and not this  \n\t", 0.5f, {});

    twoSections.trim();
    EXPECT_EQ(twoSections.rawText(), u"trim that and not this");
    
    TaggedString empty(u"\n\t\v \r  \t\n", SectionOptions(1.0f, {}));
    empty.trim();
    EXPECT_EQ(empty.rawText(), u"");
    
    TaggedString noTrim(u"no trim!", SectionOptions(1.0f, {}));
    noTrim.trim();
    EXPECT_EQ(noTrim.rawText(), u"no trim!");
}

TEST(TaggedString, ImageSections) {
    TaggedString string;
    string.addImageSection("image_name");
    EXPECT_EQ(string.rawText(), u"\uE000");
    EXPECT_TRUE(string.getSection(0).imageID);
    EXPECT_EQ(*string.getSection(0).imageID, "image_name");

    TaggedString maxSections;
    for (std::size_t i = 0; i < 6401; ++i) {
        maxSections.addImageSection(util::toString(i));
    }

    EXPECT_EQ(maxSections.getSections().size(), 6400u);
    EXPECT_EQ(maxSections.getCharCodeAt(0), u'\uE000');
    EXPECT_EQ(maxSections.getCharCodeAt(6399), u'\uF8FF');
}