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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include "cata_catch.h"
#include <initializer_list>
#include <iterator>
#include <vector>
#include <string>
#include "output.h"
template<class IterResult, class IterExpect>
static void check_equal( IterResult beg_res, IterResult end_res,
IterExpect beg_exp, IterExpect end_exp )
{
CHECK( std::distance( beg_res, end_res ) == std::distance( beg_exp, end_exp ) );
IterResult result = beg_res;
IterExpect expect = beg_exp;
for( ; result != end_res && expect != end_exp; ++result, ++expect ) {
CHECK( *result == *expect );
}
}
TEST_CASE( "fold-string" )
{
SECTION( "Case 1 - test wrapping of lorem ipsum" ) {
const auto folded = foldstring(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque a.",
17
);
const auto expected = {
/*
0123456789abcdefg
*/
"Lorem ipsum dolor",
"sit amet, ",
"consectetur ",
"adipiscing elit. ", // NOLINT(cata-text-style)
"Pellentesque a.",
};
check_equal( folded.begin(), folded.end(), expected.begin(), expected.end() );
}
SECTION( "Case 2 - test wrapping of Chinese" ) {
const auto folded = foldstring(
"春哥纯爷们,铁血真汉子。人民好兄弟,父亲好儿子。",
19
);
const auto expected = {
/*
0123456789abcdefghi
*/
"春哥纯爷们,铁血真",
"汉子。人民好兄弟,",
"父亲好儿子。",
};
check_equal( folded.begin(), folded.end(), expected.begin(), expected.end() );
}
SECTION( "Case 3 - test wrapping of mixed language" ) {
const auto folded = foldstring(
"Cataclysm-DDA是Github上的一个开源游戏项目,目前已有超过16000个PR.",
13
);
const auto expected = {
/*
0123456789abc
*/
"Cataclysm-DDA",
"是Github上的",
"一个开源游戏",
"项目,目前已",
"有超过16000个",
"PR."
};
check_equal( folded.begin(), folded.end(), expected.begin(), expected.end() );
}
SECTION( "Case 4 - test color tags" ) {
const auto folded = foldstring(
"<color_red>Lorem ipsum dolor sit amet, <color_green>consectetur adipiscing elit</color>. Pellentesque a.</color>",
18
);
const auto expected = {
"<color_red>Lorem ipsum dolor </color>",
"<color_red>sit amet, </color>",
"<color_red><color_green>consectetur </color></color>",
"<color_red><color_green>adipiscing elit</color>. </color>",
"<color_red>Pellentesque a.</color>",
};
check_equal( folded.begin(), folded.end(), expected.begin(), expected.end() );
}
SECTION( "Case 5 - test long word" ) {
const auto folded = foldstring(
"You gain a mutation called Hippopotomonstrosesquippedaliophobia!",
20
);
const auto expected = {
/*
0123456789abcdefghij
*/
"You gain a mutation ",
"called ",
"Hippopotomonstrosesq",
"uippedaliophobia!"
};
check_equal( folded.begin(), folded.end(), expected.begin(), expected.end() );
}
}
|