namespaces.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. var _helpers = require("./util/helpers");
  3. (0, _helpers.test)('match tags in the postcss namespace', 'postcss|button', function (t, tree) {
  4. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
  5. t.deepEqual(tree.nodes[0].nodes[0].value, 'button');
  6. });
  7. (0, _helpers.test)('match everything in the postcss namespace', 'postcss|*', function (t, tree) {
  8. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
  9. t.deepEqual(tree.nodes[0].nodes[0].value, '*');
  10. });
  11. (0, _helpers.test)('match any namespace', '*|button', function (t, tree) {
  12. t.deepEqual(tree.nodes[0].nodes[0].namespace, '*');
  13. t.deepEqual(tree.nodes[0].nodes[0].value, 'button');
  14. });
  15. (0, _helpers.test)('match all elements within the postcss namespace', 'postcss|*', function (t, tree) {
  16. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
  17. t.deepEqual(tree.nodes[0].nodes[0].value, '*');
  18. });
  19. (0, _helpers.test)('match all elements in all namespaces', '*|*', function (t, tree) {
  20. t.deepEqual(tree.nodes[0].nodes[0].namespace, '*');
  21. t.deepEqual(tree.nodes[0].nodes[0].value, '*');
  22. });
  23. (0, _helpers.test)('match all elements without a namespace', '|*', function (t, tree) {
  24. t.deepEqual(tree.nodes[0].nodes[0].namespace, true);
  25. t.deepEqual(tree.nodes[0].nodes[0].value, '*');
  26. });
  27. (0, _helpers.test)('match tags with no namespace', '|button', function (t, tree) {
  28. t.deepEqual(tree.nodes[0].nodes[0].namespace, true);
  29. t.deepEqual(tree.nodes[0].nodes[0].value, 'button');
  30. });
  31. (0, _helpers.test)('match namespace inside attribute selector', '[postcss|href=test]', function (t, tree) {
  32. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
  33. t.deepEqual(tree.nodes[0].nodes[0].value, 'test');
  34. });
  35. (0, _helpers.test)('match namespace inside attribute selector (2)', '[postcss|href]', function (t, tree) {
  36. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'postcss');
  37. t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
  38. });
  39. (0, _helpers.test)('match namespace inside attribute selector (3)', '[*|href]', function (t, tree) {
  40. t.deepEqual(tree.nodes[0].nodes[0].namespace, '*');
  41. t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
  42. });
  43. (0, _helpers.test)('match default namespace inside attribute selector', '[|href]', function (t, tree) {
  44. t.deepEqual(tree.nodes[0].nodes[0].namespace, true);
  45. t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
  46. });
  47. (0, _helpers.test)('match default namespace inside attribute selector with spaces', '[ |href ]', function (t, tree) {
  48. t.deepEqual(tree.nodes[0].nodes[0].namespace, true);
  49. t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href');
  50. });
  51. (0, _helpers.test)('namespace with qualified id selector', 'ns|h1#foo', function (t, tree) {
  52. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'ns');
  53. });
  54. (0, _helpers.test)('namespace with qualified class selector', 'ns|h1.foo', function (t, tree) {
  55. t.deepEqual(tree.nodes[0].nodes[0].namespace, 'ns');
  56. });
  57. (0, _helpers.test)('ns alias for namespace', 'f\\oo|h1.foo', function (t, tree) {
  58. var tag = tree.nodes[0].nodes[0];
  59. t.deepEqual(tag.namespace, 'foo');
  60. t.deepEqual(tag.ns, 'foo');
  61. tag.ns = "bar";
  62. t.deepEqual(tag.namespace, 'bar');
  63. t.deepEqual(tag.ns, 'bar');
  64. });