|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\String\Tests\Inflector; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\String\Inflector\SpanishInflector; |
| 16 | + |
| 17 | +class SpanishInflectorTest extends TestCase |
| 18 | +{ |
| 19 | + public static function singularizeProvider(): array |
| 20 | + { |
| 21 | + return [ |
| 22 | + // vowels (RAE 3.2a, 3.2c) |
| 23 | + ['peras', 'pera'], |
| 24 | + ['especies', 'especie'], |
| 25 | + ['álcalis', 'álcali'], |
| 26 | + ['códigos', 'código'], |
| 27 | + ['espíritus', 'espíritu'], |
| 28 | + |
| 29 | + // accented (RAE 3.2a, 3.2c) |
| 30 | + ['papás', 'papá'], |
| 31 | + ['cafés', 'café'], |
| 32 | + ['isrealís', 'isrealí'], |
| 33 | + ['burós', 'buró'], |
| 34 | + ['tisús', 'tisú'], |
| 35 | + |
| 36 | + // ending in -ión |
| 37 | + ['aviones', 'avión'], |
| 38 | + ['camiones', 'camión'], |
| 39 | + |
| 40 | + // ending in some letters (RAE 3.2k) |
| 41 | + ['amores', 'amor'], |
| 42 | + ['antifaces', 'antifaz'], |
| 43 | + ['atriles', 'atril'], |
| 44 | + ['fácsimiles', 'fácsimil'], |
| 45 | + ['vides', 'vid'], |
| 46 | + ['reyes', 'rey'], |
| 47 | + ['relojes', 'reloj'], |
| 48 | + ['faxes', 'fax'], |
| 49 | + ['sándwiches', 'sándwich'], |
| 50 | + ['cánones', 'cánon'], |
| 51 | + |
| 52 | + // (RAE 3.2n) |
| 53 | + ['adioses', 'adiós'], |
| 54 | + ['aguarrases', 'aguarrás'], |
| 55 | + ['arneses', 'arnés'], |
| 56 | + ['autobuses', 'autobús'], |
| 57 | + ['kermeses', 'kermés'], |
| 58 | + ['palmareses', 'palmarés'], |
| 59 | + ['toses', 'tos'], |
| 60 | + |
| 61 | + // Special |
| 62 | + ['síes', 'sí'], |
| 63 | + ['noes', 'no'], |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
| 67 | + public static function pluralizeProvider(): array |
| 68 | + { |
| 69 | + return [ |
| 70 | + // vowels (RAE 3.2a, 3.2c) |
| 71 | + ['pera', 'peras'], |
| 72 | + ['especie', 'especies'], |
| 73 | + ['álcali', 'álcalis'], |
| 74 | + ['código', 'códigos'], |
| 75 | + ['espíritu', 'espíritus'], |
| 76 | + |
| 77 | + // accented (RAE 3.2a, 3.2c) |
| 78 | + ['papá', 'papás'], |
| 79 | + ['café', 'cafés'], |
| 80 | + ['isrealí', 'isrealís'], |
| 81 | + ['buró', 'burós'], |
| 82 | + ['tisú', 'tisús'], |
| 83 | + |
| 84 | + // ending in -ión |
| 85 | + ['avión', 'aviones'], |
| 86 | + ['camión', 'camiones'], |
| 87 | + |
| 88 | + // ending in some letters (RAE 3.2k) |
| 89 | + ['amor', 'amores'], |
| 90 | + ['antifaz', 'antifaces'], |
| 91 | + ['atril', 'atriles'], |
| 92 | + ['fácsimil', 'fácsimiles'], |
| 93 | + ['vid', 'vides'], |
| 94 | + ['rey', 'reyes'], |
| 95 | + ['reloj', 'relojes'], |
| 96 | + ['fax', 'faxes'], |
| 97 | + ['sándwich', 'sándwiches'], |
| 98 | + ['cánon', 'cánones'], |
| 99 | + |
| 100 | + // (RAE 3.2n) |
| 101 | + ['adiós', 'adioses'], |
| 102 | + ['aguarrás', 'aguarrases'], |
| 103 | + ['arnés', 'arneses'], |
| 104 | + ['autobús', 'autobuses'], |
| 105 | + ['kermés', 'kermeses'], |
| 106 | + ['palmarés', 'palmareses'], |
| 107 | + ['tos', 'toses'], |
| 108 | + |
| 109 | + // Specials |
| 110 | + ['sí', 'síes'], |
| 111 | + ['no', 'noes'], |
| 112 | + ]; |
| 113 | + } |
| 114 | + |
| 115 | + public static function uninflectedProvider(): array |
| 116 | + { |
| 117 | + return [ |
| 118 | + ['lunes'], |
| 119 | + ['rodapiés'], |
| 120 | + ['reposapiés'], |
| 121 | + ['miércoles'], |
| 122 | + ['pies'], |
| 123 | + ]; |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @dataProvider singularizeProvider |
| 128 | + */ |
| 129 | + public function testSingularize(string $plural, $singular) |
| 130 | + { |
| 131 | + $this->assertSame( |
| 132 | + \is_array($singular) ? $singular : [$singular], |
| 133 | + (new SpanishInflector())->singularize($plural) |
| 134 | + ); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
| 138 | + * @dataProvider pluralizeProvider |
| 139 | + */ |
| 140 | + public function testPluralize(string $singular, $plural) |
| 141 | + { |
| 142 | + $this->assertSame( |
| 143 | + \is_array($plural) ? $plural : [$plural], |
| 144 | + (new SpanishInflector())->pluralize($singular) |
| 145 | + ); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * @dataProvider uninflectedProvider |
| 150 | + */ |
| 151 | + public function testUninflected(string $word) |
| 152 | + { |
| 153 | + $this->assertSame( |
| 154 | + \is_array($word) ? $word : [$word], |
| 155 | + (new SpanishInflector())->pluralize($word) |
| 156 | + ); |
| 157 | + } |
| 158 | +} |
0 commit comments