SingleLineCommentSpacingFixerTest.php 2.5 KB

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