tests.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var normalize = require("./lib/normalize-selector.js");
  2. var tests = {
  3. /*test*/"#foo .bar":
  4. /*expected*/"#foo .bar",
  5. /*test*/" #foo .bar ":
  6. /*expected*/"#foo .bar",
  7. /*test*/"#foo>.bar":
  8. /*expected*/"#foo > .bar",
  9. /*test*/" unit[ sh | quantity = \"200\" ] ":
  10. /*expected*/"unit[sh|quantity=\"200\"]",
  11. /*test*/"*~*>*.foo[ href *= \"/\" ]:hover>*[ data-foo = \"bar\" ]:focus+*.baz::after":
  12. /*expected*/"* ~ * > *.foo[href*=\"/\"]:hover > *[data-foo=\"bar\"]:focus + *.baz::after",
  13. /*test*/"@media screen and ( color ), projection and ( color )":
  14. /*expected*/"@media screen and (color), projection and (color)",
  15. /*test*/"@media handheld and ( min-width : 20em ), screen and ( min-width: 20em )":
  16. /*expected*/"@media handheld and (min-width:20em), screen and (min-width:20em)",
  17. /*test*/"@media screen and ( device-aspect-ratio : 2560 / 1440 )":
  18. /*expected*/"@media screen and (device-aspect-ratio:2560/1440)",
  19. /*test*/"((a ) (b(c ) ) d )>*[ data-foo = \"bar\" ]":
  20. /*expected*/"((a)(b(c))d) > *[data-foo=\"bar\"]",
  21. /*test*/"#foo[ a = \" b \\\" c\\\\\" ]":
  22. /*expected*/"#foo[a=\" b \\\" c\\\\\"]",
  23. /*test*/"#foo[ a = \"b\" i ]":
  24. /*expected*/"#foo[a=\"b\" i]",
  25. /*test*/" /*c1*/ .e1/*c2*/.e2 /*c3*/ .e3 /*c4*/ ":
  26. /*expected*/".e1 .e2 .e3",
  27. /*test*/" /*c1*/ .e1/*c2*/.e2 /*c3*/ .e3 ":
  28. /*expected*/".e1 .e2 .e3",
  29. /*test*/" /*c1*/ .e1/*c2*/.e2 /*c3*/ .e3":
  30. /*expected*/".e1 .e2 .e3",
  31. /*test*/"/*c1*/.e1/*c2*/.e2 /*c3*/ .e3":
  32. /*expected*/".e1 .e2 .e3",
  33. /*test*/".e1/*c2*/.e2 /*c3*/ .e3":
  34. /*expected*/".e1 .e2 .e3"
  35. };
  36. var test, tmp;
  37. for (test in tests) {
  38. if ((tmp = normalize(test)) && tmp === tests[test]) {
  39. console.log("PASSED: " + test + " (" + tmp + ")");
  40. }
  41. else {
  42. console.log("FAILED.\n Expected: " + tests[test] + "\n Received: " + tmp);
  43. break;
  44. }
  45. }
  46. console.log("Tests done.");