Skip to content
Snippets Groups Projects
Commit 591632df authored by Shibin Das's avatar Shibin Das
Browse files

Issue #3496376 by d34dman: Implement Rule for "Four Forms Manx"

parent fdc2cc70
No related branches found
No related tags found
No related merge requests found
<?php
namespace Drupal\string_plural_form\Plugin\StringPluralForm;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\string_plural_form\Attribute\StringPluralForm;
use Drupal\string_plural_form\StringPluralFormBase;
/**
* Provides a Plural Form for "Manx" language.
*/
#[StringPluralForm(
id: "four_forms_manx",
admin_label: new TranslatableMarkup("Four Forms Manx"),
description: new TranslatableMarkup("Case in the Manx language."),
)]
class FourFormsManx extends StringPluralFormBase {
/**
* {@inheritdoc}
*/
public function getGettextNplurals(): int {
return 4;
}
/**
* {@inheritdoc}
*/
public function getGettextPlural(): string {
return "(n % 10 == 1) ? 0 : ((n % 10 == 2) ? 1 : ((n % 100 == 0 || n % 100 == 20 || n % 100 == 40 || n % 100 == 60 || n % 100 == 80) ? 2 : 3))";
}
/**
* {@inheritdoc}
*/
public function getAssociatedLanguageCodes(): array {
return [
"gv",
];
}
/**
* {@inheritdoc}
*/
public function getIndex(int $n): int {
return ($n % 10 == 1) ? 0 : (($n % 10 == 2) ? 1 : (($n % 100 == 0 || $n % 100 == 20 || $n % 100 == 40 || $n % 100 == 60 || $n % 100 == 80) ? 2 : 3));
}
/**
* {@inheritdoc}
*/
public function getIndexLabel(int $index): TranslatableMarkup {
return match($index) {
0 => new TranslatableMarkup("1, 11, 21, 31, ..."),
1 => new TranslatableMarkup("2, 12, 22, 32, ..."),
2 => new TranslatableMarkup("0, 20, 40, 50, ..."),
3 => new TranslatableMarkup("3, 4, 5, 6, ..."),
};
}
}
<?php
namespace Drupal\Tests\string_plural_form\Unit\StringPluralForm;
use Drupal\string_plural_form\Plugin\StringPluralForm\FourFormsManx;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\string_plural_form\Plugin\StringPluralForm\FourFormsManx
* @group StringPluralFormPlugins
*/
class FourFormsManxTest extends UnitTestCase {
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FourFormsManx::getGettextNplurals()
*/
public function testGetGettextNplurals() {
$plugin = new FourFormsManx();
$this->assertEquals(4, $plugin->getGettextNplurals());
}
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FourFormsManx::getGettextNplurals()
*/
public function testGetGettextPlural() {
$plugin = new FourFormsManx();
$this->assertEquals("(n % 10 == 1) ? 0 : ((n % 10 == 2) ? 1 : ((n % 100 == 0 || n % 100 == 20 || n % 100 == 40 || n % 100 == 60 || n % 100 == 80) ? 2 : 3))", $plugin->getGettextPlural());
}
/**
* Tests \Drupal\string_plural_form\Plugin\StringPluralForm\FourFormsManx::getIndex()
*/
public function testGetIndex() {
$plugin = new FourFormsManx();
$expected_forms = [
0 => [
1, 11, 21, 31, 41, 51, 61, 71, 81, 91,
101, 111, 121, 131, 141, 151, 161, 171, 181, 191,
201, 211, 221,
],
1 => [
2, 12, 22, 32, 42, 52, 62, 72, 82, 92,
102, 112, 122, 132, 142, 152, 162, 172, 182, 192,
202, 212, 222,
],
2 => [0, 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220],
3 => [
3, 4, 5, 6, 7, 8, 9,
10, 13, 14, 15, 16, 17, 18, 19,
23, 24, 25, 26, 27, 28, 29,
30, 33, 34, 35, 36, 37, 38, 39,
43, 44, 45, 46, 47, 48, 49,
50, 53, 54, 55, 56, 57, 58, 59,
63, 64, 65, 66, 67, 68, 69,
70, 73, 74, 75, 76, 77, 78, 79,
83, 84, 85, 86, 87, 88, 89, 90,
93, 94, 95, 96, 97, 98, 99,
103, 104, 105, 106, 107, 108, 109,
110, 113, 114, 115, 116, 117, 118, 119,
123, 124, 125, 126, 127, 128, 129,
130, 133, 134, 135, 136, 137, 138, 139,
143, 144, 145, 146, 147, 148, 149,
150, 153, 154, 155, 156, 157, 158, 159,
163, 164, 165, 166, 167, 168, 169,
170, 173, 174, 175, 176, 177, 178,
179, 183, 184, 185, 186, 187, 188, 189,
190, 193, 194, 195, 196, 197, 198, 199,
203, 204, 205, 206, 207, 208, 209,
210, 213, 214, 215, 216, 217, 218, 219,
223, 224, 225, 226, 227, 228, 229,
],
];
foreach ($expected_forms as $index => $numbers) {
foreach ($numbers as $n) {
$this->assertEquals($index, $plugin->getIndex($n));
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment