NoTrailingWhitespaceInCommentFixerTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\Comment;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer
  20. */
  21. final class NoTrailingWhitespaceInCommentFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null): void
  27. {
  28. $this->doTest($expected, $input);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. yield [
  33. '<?php
  34. /*
  35. //
  36. //
  37. //
  38. //
  39. //
  40. //
  41. //
  42. //
  43. */
  44. ',
  45. '<?php
  46. /*
  47. //
  48. //
  49. '.'
  50. //
  51. //
  52. //
  53. '.'
  54. //
  55. //
  56. '.'
  57. //
  58. */
  59. ',
  60. ];
  61. yield [
  62. '<?php
  63. // This is'.'
  64. //'.'
  65. //'.'
  66. // multiline comment.
  67. //',
  68. '<?php
  69. // This is '.'
  70. // '.'
  71. // '.'
  72. // multiline comment. '.'
  73. // ',
  74. ];
  75. yield [
  76. '<?php
  77. /*
  78. * This is another'.'
  79. *'.'
  80. *'.'
  81. * multiline comment.'.'
  82. */',
  83. '<?php
  84. /* '.'
  85. * This is another '.'
  86. * '.'
  87. * '.'
  88. * multiline comment. '.'
  89. */',
  90. ];
  91. yield [
  92. '<?php
  93. /**
  94. * Summary'.'
  95. *'.'
  96. *'.'
  97. * Description.'.'
  98. *
  99. * @annotation
  100. * Foo
  101. */',
  102. '<?php
  103. /** '.'
  104. * Summary '.'
  105. * '.'
  106. * '.'
  107. * Description. '.'
  108. * '.'
  109. * @annotation '.'
  110. * Foo '.'
  111. */',
  112. ];
  113. yield [
  114. str_replace(
  115. "\n",
  116. "\r\n",
  117. '<?php
  118. /**
  119. * Summary
  120. *'.'
  121. * Description
  122. */'
  123. ),
  124. str_replace(
  125. "\n",
  126. "\r\n",
  127. '<?php
  128. /**
  129. * Summary
  130. * '.'
  131. * Description
  132. */'
  133. ),
  134. ];
  135. yield [
  136. str_replace(
  137. "\n",
  138. "\r",
  139. '<?php
  140. /**
  141. * Summary
  142. *'.'
  143. * Description
  144. */'
  145. ),
  146. str_replace(
  147. "\n",
  148. "\r",
  149. '<?php
  150. /**
  151. * Summary
  152. * '.'
  153. * Description
  154. */'
  155. ),
  156. ];
  157. }
  158. }