.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / normalize-selector / test / mocha / suite.js
1 // mocha/suite.js for normalize-selector.js
2
3 var normalizeSelector;
4 var assert;
5
6 if (typeof require == 'function') {
7   // enable to re-use in a browser without require.js
8   normalizeSelector = require('../../lib/normalize-selector.js');
9   assert = require('assertik');
10 } else {
11   assert = window.assertik;
12 }
13
14 suite('normalizeSelector');
15
16 test('should be function', function () {
17   assert.equal(typeof normalizeSelector, 'function', 'wrong type');
18 });
19
20 test('should normalize BIG SELECTOR', function () {
21   var selector = "*~*>*.foo[   href *=  \"/\"   ]:hover>*[  data-foo =   " +
22                  "\"bar\"      ]:focus+*.baz::after";
23   var expected = "* ~ * > *.foo[href*=\"/\"]:hover > *[data-foo=\"bar\"]:" +
24                  "focus + *.baz::after";
25   assert.equal(normalizeSelector(selector), expected);
26 });
27
28 test('should return optimized selector with no change', function () {
29   assert.equal(normalizeSelector("#foo .bar"), "#foo .bar");
30 });
31
32 test('should trim whitespace', function () {
33   assert.equal(normalizeSelector(" #foo   .bar "), "#foo .bar");
34 });
35
36 test('should separate between combinators', function () {
37   assert.equal(normalizeSelector("#foo>.bar+.baz"), "#foo > .bar + .baz");
38 });
39
40 test('should not separate concatenated classes', function () {
41   assert.equal(normalizeSelector("#foo.bar.baz"), "#foo.bar.baz");
42 });
43
44 test('should normalize asterisks', function () {
45   var selector = " *.class[ data * = 'data' ] ";
46   assert.equal(normalizeSelector(selector), "*.class[data*='data']");
47 });
48
49 test('should remove comments', function () {
50   assert.equal(normalizeSelector(".e1 /* c2 */ .e2"), ".e1 .e2");
51   assert.equal(normalizeSelector(" /*c1*/ .e1/*c2*/.e2 /*c3*/ .e3 /*c4*/ "), ".e1 .e2 .e3");
52   assert.equal(normalizeSelector(" /*c1*/ .e1/*c2*/.e2 /*c3*/ .e3 "), ".e1 .e2 .e3");
53   assert.equal(normalizeSelector("/*c1*/.e1/*c2*/.e2 /*c3*/ .e3"), ".e1 .e2 .e3");
54   assert.equal(normalizeSelector(".e1/*c2*/.e2 /*c3*/ .e3"), ".e1 .e2 .e3");
55 });
56
57 test('should replace comments with single whitespace', function () {
58   assert.equal(normalizeSelector("tag/* c2 */tag"), "tag tag");
59 });
60
61 test('should normalize parentheses', function() {
62   var selector = "((a ) (b(c ) ) d )>*[ data-foo = \"bar\" ]";
63   var expected = "((a)(b(c))d) > *[data-foo=\"bar\"]";
64   assert.equal(normalizeSelector(selector), expected);
65 });
66
67 test('should normalize @-rule parentheses', function () {
68   var selector = "@media  screen  and  ( color ),  projection  and  (color )";
69   var expected = "@media screen and (color), projection and (color)";
70   assert.equal(normalizeSelector(selector), expected);
71 });
72
73 test('should normalize @-rules with compound parentheses', function () {
74   var selector = "@media  handheld  and  ( min-width : 20em ),   screen  " +
75                  "and  ( min-width: 20em )";
76   var expected = "@media handheld and (min-width:20em), screen and " +
77                  "(min-width:20em)";
78   assert.equal(normalizeSelector(selector), expected);
79 });
80
81 test('should normalize @-rules with operations', function () {
82   var selector = "@media  screen  and  ( device-aspect-ratio : 2560 / 1440 )";
83   var expected = "@media screen and (device-aspect-ratio:2560/1440)";
84   assert.equal(normalizeSelector(selector), expected);
85 });
86
87 test('should normalize descriptors', function () {
88   var selector = "@counter-style    triangle";
89   assert.equal(normalizeSelector(selector), "@counter-style triangle");
90 });
91
92 test('should normalize case-insensitivity attribute selector', function () {
93   assert.equal(normalizeSelector("[ att ~= val  i ]"), "[att~=val i]");
94   assert.equal(normalizeSelector("#foo[  a  =  \"b\"  i  ]"), "#foo[a=\"b\" i]");
95 });
96
97 test('should normalize namespaced attribute selector', function () {
98   var selector = ' unit[ sh | quantity = "200" ] ';
99   var expected = 'unit[sh|quantity="200"]';
100   assert.equal(normalizeSelector(selector), expected);
101 });
102
103 test('should normalize pseudo-classes', function () {
104   var selector = "   :nth-last-of-type( )   ";
105   assert.equal(normalizeSelector(selector), ":nth-last-of-type()");
106 });
107
108 test('should normalize pseudo-elements', function () {
109   var selector = "   ::nth-fragment(   )   ";
110   assert.equal(normalizeSelector(selector), "::nth-fragment()");
111 });
112
113 test('should normalize backslashes', function () {
114   var selector = "#foo[ a = \" b \\\" c\\\\\" ]";
115   var expected = "#foo[a=\" b \\\" c\\\\\"]";
116   assert.equal(normalizeSelector(selector), expected);
117 });