File: script_runs.cpp

package info (click to toggle)
mapnik 4.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 18,548 kB
  • sloc: cpp: 163,861; python: 1,190; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (51 lines) | stat: -rw-r--r-- 1,456 bytes parent folder | download | duplicates (3)
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
#include "catch.hpp"
#include <unicode/unistr.h>
#include <mapnik/unicode.hpp>
#include <mapnik/text/scrptrun.hpp>
#include <utility>

TEST_CASE("nested script runs")
{
    mapnik::value_unicode_string text(u"Nested text runs(первый(second(третий)))"); // mixed scripts
    ScriptRun runs(text.getBuffer(), text.length());
    std::size_t count = 0;
    std::size_t size = 0;
    while (runs.next())
    {
        if (count & 1)
            CHECK(runs.getScriptCode() == USCRIPT_CYRILLIC);
        else
            CHECK(runs.getScriptCode() == USCRIPT_LATIN);
        size += runs.getScriptEnd() - runs.getScriptStart();
        ++count;
    }
    REQUIRE(count == 7);
    REQUIRE(std::cmp_equal(size, text.length()));
}

TEST_CASE("many punctuation chars")
{
    mapnik::value_unicode_string text((std::string(791, '(') + "test").data());
    ScriptRun runs(text.getBuffer(), text.length());
    while (runs.next())
    {
        CHECK(runs.getScriptCode() == 25);
        CHECK(runs.getScriptStart() == 0);
        CHECK(runs.getScriptEnd() == text.length());
    }
}

TEST_CASE("empty runs")
{
    mapnik::value_unicode_string text("()text");
    ScriptRun runs(text.getBuffer(), text.length());
    std::size_t count = 0;
    std::size_t size = 0;
    while (runs.next())
    {
        size += runs.getScriptEnd() - runs.getScriptStart();
        ++count;
    }
    REQUIRE(count == 1);
    REQUIRE(std::cmp_equal(size, text.length()));
}