arrayInsertionWithComments.test 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. Inserting array item with comment
  2. -----
  3. <?php
  4. $items = [
  5. 'a' => 'foo',
  6. 'b' => 'bar',
  7. ];
  8. -----
  9. $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c'));
  10. $node->setAttribute('comments', [new Comment\Doc(<<<COMMENT
  11. /**
  12. * A doc comment
  13. */
  14. COMMENT
  15. )]);
  16. $array = $stmts[0]->expr->expr;
  17. $array->items[] = $node;
  18. -----
  19. <?php
  20. $items = [
  21. 'a' => 'foo',
  22. 'b' => 'bar',
  23. /**
  24. * A doc comment
  25. */
  26. 'c' => 'baz',
  27. ];
  28. -----
  29. <?php
  30. $items = [
  31. 'a' => 'foo',
  32. 'b' => 'bar',
  33. ];
  34. -----
  35. $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c'));
  36. $node->setAttribute('comments', [new Comment("/* Block comment */")]);
  37. $array = $stmts[0]->expr->expr;
  38. $array->items[] = $node;
  39. -----
  40. <?php
  41. $items = [
  42. 'a' => 'foo',
  43. 'b' => 'bar',
  44. /* Block comment */
  45. 'c' => 'baz',
  46. ];
  47. -----
  48. <?php
  49. $items = [
  50. 'a' => 'foo',
  51. 'b' => 'bar',
  52. ];
  53. -----
  54. $node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c'));
  55. $node->setAttribute('comments', [new Comment("// Line comment")]);
  56. $array = $stmts[0]->expr->expr;
  57. $array->items[] = $node;
  58. -----
  59. <?php
  60. $items = [
  61. 'a' => 'foo',
  62. 'b' => 'bar',
  63. // Line comment
  64. 'c' => 'baz',
  65. ];
  66. -----
  67. <?php
  68. $items = [
  69. 'a' => 'foo',
  70. ];
  71. -----
  72. $node = new Expr\ArrayItem(new Scalar\String_('bar'), new Scalar\String_('b'));
  73. $node->setAttribute('comments', [new Comment("// Line comment")]);
  74. $array = $stmts[0]->expr->expr;
  75. $array->items[] = $node;
  76. -----
  77. <?php
  78. $items = [
  79. 'a' => 'foo',
  80. // Line comment
  81. 'b' => 'bar',
  82. ];
  83. -----
  84. <?php
  85. $items = [];
  86. -----
  87. $node = new Expr\ArrayItem(new Scalar\String_('foo'), new Scalar\String_('a'));
  88. $node->setAttribute('comments', [new Comment("// Line comment")]);
  89. $array = $stmts[0]->expr->expr;
  90. $array->items[] = $node;
  91. -----
  92. <?php
  93. $items = [
  94. // Line comment
  95. 'a' => 'foo',
  96. ];