CommentTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php declare(strict_types=1);
  2. namespace PhpParser;
  3. class CommentTest extends \PHPUnit\Framework\TestCase
  4. {
  5. public function testGetSet() {
  6. $comment = new Comment('/* Some comment */', 1, 10, 2);
  7. $this->assertSame('/* Some comment */', $comment->getText());
  8. $this->assertSame('/* Some comment */', (string) $comment);
  9. $this->assertSame(1, $comment->getLine());
  10. $this->assertSame(10, $comment->getFilePos());
  11. $this->assertSame(2, $comment->getTokenPos());
  12. }
  13. /**
  14. * @dataProvider provideTestReformatting
  15. */
  16. public function testReformatting($commentText, $reformattedText) {
  17. $comment = new Comment($commentText);
  18. $this->assertSame($reformattedText, $comment->getReformattedText());
  19. }
  20. public function provideTestReformatting() {
  21. return [
  22. ['// Some text' . "\n", '// Some text'],
  23. ['/* Some text */', '/* Some text */'],
  24. [
  25. '/**
  26. * Some text.
  27. * Some more text.
  28. */',
  29. '/**
  30. * Some text.
  31. * Some more text.
  32. */'
  33. ],
  34. [
  35. '/*
  36. Some text.
  37. Some more text.
  38. */',
  39. '/*
  40. Some text.
  41. Some more text.
  42. */'
  43. ],
  44. [
  45. '/* Some text.
  46. More text.
  47. Even more text. */',
  48. '/* Some text.
  49. More text.
  50. Even more text. */'
  51. ],
  52. [
  53. '/* Some text.
  54. More text.
  55. Indented text. */',
  56. '/* Some text.
  57. More text.
  58. Indented text. */',
  59. ],
  60. // invalid comment -> no reformatting
  61. [
  62. 'hallo
  63. world',
  64. 'hallo
  65. world',
  66. ],
  67. ];
  68. }
  69. }