StringUtilTest.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\PropertyAccess\Tests;
  11. use Symfony\Component\PropertyAccess\StringUtil;
  12. class StringUtilTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function singularifyProvider()
  15. {
  16. // see http://english-zone.com/spelling/plurals.html
  17. // see http://www.scribd.com/doc/3271143/List-of-100-Irregular-Plural-Nouns-in-English
  18. return array(
  19. array('accesses', 'access'),
  20. array('addresses', 'address'),
  21. array('agendas', 'agenda'),
  22. array('alumnae', 'alumna'),
  23. array('alumni', 'alumnus'),
  24. array('analyses', array('analys', 'analyse', 'analysis')),
  25. array('antennae', 'antenna'),
  26. array('antennas', 'antenna'),
  27. array('appendices', array('appendex', 'appendix', 'appendice')),
  28. array('arches', array('arch', 'arche')),
  29. array('atlases', array('atlas', 'atlase', 'atlasis')),
  30. array('axes', array('ax', 'axe', 'axis')),
  31. array('babies', 'baby'),
  32. array('bacteria', array('bacterion', 'bacterium')),
  33. array('bases', array('bas', 'base', 'basis')),
  34. array('batches', array('batch', 'batche')),
  35. array('beaux', 'beau'),
  36. array('bees', array('be', 'bee')),
  37. array('boxes', 'box'),
  38. array('boys', 'boy'),
  39. array('bureaus', 'bureau'),
  40. array('bureaux', 'bureau'),
  41. array('buses', array('bus', 'buse', 'busis')),
  42. array('bushes', array('bush', 'bushe')),
  43. array('calves', array('calf', 'calve', 'calff')),
  44. array('cars', 'car'),
  45. array('cassettes', array('cassett', 'cassette')),
  46. array('caves', array('caf', 'cave', 'caff')),
  47. array('chateaux', 'chateau'),
  48. array('cheeses', array('chees', 'cheese', 'cheesis')),
  49. array('children', 'child'),
  50. array('circuses', array('circus', 'circuse', 'circusis')),
  51. array('cliffs', 'cliff'),
  52. array('committee', 'committee'),
  53. array('crises', array('cris', 'crise', 'crisis')),
  54. array('criteria', array('criterion', 'criterium')),
  55. array('cups', 'cup'),
  56. array('data', array('daton', 'datum')),
  57. array('days', 'day'),
  58. array('discos', 'disco'),
  59. array('devices', array('devex', 'devix', 'device')),
  60. array('drives', 'drive'),
  61. array('drivers', 'driver'),
  62. array('dwarves', array('dwarf', 'dwarve', 'dwarff')),
  63. array('echoes', array('echo', 'echoe')),
  64. array('elves', array('elf', 'elve', 'elff')),
  65. array('emphases', array('emphas', 'emphase', 'emphasis')),
  66. array('faxes', 'fax'),
  67. array('feet', 'foot'),
  68. array('feedback', 'feedback'),
  69. array('foci', 'focus'),
  70. array('focuses', array('focus', 'focuse', 'focusis')),
  71. array('formulae', 'formula'),
  72. array('formulas', 'formula'),
  73. array('fungi', 'fungus'),
  74. array('funguses', array('fungus', 'funguse', 'fungusis')),
  75. array('garages', array('garag', 'garage')),
  76. array('geese', 'goose'),
  77. array('halves', array('half', 'halve', 'halff')),
  78. array('hats', 'hat'),
  79. array('heroes', array('hero', 'heroe')),
  80. array('hippopotamuses', array('hippopotamus', 'hippopotamuse', 'hippopotamusis')), //hippopotami
  81. array('hoaxes', 'hoax'),
  82. array('hooves', array('hoof', 'hoove', 'hooff')),
  83. array('houses', array('hous', 'house', 'housis')),
  84. array('indexes', 'index'),
  85. array('indices', array('index', 'indix', 'indice')),
  86. array('ions', 'ion'),
  87. array('irises', array('iris', 'irise', 'irisis')),
  88. array('kisses', 'kiss'),
  89. array('knives', 'knife'),
  90. array('lamps', 'lamp'),
  91. array('leaves', array('leaf', 'leave', 'leaff')),
  92. array('lice', 'louse'),
  93. array('lives', 'life'),
  94. array('matrices', array('matrex', 'matrix', 'matrice')),
  95. array('matrixes', 'matrix'),
  96. array('men', 'man'),
  97. array('mice', 'mouse'),
  98. array('moves', 'move'),
  99. array('movies', 'movie'),
  100. array('nebulae', 'nebula'),
  101. array('neuroses', array('neuros', 'neurose', 'neurosis')),
  102. array('news', 'news'),
  103. array('oases', array('oas', 'oase', 'oasis')),
  104. array('objectives', 'objective'),
  105. array('oxen', 'ox'),
  106. array('parties', 'party'),
  107. array('people', 'person'),
  108. array('persons', 'person'),
  109. array('phenomena', array('phenomenon', 'phenomenum')),
  110. array('photos', 'photo'),
  111. array('pianos', 'piano'),
  112. array('plateaux', 'plateau'),
  113. array('poppies', 'poppy'),
  114. array('prices', array('prex', 'prix', 'price')),
  115. array('quizzes', 'quiz'),
  116. array('radii', 'radius'),
  117. array('roofs', 'roof'),
  118. array('roses', array('ros', 'rose', 'rosis')),
  119. array('sandwiches', array('sandwich', 'sandwiche')),
  120. array('scarves', array('scarf', 'scarve', 'scarff')),
  121. array('schemas', 'schema'), //schemata
  122. array('selfies', 'selfie'),
  123. array('series', 'series'),
  124. array('services', 'service'),
  125. array('sheriffs', 'sheriff'),
  126. array('shoes', array('sho', 'shoe')),
  127. array('spies', 'spy'),
  128. array('staves', array('staf', 'stave', 'staff')),
  129. array('stories', 'story'),
  130. array('strata', array('straton', 'stratum')),
  131. array('suitcases', array('suitcas', 'suitcase', 'suitcasis')),
  132. array('syllabi', 'syllabus'),
  133. array('tags', 'tag'),
  134. array('teeth', 'tooth'),
  135. array('theses', array('thes', 'these', 'thesis')),
  136. array('thieves', array('thief', 'thieve', 'thieff')),
  137. array('trees', array('tre', 'tree')),
  138. array('waltzes', array('waltz', 'waltze')),
  139. array('wives', 'wife'),
  140. // test casing: if the first letter was uppercase, it should remain so
  141. array('Men', 'Man'),
  142. array('GrandChildren', 'GrandChild'),
  143. array('SubTrees', array('SubTre', 'SubTree')),
  144. // Known issues
  145. //array('insignia', 'insigne'),
  146. //array('insignias', 'insigne'),
  147. //array('rattles', 'rattle'),
  148. );
  149. }
  150. /**
  151. * @dataProvider singularifyProvider
  152. */
  153. public function testSingularify($plural, $singular)
  154. {
  155. $single = StringUtil::singularify($plural);
  156. if (is_string($singular) && is_array($single)) {
  157. $this->fail("--- Expected\n`string`: ".$singular."\n+++ Actual\n`array`: ".implode(', ', $single));
  158. } elseif (is_array($singular) && is_string($single)) {
  159. $this->fail("--- Expected\n`array`: ".implode(', ', $singular)."\n+++ Actual\n`string`: ".$single);
  160. }
  161. $this->assertEquals($singular, $single);
  162. }
  163. }