mapnik/test/unit/text/script_runs.cpp

51 lines
1.4 KiB
C++
Raw Normal View History

2019-11-04 11:47:35 +01:00
#include "catch.hpp"
2019-11-04 12:22:41 +01:00
#include <unicode/unistr.h>
2019-11-04 11:47:35 +01:00
#include <mapnik/unicode.hpp>
#include <mapnik/text/scrptrun.hpp>
TEST_CASE("nested script runs")
{
mapnik::value_unicode_string text(u"Nested text runs(первый(second(третий)))"); // mixed scripts
2019-11-04 11:47:35 +01:00
ScriptRun runs(text.getBuffer(), text.length());
std::size_t count = 0;
std::size_t size = 0;
while (runs.next())
{
2022-01-26 23:25:53 +01:00
if (count & 1)
CHECK(runs.getScriptCode() == USCRIPT_CYRILLIC);
else
CHECK(runs.getScriptCode() == USCRIPT_LATIN);
2019-11-04 11:47:35 +01:00
size += runs.getScriptEnd() - runs.getScriptStart();
++count;
}
REQUIRE(count == 7);
REQUIRE(size == text.length());
}
TEST_CASE("many punctuation chars")
{
mapnik::value_unicode_string text((std::string(791, '(') + "test").data());
2019-11-04 11:47:35 +01:00
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(size == text.length());
}