id.js 12 KB

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