comments.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. "use strict";
  2. var _helpers = require("./util/helpers");
  3. (0, _helpers.test)('comments', '/*test comment*/h2', function (t, tree) {
  4. t.deepEqual(tree.nodes[0].nodes[0].value, '/*test comment*/');
  5. t.deepEqual(tree.nodes[0].nodes[1].value, 'h2');
  6. });
  7. (0, _helpers.test)('comments (2)', '.a /*test comment*/label', function (t, tree) {
  8. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  9. t.deepEqual(tree.nodes[0].nodes[1].type, 'combinator');
  10. t.deepEqual(tree.nodes[0].nodes[1].value, ' ');
  11. t.deepEqual(tree.nodes[0].nodes[1].spaces.after, ' ');
  12. t.deepEqual(tree.nodes[0].nodes[1].rawSpaceAfter, ' /*test comment*/');
  13. t.deepEqual(tree.nodes[0].nodes[2].type, 'tag');
  14. });
  15. (0, _helpers.test)('comments (3)', '.a /*test comment*/ label', function (t, tree) {
  16. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  17. t.deepEqual(tree.nodes[0].nodes[1].type, 'combinator');
  18. t.deepEqual(tree.nodes[0].nodes[1].value, ' ');
  19. t.deepEqual(tree.nodes[0].nodes[1].spaces.before, ' ');
  20. t.deepEqual(tree.nodes[0].nodes[1].rawSpaceBefore, ' /*test comment*/ ');
  21. t.deepEqual(tree.nodes[0].nodes[2].type, 'tag');
  22. });
  23. (0, _helpers.test)('multiple comments and other things', 'h1/*test*/h2/*test*/.test/*test*/', function (t, tree) {
  24. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag', 'should have a tag');
  25. t.deepEqual(tree.nodes[0].nodes[1].type, 'comment', 'should have a comment');
  26. t.deepEqual(tree.nodes[0].nodes[2].type, 'tag', 'should have a tag');
  27. t.deepEqual(tree.nodes[0].nodes[3].type, 'comment', 'should have a comment');
  28. t.deepEqual(tree.nodes[0].nodes[4].type, 'class', 'should have a class name');
  29. t.deepEqual(tree.nodes[0].nodes[5].type, 'comment', 'should have a comment');
  30. });
  31. (0, _helpers.test)('ending in comment', ".bar /* comment 3 */", function (t, tree) {
  32. var classname = tree.nodes[0].nodes[0];
  33. t.deepEqual(classname.type, 'class', 'should have a tag');
  34. t.deepEqual(classname.spaces.after, ' ');
  35. t.deepEqual(classname.raws.spaces.after, ' /* comment 3 */');
  36. });
  37. (0, _helpers.test)('comments in selector list', 'h2, /*test*/ h4', function (t, tree) {
  38. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
  39. t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');
  40. t.deepEqual(tree.nodes[1].nodes[0].rawSpaceBefore, ' ');
  41. t.deepEqual(tree.nodes[1].nodes[0].type, 'comment');
  42. t.deepEqual(tree.nodes[1].nodes[0].value, '/*test*/');
  43. t.deepEqual(tree.nodes[1].nodes[1].rawSpaceBefore, ' ');
  44. t.deepEqual(tree.nodes[1].nodes[1].type, 'tag');
  45. t.deepEqual(tree.nodes[1].nodes[1].value, 'h4');
  46. });
  47. (0, _helpers.test)('comments in selector list (2)', 'h2,/*test*/h4', function (t, tree) {
  48. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
  49. t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');
  50. t.deepEqual(tree.nodes[1].nodes[0].rawSpaceBefore, '');
  51. t.deepEqual(tree.nodes[1].nodes[0].type, 'comment');
  52. t.deepEqual(tree.nodes[1].nodes[0].value, '/*test*/');
  53. t.deepEqual(tree.nodes[1].nodes[1].type, 'tag');
  54. t.deepEqual(tree.nodes[1].nodes[1].value, 'h4');
  55. t.deepEqual(tree.nodes[1].nodes[1].rawSpaceBefore, '');
  56. });
  57. (0, _helpers.test)('comments in selector list (3)', 'h2/*test*/, h4', function (t, tree) {
  58. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
  59. t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');
  60. t.deepEqual(tree.nodes[0].nodes[1].rawSpaceBefore, '');
  61. t.deepEqual(tree.nodes[0].nodes[1].type, 'comment');
  62. t.deepEqual(tree.nodes[0].nodes[1].value, '/*test*/');
  63. t.deepEqual(tree.nodes[1].nodes[0].type, 'tag');
  64. t.deepEqual(tree.nodes[1].nodes[0].value, 'h4');
  65. t.deepEqual(tree.nodes[1].nodes[0].rawSpaceBefore, ' ');
  66. });
  67. (0, _helpers.test)('comments in selector list (4)', 'h2, /*test*/ /*test*/ h4', function (t, tree) {
  68. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
  69. t.deepEqual(tree.nodes[0].nodes[0].value, 'h2');
  70. t.deepEqual(tree.nodes[1].nodes[0].rawSpaceBefore, ' ');
  71. t.deepEqual(tree.nodes[1].nodes[0].type, 'comment');
  72. t.deepEqual(tree.nodes[1].nodes[0].value, '/*test*/');
  73. t.deepEqual(tree.nodes[1].nodes[1].rawSpaceBefore, ' ');
  74. t.deepEqual(tree.nodes[1].nodes[1].type, 'comment');
  75. t.deepEqual(tree.nodes[1].nodes[1].value, '/*test*/');
  76. t.deepEqual(tree.nodes[1].nodes[2].rawSpaceBefore, ' ');
  77. t.deepEqual(tree.nodes[1].nodes[2].type, 'tag');
  78. t.deepEqual(tree.nodes[1].nodes[2].value, 'h4');
  79. });