mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Fixup parsing for Plural-Forms
(#15519)
This commit is contained in:
parent
1e59b9a756
commit
ac7406c8a1
3 changed files with 51 additions and 22 deletions
|
@ -25,12 +25,41 @@ TEST_CASE("test translations")
|
|||
{
|
||||
SECTION("Plural-Forms function for translations")
|
||||
{
|
||||
auto form = GettextPluralForm::parseHeaderLine(L"Plural-Forms: nplurals=3; plural= (n-1+1)<=1 ? n||1?0:1 : 1?(!!2):2;");
|
||||
REQUIRE(form);
|
||||
REQUIRE(form->size() == 3);
|
||||
#define REQUIRE_FORM_SIZE(x) {REQUIRE(form); REQUIRE(form->size() == (x));}
|
||||
// Test cases from https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html
|
||||
auto form = GettextPluralForm::parseHeaderLine(L"Plural-Forms: nplurals=2; plural=n != 1;");
|
||||
REQUIRE_FORM_SIZE(2);
|
||||
CHECK((*form)(0) == 1);
|
||||
CHECK((*form)(1) == 0);
|
||||
CHECK((*form)(2) == 1);
|
||||
|
||||
form = GettextPluralForm::parseHeaderLine(L"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;");
|
||||
REQUIRE_FORM_SIZE(3);
|
||||
CHECK((*form)(0) == 2);
|
||||
CHECK((*form)(1) == 0);
|
||||
CHECK((*form)(102) == 1);
|
||||
CHECK((*form)(111) == 1);
|
||||
|
||||
form = GettextPluralForm::parseHeaderLine(L"Plural-Forms: nplurals=3; "
|
||||
"plural=n%10==1 && n%100!=11 ? 0 : "
|
||||
"n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;");
|
||||
REQUIRE_FORM_SIZE(3);
|
||||
CHECK((*form)(0) == 2);
|
||||
CHECK((*form)(1) == 0);
|
||||
CHECK((*form)(102) == 1);
|
||||
CHECK((*form)(104) == 1);
|
||||
CHECK((*form)(111) == 2);
|
||||
CHECK((*form)(112) == 2);
|
||||
CHECK((*form)(121) == 0);
|
||||
CHECK((*form)(122) == 1);
|
||||
|
||||
// Edge cases
|
||||
form = GettextPluralForm::parseHeaderLine(L"Plural-Forms: nplurals=3; plural= (n-1+1)<=1 ? n||1?0:1 : 1?(!!2):2;");
|
||||
REQUIRE_FORM_SIZE(3);
|
||||
CHECK((*form)(0) == 0);
|
||||
CHECK((*form)(1) == 0);
|
||||
CHECK((*form)(2) == 1);
|
||||
#undef REQUIRE_FORM_SIZE
|
||||
}
|
||||
|
||||
SECTION("PO file parser")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue