CommentTest.php 2.0 KB

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