StringUtilTest.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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('tags', 'tag'),
  20. array('alumni', 'alumnus'),
  21. array('funguses', array('fungus', 'funguse', 'fungusis')),
  22. array('fungi', 'fungus'),
  23. array('axes', array('ax', 'axe', 'axis')),
  24. array('appendices', array('appendex', 'appendix', 'appendice')),
  25. array('indices', array('index', 'indix', 'indice')),
  26. array('prices', array('prex', 'prix', 'price')),
  27. array('indexes', 'index'),
  28. array('children', 'child'),
  29. array('men', 'man'),
  30. array('women', 'woman'),
  31. array('oxen', 'ox'),
  32. array('bacteria', array('bacterion', 'bacterium')),
  33. array('criteria', array('criterion', 'criterium')),
  34. array('feet', 'foot'),
  35. array('nebulae', 'nebula'),
  36. array('babies', 'baby'),
  37. array('hooves', 'hoof'),
  38. array('chateaux', 'chateau'),
  39. array('echoes', array('echo', 'echoe')),
  40. array('analyses', array('analys', 'analyse', 'analysis')),
  41. array('theses', array('thes', 'these', 'thesis')),
  42. array('foci', 'focus'),
  43. array('focuses', array('focus', 'focuse', 'focusis')),
  44. array('oases', array('oas', 'oase', 'oasis')),
  45. array('matrices', array('matrex', 'matrix', 'matrice')),
  46. array('matrixes', 'matrix'),
  47. array('bureaus', 'bureau'),
  48. array('bureaux', 'bureau'),
  49. array('beaux', 'beau'),
  50. array('data', array('daton', 'datum')),
  51. array('phenomena', array('phenomenon', 'phenomenum')),
  52. array('strata', array('straton', 'stratum')),
  53. array('geese', 'goose'),
  54. array('teeth', 'tooth'),
  55. array('antennae', 'antenna'),
  56. array('antennas', 'antenna'),
  57. array('houses', array('hous', 'house', 'housis')),
  58. array('arches', array('arch', 'arche')),
  59. array('atlases', array('atlas', 'atlase', 'atlasis')),
  60. array('batches', array('batch', 'batche')),
  61. array('bushes', array('bush', 'bushe')),
  62. array('buses', array('bus', 'buse', 'busis')),
  63. array('calves', 'calf'),
  64. array('circuses', array('circus', 'circuse', 'circusis')),
  65. array('crises', array('cris', 'crise', 'crisis')),
  66. array('dwarves', 'dwarf'),
  67. array('elves', 'elf'),
  68. array('emphases', array('emphas', 'emphase', 'emphasis')),
  69. array('faxes', 'fax'),
  70. array('halves', 'half'),
  71. array('heroes', array('hero', 'heroe')),
  72. array('hoaxes', 'hoax'),
  73. array('irises', array('iris', 'irise', 'irisis')),
  74. array('kisses', array('kiss', 'kisse', 'kissis')),
  75. array('knives', 'knife'),
  76. array('lives', 'life'),
  77. array('lice', 'louse'),
  78. array('mice', 'mouse'),
  79. array('neuroses', array('neuros', 'neurose', 'neurosis')),
  80. array('plateaux', 'plateau'),
  81. array('poppies', 'poppy'),
  82. array('quizzes', 'quiz'),
  83. array('scarves', 'scarf'),
  84. array('spies', 'spy'),
  85. array('stories', 'story'),
  86. array('syllabi', 'syllabus'),
  87. array('thieves', 'thief'),
  88. array('waltzes', array('waltz', 'waltze')),
  89. array('wharves', 'wharf'),
  90. array('wives', 'wife'),
  91. array('ions', 'ion'),
  92. array('bases', array('bas', 'base', 'basis')),
  93. array('cars', 'car'),
  94. array('cassettes', array('cassett', 'cassette')),
  95. array('lamps', 'lamp'),
  96. array('hats', 'hat'),
  97. array('cups', 'cup'),
  98. array('boxes', 'box'),
  99. array('sandwiches', array('sandwich', 'sandwiche')),
  100. array('suitcases', array('suitcas', 'suitcase', 'suitcasis')),
  101. array('roses', array('ros', 'rose', 'rosis')),
  102. array('garages', array('garag', 'garage')),
  103. array('shoes', array('sho', 'shoe')),
  104. array('days', 'day'),
  105. array('boys', 'boy'),
  106. array('roofs', 'roof'),
  107. array('cliffs', 'cliff'),
  108. array('sheriffs', 'sheriff'),
  109. array('discos', 'disco'),
  110. array('pianos', 'piano'),
  111. array('photos', 'photo'),
  112. array('trees', array('tre', 'tree')),
  113. array('bees', array('be', 'bee')),
  114. array('cheeses', array('chees', 'cheese', 'cheesis')),
  115. array('radii', 'radius'),
  116. array('objectives', 'objective'),
  117. array('moves', 'move'),
  118. // test casing: if the first letter was uppercase, it should remain so
  119. array('Men', 'Man'),
  120. array('GrandChildren', 'GrandChild'),
  121. array('SubTrees', array('SubTre', 'SubTree')),
  122. );
  123. }
  124. /**
  125. * @dataProvider singularifyProvider
  126. */
  127. public function testSingularify($plural, $singular)
  128. {
  129. $this->assertEquals($singular, StringUtil::singularify($plural));
  130. }
  131. }