CommentTest.php 1.8 KB

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