CommentTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. }
  12. /**
  13. * @dataProvider provideTestReformatting
  14. */
  15. public function testReformatting($commentText, $reformattedText) {
  16. $comment = new Comment($commentText);
  17. $this->assertSame($reformattedText, $comment->getReformattedText());
  18. }
  19. public function provideTestReformatting() {
  20. return array(
  21. array('// Some text' . "\n", '// Some text'),
  22. array('/* Some text */', '/* Some text */'),
  23. array(
  24. '/**
  25. * Some text.
  26. * Some more text.
  27. */',
  28. '/**
  29. * Some text.
  30. * Some more text.
  31. */'
  32. ),
  33. array(
  34. '/*
  35. Some text.
  36. Some more text.
  37. */',
  38. '/*
  39. Some text.
  40. Some more text.
  41. */'
  42. ),
  43. array(
  44. '/* Some text.
  45. More text.
  46. Even more text. */',
  47. '/* Some text.
  48. More text.
  49. Even more text. */'
  50. ),
  51. array(
  52. '/* Some text.
  53. More text.
  54. Indented text. */',
  55. '/* Some text.
  56. More text.
  57. Indented text. */',
  58. ),
  59. // invalid comment -> no reformatting
  60. array(
  61. 'hallo
  62. world',
  63. 'hallo
  64. world',
  65. ),
  66. );
  67. }
  68. }