classes.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. "use strict";
  2. var _helpers = require("./util/helpers");
  3. (0, _helpers.test)('class name', '.one', function (t, tree) {
  4. t.deepEqual(tree.nodes[0].nodes[0].value, 'one');
  5. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  6. });
  7. (0, _helpers.test)('multiple class names', '.one.two.three', function (t, tree) {
  8. t.deepEqual(tree.nodes[0].nodes[0].value, 'one');
  9. t.deepEqual(tree.nodes[0].nodes[1].value, 'two');
  10. t.deepEqual(tree.nodes[0].nodes[2].value, 'three');
  11. });
  12. (0, _helpers.test)('qualified class', 'button.btn-primary', function (t, tree) {
  13. t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');
  14. t.deepEqual(tree.nodes[0].nodes[1].type, 'class');
  15. });
  16. (0, _helpers.test)('escaped numbers in class name', '.\\31\\ 0', function (t, tree) {
  17. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  18. t.deepEqual(tree.nodes[0].nodes[0].value, '1 0');
  19. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\31\\ 0');
  20. });
  21. (0, _helpers.test)('extraneous non-combinating whitespace', ' .h1 , .h2 ', function (t, tree) {
  22. t.deepEqual(tree.nodes[0].nodes[0].value, 'h1');
  23. t.deepEqual(tree.nodes[0].nodes[0].spaces.before, ' ');
  24. t.deepEqual(tree.nodes[0].nodes[0].spaces.after, ' ');
  25. t.deepEqual(tree.nodes[1].nodes[0].value, 'h2');
  26. t.deepEqual(tree.nodes[1].nodes[0].spaces.before, ' ');
  27. t.deepEqual(tree.nodes[1].nodes[0].spaces.after, ' ');
  28. });
  29. (0, _helpers.test)('Less interpolation within a class', '.foo@{bar}', function (t, tree) {
  30. t.deepEqual(tree.nodes[0].nodes.length, 1);
  31. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  32. t.deepEqual(tree.nodes[0].nodes[0].value, 'foo@{bar}');
  33. });
  34. (0, _helpers.test)('ClassName#set value', ".fo\\o", function (t, selectors) {
  35. var className = selectors.first.first;
  36. t.deepEqual(className.raws, {
  37. value: "fo\\o"
  38. });
  39. className.value = "bar";
  40. t.deepEqual(className.raws, {});
  41. });
  42. (0, _helpers.test)('escaped dot in class name', '.foo\\.bar', function (t, tree) {
  43. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  44. t.deepEqual(tree.nodes[0].nodes[0].value, 'foo.bar');
  45. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'foo\\.bar');
  46. });
  47. (0, _helpers.test)('class selector with escaping', '.♥', function (t, tree) {
  48. t.deepEqual(tree.nodes[0].nodes[0].value, '♥');
  49. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  50. });
  51. (0, _helpers.test)('class selector with escaping (1)', '.©', function (t, tree) {
  52. t.deepEqual(tree.nodes[0].nodes[0].value, '©');
  53. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  54. });
  55. (0, _helpers.test)('class selector with escaping (2)', '.“‘’”', function (t, tree) {
  56. t.deepEqual(tree.nodes[0].nodes[0].value, '“‘’”');
  57. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  58. });
  59. (0, _helpers.test)('class selector with escaping (3)', '.☺☃', function (t, tree) {
  60. t.deepEqual(tree.nodes[0].nodes[0].value, '☺☃');
  61. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  62. });
  63. (0, _helpers.test)('class selector with escaping (4)', '.⌘⌥', function (t, tree) {
  64. t.deepEqual(tree.nodes[0].nodes[0].value, '⌘⌥');
  65. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  66. });
  67. (0, _helpers.test)('class selector with escaping (5)', '.𝄞♪♩♫♬', function (t, tree) {
  68. t.deepEqual(tree.nodes[0].nodes[0].value, '𝄞♪♩♫♬');
  69. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  70. });
  71. (0, _helpers.test)('class selector with escaping (6)', '.💩', function (t, tree) {
  72. t.deepEqual(tree.nodes[0].nodes[0].value, '💩');
  73. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  74. });
  75. (0, _helpers.test)('class selector with escaping (7)', '.\\?', function (t, tree) {
  76. t.deepEqual(tree.nodes[0].nodes[0].value, '?');
  77. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  78. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\?');
  79. });
  80. (0, _helpers.test)('class selector with escaping (8)', '.\\@', function (t, tree) {
  81. t.deepEqual(tree.nodes[0].nodes[0].value, '@');
  82. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  83. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\@');
  84. });
  85. (0, _helpers.test)('class selector with escaping (9)', '.\\.', function (t, tree) {
  86. t.deepEqual(tree.nodes[0].nodes[0].value, '.');
  87. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  88. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\.');
  89. });
  90. (0, _helpers.test)('class selector with escaping (10)', '.\\3A \\)', function (t, tree) {
  91. t.deepEqual(tree.nodes[0].nodes[0].value, ':)');
  92. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  93. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\3A \\)');
  94. });
  95. (0, _helpers.test)('class selector with escaping (11)', '.\\3A \\`\\(', function (t, tree) {
  96. t.deepEqual(tree.nodes[0].nodes[0].value, ':`(');
  97. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  98. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\3A \\`\\(');
  99. });
  100. (0, _helpers.test)('class selector with escaping (12)', '.\\31 23', function (t, tree) {
  101. t.deepEqual(tree.nodes[0].nodes[0].value, '123');
  102. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  103. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\31 23');
  104. });
  105. (0, _helpers.test)('class selector with escaping (13)', '.\\31 a2b3c', function (t, tree) {
  106. t.deepEqual(tree.nodes[0].nodes[0].value, '1a2b3c');
  107. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  108. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\31 a2b3c');
  109. });
  110. (0, _helpers.test)('class selector with escaping (14)', '.\\<p\\>', function (t, tree) {
  111. t.deepEqual(tree.nodes[0].nodes[0].value, '<p>');
  112. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  113. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\<p\\>');
  114. });
  115. (0, _helpers.test)('class selector with escaping (15)', '.\\<\\>\\<\\<\\<\\>\\>\\<\\>', function (t, tree) {
  116. t.deepEqual(tree.nodes[0].nodes[0].value, '<><<<>><>');
  117. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  118. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\<\\>\\<\\<\\<\\>\\>\\<\\>');
  119. });
  120. (0, _helpers.test)('class selector with escaping (16)', '.\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\[\\>\\+\\+\\+\\+\\+\\+\\+\\>\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\>\\+\\+\\+\\>\\+\\<\\<\\<\\<\\-\\]\\>\\+\\+\\.\\>\\+\\.\\+\\+\\+\\+\\+\\+\\+\\.\\.\\+\\+\\+\\.\\>\\+\\+\\.\\<\\<\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\.\\>\\.\\+\\+\\+\\.\\-\\-\\-\\-\\-\\-\\.\\-\\-\\-\\-\\-\\-\\-\\-\\.\\>\\+\\.\\>\\.', function (t, tree) {
  121. t.deepEqual(tree.nodes[0].nodes[0].value, '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.');
  122. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  123. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\[\\>\\+\\+\\+\\+\\+\\+\\+\\>\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\>\\+\\+\\+\\>\\+\\<\\<\\<\\<\\-\\]\\>\\+\\+\\.\\>\\+\\.\\+\\+\\+\\+\\+\\+\\+\\.\\.\\+\\+\\+\\.\\>\\+\\+\\.\\<\\<\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\+\\.\\>\\.\\+\\+\\+\\.\\-\\-\\-\\-\\-\\-\\.\\-\\-\\-\\-\\-\\-\\-\\-\\.\\>\\+\\.\\>\\.');
  124. });
  125. (0, _helpers.test)('class selector with escaping (17)', '.\\#', function (t, tree) {
  126. t.deepEqual(tree.nodes[0].nodes[0].value, '#');
  127. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  128. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\#');
  129. });
  130. (0, _helpers.test)('class selector with escaping (18)', '.\\#\\#', function (t, tree) {
  131. t.deepEqual(tree.nodes[0].nodes[0].value, '##');
  132. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  133. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\#\\#');
  134. });
  135. (0, _helpers.test)('class selector with escaping (19)', '.\\#\\.\\#\\.\\#', function (t, tree) {
  136. t.deepEqual(tree.nodes[0].nodes[0].value, '#.#.#');
  137. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  138. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\#\\.\\#\\.\\#');
  139. });
  140. (0, _helpers.test)('class selector with escaping (20)', '.\\_', function (t, tree) {
  141. t.deepEqual(tree.nodes[0].nodes[0].value, '_');
  142. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  143. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\_');
  144. });
  145. (0, _helpers.test)('class selector with escaping (21)', '.\\{\\}', function (t, tree) {
  146. t.deepEqual(tree.nodes[0].nodes[0].value, '{}');
  147. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  148. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\{\\}');
  149. });
  150. (0, _helpers.test)('class selector with escaping (22)', '.\\#fake\\-id', function (t, tree) {
  151. t.deepEqual(tree.nodes[0].nodes[0].value, '#fake-id');
  152. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  153. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\#fake\\-id');
  154. });
  155. (0, _helpers.test)('class selector with escaping (23)', '.foo\\.bar', function (t, tree) {
  156. t.deepEqual(tree.nodes[0].nodes[0].value, 'foo.bar');
  157. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  158. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'foo\\.bar');
  159. });
  160. (0, _helpers.test)('class selector with escaping (24)', '.\\3A hover', function (t, tree) {
  161. t.deepEqual(tree.nodes[0].nodes[0].value, ':hover');
  162. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  163. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\3A hover');
  164. });
  165. (0, _helpers.test)('class selector with escaping (25)', '.\\3A hover\\3A focus\\3A active', function (t, tree) {
  166. t.deepEqual(tree.nodes[0].nodes[0].value, ':hover:focus:active');
  167. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  168. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\3A hover\\3A focus\\3A active');
  169. });
  170. (0, _helpers.test)('class selector with escaping (26)', '.\\[attr\\=value\\]', function (t, tree) {
  171. t.deepEqual(tree.nodes[0].nodes[0].value, '[attr=value]');
  172. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  173. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\[attr\\=value\\]');
  174. });
  175. (0, _helpers.test)('class selector with escaping (27)', '.f\\/o\\/o', function (t, tree) {
  176. t.deepEqual(tree.nodes[0].nodes[0].value, 'f/o/o');
  177. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  178. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\/o\\/o');
  179. });
  180. (0, _helpers.test)('class selector with escaping (28)', '.f\\\\o\\\\o', function (t, tree) {
  181. t.deepEqual(tree.nodes[0].nodes[0].value, 'f\\o\\o');
  182. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  183. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\\\o\\\\o');
  184. });
  185. (0, _helpers.test)('class selector with escaping (29)', '.f\\*o\\*o', function (t, tree) {
  186. t.deepEqual(tree.nodes[0].nodes[0].value, 'f*o*o');
  187. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  188. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\*o\\*o');
  189. });
  190. (0, _helpers.test)('class selector with escaping (30)', '.f\\!o\\!o', function (t, tree) {
  191. t.deepEqual(tree.nodes[0].nodes[0].value, 'f!o!o');
  192. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  193. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\!o\\!o');
  194. });
  195. (0, _helpers.test)('class selector with escaping (31)', '.f\\\'o\\\'o', function (t, tree) {
  196. t.deepEqual(tree.nodes[0].nodes[0].value, 'f\'o\'o');
  197. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  198. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\\'o\\\'o');
  199. });
  200. (0, _helpers.test)('class selector with escaping (32)', '.f\\~o\\~o', function (t, tree) {
  201. t.deepEqual(tree.nodes[0].nodes[0].value, 'f~o~o');
  202. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  203. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\~o\\~o');
  204. });
  205. (0, _helpers.test)('class selector with escaping (33)', '.f\\+o\\+o', function (t, tree) {
  206. t.deepEqual(tree.nodes[0].nodes[0].value, 'f+o+o');
  207. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  208. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'f\\+o\\+o');
  209. });
  210. (0, _helpers.test)('class selector with escaping (34)', '.\\1D306', function (t, tree) {
  211. t.deepEqual(tree.nodes[0].nodes[0].value, '𝌆');
  212. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  213. t.deepEqual(tree.nodes[0].nodes[0].raws.value, '\\1D306');
  214. });
  215. (0, _helpers.test)('class selector with escaping (35)', '.not-pseudo\\:focus', function (t, tree) {
  216. t.deepEqual(tree.nodes[0].nodes[0].value, 'not-pseudo:focus');
  217. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  218. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'not-pseudo\\:focus');
  219. });
  220. (0, _helpers.test)('class selector with escaping (36)', '.not-pseudo\\:\\:focus', function (t, tree) {
  221. t.deepEqual(tree.nodes[0].nodes[0].value, 'not-pseudo::focus');
  222. t.deepEqual(tree.nodes[0].nodes[0].type, 'class');
  223. t.deepEqual(tree.nodes[0].nodes[0].raws.value, 'not-pseudo\\:\\:focus');
  224. });