SingleLineCommentSpacingFixerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. * @internal
  16. *
  17. * @covers \PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer
  18. *
  19. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer>
  20. */
  21. final class SingleLineCommentSpacingFixerTest 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. /**
  31. * @return iterable<int|string, array{0: string, 1?: string}>
  32. */
  33. public static function provideFixCases(): iterable
  34. {
  35. yield 'comment list' => [
  36. '<?php
  37. // following:
  38. // 1 :
  39. // 2 :
  40. # Test:
  41. # - abc
  42. # - fgh
  43. # Title:
  44. # | abc1
  45. # | xyz
  46. // Point:
  47. // * first point
  48. // * some other point
  49. // Matrix:
  50. // [1,2]
  51. // [3,4]
  52. ',
  53. ];
  54. yield [
  55. '<?php /* XYZ */',
  56. '<?php /* XYZ */',
  57. ];
  58. yield [
  59. '<?php // /',
  60. '<?php ///',
  61. ];
  62. yield [
  63. '<?php // //',
  64. '<?php ////',
  65. ];
  66. yield 'hash open slash asterisk close' => [
  67. '<?php # A*/',
  68. '<?php #A*/',
  69. ];
  70. yield [
  71. "<?php
  72. // a
  73. # b
  74. /* ABC */
  75. // \t d
  76. #\te
  77. /* f */
  78. ",
  79. "<?php
  80. //a
  81. #b
  82. /*ABC*/
  83. // \t d
  84. #\te
  85. /* f */
  86. ",
  87. ];
  88. yield 'do not fix multi line comments' => [
  89. '<?php
  90. /*
  91. */
  92. /*A
  93. B*/
  94. ',
  95. ];
  96. yield 'empty double slash' => [
  97. '<?php //',
  98. ];
  99. yield 'empty hash' => [
  100. '<?php #',
  101. ];
  102. yield [
  103. '<?php /**/',
  104. ];
  105. yield [
  106. '<?php /***/',
  107. ];
  108. yield 'do not fix PHPDocs' => [
  109. "<?php /**\n*/ /**\nX1*/ /** Y1 */",
  110. ];
  111. yield 'do not fix comments looking like PHPDocs' => [
  112. '<?php /**/ /**X1*/ /** Y1 */',
  113. ];
  114. yield 'do not fix annotation' => [
  115. '<?php
  116. namespace PhpCsFixer\Tests\Fixer\Basic;
  117. new
  118. #[Foo]
  119. class extends stdClass {};
  120. ',
  121. ];
  122. }
  123. }