text.tests.cpp

 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
#include <planet/sdl/ui/text.hpp>
#include <planet/ui/baseplate.hpp>
#include <felspar/test.hpp>
#include <felspar/memory/hexdump.hpp>


namespace {


    auto const suite = felspar::testsuite(
            "text",
            [](auto check) {
                std::string str{};
                check(planet::sdl::ui::text::identify_words(str).empty())
                        == true;
            },
            [](auto check, auto &log) {
                std::string str{"Hello World!"};
                auto const words = planet::sdl::ui::text::identify_words(str);
                felspar::memory::hexdump(
                        log, std::span{str.data(), str.size()});
                check(words.size()) == 2u;
                felspar::memory::hexdump(
                        log, std::span{words[0].data(), words[0].size()});
                check(words[0]) == "Hello";
                felspar::memory::hexdump(
                        log, std::span{words[1].data(), words[1].size()});
                check(words[1]) == "World!";
            },
            [](auto check, auto &log) {
                std::string str{"  Hello World!"};
                auto const words = planet::sdl::ui::text::identify_words(str);
                felspar::memory::hexdump(
                        log, std::span{str.data(), str.size()});
                check(words.size()) == 2u;
                felspar::memory::hexdump(
                        log, std::span{words[0].data(), words[0].size()});
                check(words[0]) == "Hello";
                felspar::memory::hexdump(
                        log, std::span{words[1].data(), words[1].size()});
                check(words[1]) == "World!";
            },
            [](auto check, auto &log) {
                std::string str{"Hello World!  "};
                auto const words = planet::sdl::ui::text::identify_words(str);
                felspar::memory::hexdump(
                        log, std::span{str.data(), str.size()});
                check(words.size()) == 2u;
                felspar::memory::hexdump(
                        log, std::span{words[0].data(), words[0].size()});
                check(words[0]) == "Hello";
                felspar::memory::hexdump(
                        log, std::span{words[1].data(), words[1].size()});
                check(words[1]) == "World!";
            });


}