How to use nodes method in Best

Best JavaScript code snippet using best

sourceIndex.js

Source:sourceIndex.js Github

copy

Full Screen

1"use strict";2var _helpers = require("./util/helpers");3(0, _helpers.test)('universal selector', '*', function (t, tree) {4 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);5 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 1);6 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);7});8(0, _helpers.test)('lobotomized owl selector', ' * + * ', function (t, tree) {9 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 2);10 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 2);11 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 1);12 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 4);13 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 4);14 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 3);15 t.deepEqual(tree.nodes[0].nodes[2].source.start.column, 6);16 t.deepEqual(tree.nodes[0].nodes[2].source.end.column, 6);17 t.deepEqual(tree.nodes[0].nodes[2].sourceIndex, 5);18});19(0, _helpers.test)('comment', '/**\n * Hello!\n */', function (t, tree) {20 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);21 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 3);22 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);23});24(0, _helpers.test)('comment & universal selectors', '*/*test*/*', function (t, tree) {25 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);26 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 1);27 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);28 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 2);29 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 9);30 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 1);31 t.deepEqual(tree.nodes[0].nodes[2].source.start.column, 10);32 t.deepEqual(tree.nodes[0].nodes[2].source.end.column, 10);33 t.deepEqual(tree.nodes[0].nodes[2].sourceIndex, 9);34});35(0, _helpers.test)('tag selector', 'h1', function (t, tree) {36 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);37 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 2);38 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);39});40(0, _helpers.test)('id selector', '#id', function (t, tree) {41 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);42 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 3);43 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);44});45(0, _helpers.test)('tag selector followed by id selector', 'h1, #id', function (t, tree) {46 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);47 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 2);48 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);49 t.deepEqual(tree.nodes[1].nodes[0].source.start.column, 5);50 t.deepEqual(tree.nodes[1].nodes[0].source.end.column, 7);51 t.deepEqual(tree.nodes[1].nodes[0].sourceIndex, 4);52});53(0, _helpers.test)('multiple id selectors', '#one#two', function (t, tree) {54 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);55 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 4);56 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);57 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 5);58 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 8);59 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 4);60});61(0, _helpers.test)('multiple id selectors (2)', '#one#two#three#four', function (t, tree) {62 t.deepEqual(tree.nodes[0].nodes[2].source.start.column, 9);63 t.deepEqual(tree.nodes[0].nodes[2].source.end.column, 14);64 t.deepEqual(tree.nodes[0].nodes[2].sourceIndex, 8);65 t.deepEqual(tree.nodes[0].nodes[3].source.start.column, 15);66 t.deepEqual(tree.nodes[0].nodes[3].source.end.column, 19);67 t.deepEqual(tree.nodes[0].nodes[3].sourceIndex, 14);68});69(0, _helpers.test)('multiple id selectors (3)', '#one#two,#three#four', function (t, tree) {70 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 5);71 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 8);72 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 4);73 t.deepEqual(tree.nodes[1].nodes[1].source.start.column, 16);74 t.deepEqual(tree.nodes[1].nodes[1].source.end.column, 20);75 t.deepEqual(tree.nodes[1].nodes[1].sourceIndex, 15);76});77(0, _helpers.test)('multiple class selectors', '.one.two,.three.four', function (t, tree) {78 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 5);79 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 8);80 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 4);81 t.deepEqual(tree.nodes[1].nodes[1].source.start.column, 16);82 t.deepEqual(tree.nodes[1].nodes[1].source.end.column, 20);83 t.deepEqual(tree.nodes[1].nodes[1].sourceIndex, 15);84});85(0, _helpers.test)('attribute selector', '[name="james"]', function (t, tree) {86 t.deepEqual(tree.nodes[0].nodes[0].source.start.line, 1);87 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);88 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 14);89 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);90});91(0, _helpers.test)('multiple attribute selectors', '[name="james"][name="ed"],[name="snakeman"][name="a"]', function (t, tree) {92 t.deepEqual(tree.nodes[0].nodes[0].source.start.line, 1);93 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);94 t.deepEqual(tree.nodes[0].nodes[0].source.end.line, 1);95 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 14);96 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);97 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1);98 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 15);99 t.deepEqual(tree.nodes[0].nodes[1].source.end.line, 1);100 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 25);101 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 14);102 t.deepEqual(tree.nodes[1].nodes[0].source.start.line, 1);103 t.deepEqual(tree.nodes[1].nodes[0].source.start.column, 27);104 t.deepEqual(tree.nodes[1].nodes[0].source.end.line, 1);105 t.deepEqual(tree.nodes[1].nodes[0].source.end.column, 43);106 t.deepEqual(tree.nodes[1].nodes[0].sourceIndex, 26);107 t.deepEqual(tree.nodes[1].nodes[1].source.start.line, 1);108 t.deepEqual(tree.nodes[1].nodes[1].source.start.column, 44);109 t.deepEqual(tree.nodes[1].nodes[1].source.end.line, 1);110 t.deepEqual(tree.nodes[1].nodes[1].source.end.column, 53);111 t.deepEqual(tree.nodes[1].nodes[1].sourceIndex, 43);112});113(0, _helpers.test)('pseudo-class', 'h1:first-child', function (t, tree) {114 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1);115 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 3);116 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 14);117 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 2);118});119(0, _helpers.test)('pseudo-class with argument', 'h1:not(.strudel, .food)', function (t, tree) {120 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1);121 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 3);122 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 23);123 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 2);124});125(0, _helpers.test)('pseudo-element', 'h1::before', function (t, tree) {126 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1);127 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 3);128 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 10);129 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 2);130});131(0, _helpers.test)('multiple pseudos', 'h1:not(.food)::before, a:first-child', function (t, tree) {132 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1);133 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 3);134 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 13);135 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 2);136 t.deepEqual(tree.nodes[0].nodes[2].source.start.line, 1);137 t.deepEqual(tree.nodes[0].nodes[2].source.start.column, 14);138 t.deepEqual(tree.nodes[0].nodes[2].source.end.column, 21);139 t.deepEqual(tree.nodes[0].nodes[2].sourceIndex, 13);140 t.deepEqual(tree.nodes[1].nodes[1].source.start.line, 1);141 t.deepEqual(tree.nodes[1].nodes[1].source.start.column, 25);142 t.deepEqual(tree.nodes[1].nodes[1].source.end.column, 36);143 t.deepEqual(tree.nodes[1].nodes[1].sourceIndex, 24);144});145(0, _helpers.test)('combinators', 'div > h1 span', function (t, tree) {146 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1, "> start line");147 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 5, "> start column");148 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 5, "> end column");149 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 4, "> sourceIndex");150 t.deepEqual(tree.nodes[0].nodes[3].source.start.line, 1, "' ' start line");151 t.deepEqual(tree.nodes[0].nodes[3].source.start.column, 9, "' ' start column");152 t.deepEqual(tree.nodes[0].nodes[3].source.end.column, 9, "' ' end column");153 t.deepEqual(tree.nodes[0].nodes[3].sourceIndex, 8, "' ' sourceIndex");154});155(0, _helpers.test)('combinators surrounded by superfluous spaces', 'div > h1 ~ span a', function (t, tree) {156 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1, "> start line");157 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 7, "> start column");158 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 7, "> end column");159 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 6, "> sourceIndex");160 t.deepEqual(tree.nodes[0].nodes[3].source.start.line, 1, "~ start line");161 t.deepEqual(tree.nodes[0].nodes[3].source.start.column, 13, "~ start column");162 t.deepEqual(tree.nodes[0].nodes[3].source.end.column, 13, "~ end column");163 t.deepEqual(tree.nodes[0].nodes[3].sourceIndex, 12, "~ sourceIndex");164 t.deepEqual(tree.nodes[0].nodes[5].source.start.line, 1, "' ' start line");165 t.deepEqual(tree.nodes[0].nodes[5].source.start.column, 21, "' ' start column");166 t.deepEqual(tree.nodes[0].nodes[5].source.end.column, 23, "' ' end column");167 t.deepEqual(tree.nodes[0].nodes[5].sourceIndex, 20, "' ' sourceIndex");168});169(0, _helpers.test)('multiple id selectors on different lines', '#one,\n#two', function (t, tree) {170 t.deepEqual(tree.nodes[0].nodes[0].source.start.line, 1);171 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1);172 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 4);173 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0);174 t.deepEqual(tree.nodes[1].nodes[0].source.start.line, 2);175 t.deepEqual(tree.nodes[1].nodes[0].source.start.column, 1);176 t.deepEqual(tree.nodes[1].nodes[0].source.end.column, 4);177 t.deepEqual(tree.nodes[1].nodes[0].sourceIndex, 6);178});179(0, _helpers.test)('multiple id selectors on different CRLF lines', '#one,\r\n#two,\r\n#three', function (t, tree) {180 t.deepEqual(tree.nodes[0].nodes[0].source.start.line, 1, '#one start line');181 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 1, '#one start column');182 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 4, '#one end column');183 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 0, '#one sourceIndex');184 t.deepEqual(tree.nodes[1].nodes[0].source.start.line, 2, '#two start line');185 t.deepEqual(tree.nodes[1].nodes[0].source.start.column, 1, '#two start column');186 t.deepEqual(tree.nodes[1].nodes[0].source.end.column, 4, '#two end column');187 t.deepEqual(tree.nodes[1].nodes[0].sourceIndex, 7, '#two sourceIndex');188 t.deepEqual(tree.nodes[2].nodes[0].source.start.line, 3, '#three start line');189 t.deepEqual(tree.nodes[2].nodes[0].source.start.column, 1, '#three start column');190 t.deepEqual(tree.nodes[2].nodes[0].source.end.column, 6, '#three end column');191 t.deepEqual(tree.nodes[2].nodes[0].sourceIndex, 14, '#three sourceIndex');192});193(0, _helpers.test)('id, tag, pseudo, and class selectors on different lines with indentation', '\t#one,\n\th1:after,\n\t\t.two', function (t, tree) {194 t.deepEqual(tree.nodes[0].nodes[0].source.start.line, 1, '#one start line');195 t.deepEqual(tree.nodes[0].nodes[0].source.start.column, 2, '#one start column');196 t.deepEqual(tree.nodes[0].nodes[0].source.end.column, 5, '#one end column');197 t.deepEqual(tree.nodes[0].nodes[0].sourceIndex, 1, '#one sourceIndex');198 t.deepEqual(tree.nodes[1].nodes[0].source.start.line, 2, 'h1 start line');199 t.deepEqual(tree.nodes[1].nodes[0].source.start.column, 2, 'h1 start column');200 t.deepEqual(tree.nodes[1].nodes[0].source.end.column, 3, 'h1 end column');201 t.deepEqual(tree.nodes[1].nodes[0].sourceIndex, 8, 'h1 sourceIndex');202 t.deepEqual(tree.nodes[1].nodes[1].source.start.line, 2, ':after start line');203 t.deepEqual(tree.nodes[1].nodes[1].source.start.column, 4, ':after start column');204 t.deepEqual(tree.nodes[1].nodes[1].source.end.column, 9, ':after end column');205 t.deepEqual(tree.nodes[1].nodes[1].sourceIndex, 10, ':after sourceIndex');206 t.deepEqual(tree.nodes[2].nodes[0].source.start.line, 3, '.two start line');207 t.deepEqual(tree.nodes[2].nodes[0].source.start.column, 3, '.two start column');208 t.deepEqual(tree.nodes[2].nodes[0].source.end.column, 6, '.two end column');209 t.deepEqual(tree.nodes[2].nodes[0].sourceIndex, 20, '.two sourceIndex');210});211(0, _helpers.test)('pseudo with arguments spanning multiple lines', 'h1:not(\n\t.one,\n\t.two\n)', function (t, tree) {212 t.deepEqual(tree.nodes[0].nodes[1].source.start.line, 1, ':not start line');213 t.deepEqual(tree.nodes[0].nodes[1].source.start.column, 3, ':not start column');214 t.deepEqual(tree.nodes[0].nodes[1].source.end.line, 4, ':not end line');215 t.deepEqual(tree.nodes[0].nodes[1].source.end.column, 1, ':not end column');216 t.deepEqual(tree.nodes[0].nodes[1].sourceIndex, 2, ':not sourceIndex');217 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].source.start.line, 2, '.one start line');218 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].source.start.column, 2, '.one start column');219 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].source.end.line, 2, '.one end line');220 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].source.end.column, 5, '.one end column');221 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].sourceIndex, 9, '.one sourceIndex');222 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].source.start.line, 3, '.two start line');223 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].source.start.column, 2, '.two start column');224 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].source.end.line, 3, '.two end line');225 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].source.end.column, 5, '.two end column');226 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].sourceIndex, 16, '.two sourceIndex');...

Full Screen

Full Screen

id.js

Source:id.js Github

copy

Full Screen

1"use strict";2var _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');...

Full Screen

Full Screen

pseudos.js

Source:pseudos.js Github

copy

Full Screen

1"use strict";2var _helpers = require("./util/helpers");3(0, _helpers.test)('pseudo element (single colon)', 'h1:after', function (t, tree) {4 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');5 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');6 t.deepEqual(tree.nodes[0].nodes[1].value, ':after');7});8(0, _helpers.test)('pseudo element (double colon)', 'h1::after', function (t, tree) {9 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');10 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');11 t.deepEqual(tree.nodes[0].nodes[1].value, '::after');12});13(0, _helpers.test)('multiple pseudo elements', '*:target::before, a:after', function (t, tree) {14 t.deepEqual(tree.nodes[0].nodes[0].value, '*');15 t.deepEqual(tree.nodes[0].nodes[1].value, ':target');16 t.deepEqual(tree.nodes[0].nodes[2].value, '::before');17 t.deepEqual(tree.nodes[1].nodes[1].value, ':after');18});19(0, _helpers.test)('negation pseudo element', 'h1:not(.heading)', function (t, tree) {20 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');21 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, 'heading');22});23(0, _helpers.test)('negation pseudo element (2)', 'h1:not(.heading, .title, .content)', function (t, tree) {24 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');25 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, 'heading');26 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].value, 'title');27 t.deepEqual(tree.nodes[0].nodes[1].nodes[2].nodes[0].value, 'content');28});29(0, _helpers.test)('negation pseudo element (3)', 'h1:not(.heading > .title) > h1', function (t, tree) {30 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, 'heading');31 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[1].value, '>');32 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[2].value, 'title');33 t.deepEqual(tree.nodes[0].nodes[2].value, '>');34 t.deepEqual(tree.nodes[0].nodes[3].value, 'h1');35});36(0, _helpers.test)('negation pseudo element (4)', 'h1:not(h2:not(h3))', function (t, tree) {37 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[1].nodes[0].nodes[0].value, 'h3');38 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[1].nodes[0].nodes[0].parent.type, 'selector');39});40(0, _helpers.test)('pseudo class in the middle of a selector', 'a:link.external', function (t, tree) {41 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');42 t.deepEqual(tree.nodes[0].nodes[0].value, 'a');43 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');44 t.deepEqual(tree.nodes[0].nodes[1].value, ':link');45 t.deepEqual(tree.nodes[0].nodes[2].type, 'class');46 t.deepEqual(tree.nodes[0].nodes[2].value, 'external');47});48(0, _helpers.test)('extra whitespace inside parentheses', 'a:not( h2 )', function (t, tree) {49 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, 'h2');50 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].spaces.after, ' ');51 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].spaces.before, ' ');52});53(0, _helpers.test)('escaped numbers in class name with pseudo', 'a:before.\\31\\ 0', function (t, tree) {54 t.deepEqual(tree.nodes[0].nodes[2].type, 'class');55 t.deepEqual(tree.nodes[0].nodes[2].value, '1 0');56 t.deepEqual(tree.nodes[0].nodes[2].raws.value, '\\31\\ 0');57});58(0, _helpers.test)('nested pseudo', '.btn-group>.btn:last-child:not(:first-child)', function (t, tree) {59 t.deepEqual(tree.nodes[0].nodes[4].value, ':not');60});61(0, _helpers.test)('extraneous non-combinating whitespace', ' h1:after , h2:after ', function (t, tree) {62 t.deepEqual(tree.nodes[0].nodes[0].spaces.before, ' ');63 t.deepEqual(tree.nodes[0].nodes[1].value, ':after');64 t.deepEqual(tree.nodes[0].nodes[1].spaces.after, ' ');65 t.deepEqual(tree.nodes[0].nodes[0].spaces.before, ' ');66 t.deepEqual(tree.nodes[1].nodes[1].value, ':after');67 t.deepEqual(tree.nodes[1].nodes[1].spaces.after, ' ');68});69(0, _helpers.test)('negation pseudo element with quotes', 'h1:not(".heading")', function (t, tree) {70 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');71 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, '".heading"');72});73(0, _helpers.test)('negation pseudo element with single quotes', "h1:not('.heading')", function (t, tree) {74 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');75 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, "'.heading'");76});77(0, _helpers.test)('Issue #116', "svg:not(:root)", function (t, tree) {78 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');79 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, ':root');80});81(0, _helpers.test)('alone pseudo class', ':root', function (t, tree) {82 t.deepEqual(tree.nodes[0].nodes[0].type, 'pseudo');83 t.deepEqual(tree.nodes[0].nodes[0].value, ':root');84});85(0, _helpers.test)('non standard pseudo (@custom-selector)', ":--foobar, a", function (t, tree) {86 t.deepEqual(tree.nodes[0].nodes[0].value, ':--foobar');87 t.deepEqual(tree.nodes[0].nodes[0].type, 'pseudo');88 t.deepEqual(tree.nodes[1].nodes[0].value, 'a');89 t.deepEqual(tree.nodes[1].nodes[0].type, 'tag');90});91(0, _helpers.test)('non standard pseudo (@custom-selector) (1)', "a, :--foobar", function (t, tree) {92 t.deepEqual(tree.nodes[0].nodes[0].value, 'a');93 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');94 t.deepEqual(tree.nodes[1].nodes[0].value, ':--foobar');95 t.deepEqual(tree.nodes[1].nodes[0].type, 'pseudo');96});97(0, _helpers.test)('current pseudo class', ':current(p, li, dt, dd)', function (t, tree) {98 t.deepEqual(tree.nodes[0].nodes[0].type, 'pseudo');99 t.deepEqual(tree.nodes[0].nodes[0].value, ':current');100 t.deepEqual(tree.nodes[0].nodes[0].nodes[0].nodes[0].type, 'tag');101 t.deepEqual(tree.nodes[0].nodes[0].nodes[0].nodes[0].value, 'p');102 t.deepEqual(tree.nodes[0].nodes[0].nodes[1].nodes[0].type, 'tag');103 t.deepEqual(tree.nodes[0].nodes[0].nodes[1].nodes[0].value, 'li');104 t.deepEqual(tree.nodes[0].nodes[0].nodes[2].nodes[0].type, 'tag');105 t.deepEqual(tree.nodes[0].nodes[0].nodes[2].nodes[0].value, 'dt');106 t.deepEqual(tree.nodes[0].nodes[0].nodes[3].nodes[0].type, 'tag');107 t.deepEqual(tree.nodes[0].nodes[0].nodes[3].nodes[0].value, 'dd');108});109(0, _helpers.test)('is pseudo class', ':is(p, li, dt, dd)', function (t, tree) {110 t.deepEqual(tree.nodes[0].nodes[0].type, 'pseudo');111 t.deepEqual(tree.nodes[0].nodes[0].value, ':is');112 t.deepEqual(tree.nodes[0].nodes[0].nodes[0].nodes[0].type, 'tag');113 t.deepEqual(tree.nodes[0].nodes[0].nodes[0].nodes[0].value, 'p');114 t.deepEqual(tree.nodes[0].nodes[0].nodes[1].nodes[0].type, 'tag');115 t.deepEqual(tree.nodes[0].nodes[0].nodes[1].nodes[0].value, 'li');116 t.deepEqual(tree.nodes[0].nodes[0].nodes[2].nodes[0].type, 'tag');117 t.deepEqual(tree.nodes[0].nodes[0].nodes[2].nodes[0].value, 'dt');118 t.deepEqual(tree.nodes[0].nodes[0].nodes[3].nodes[0].type, 'tag');119 t.deepEqual(tree.nodes[0].nodes[0].nodes[3].nodes[0].value, 'dd');120});121(0, _helpers.test)('is pseudo class with namespace', '*|*:is(:hover, :focus) ', function (t, tree) {122 t.deepEqual(tree.nodes[0].nodes[0].type, 'universal');123 t.deepEqual(tree.nodes[0].nodes[0].namespace, '*');124 t.deepEqual(tree.nodes[0].nodes[0].value, '*');125 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');126 t.deepEqual(tree.nodes[0].nodes[1].value, ':is');127 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].type, 'pseudo');128 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, ':hover');129 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].type, 'pseudo');130 t.deepEqual(tree.nodes[0].nodes[1].nodes[1].nodes[0].value, ':focus');131});132(0, _helpers.test)('has pseudo class', 'a:has(> img)', function (t, tree) {133 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');134 t.deepEqual(tree.nodes[0].nodes[0].value, 'a');135 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');136 t.deepEqual(tree.nodes[0].nodes[1].value, ':has');137 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].type, 'combinator');138 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, '>');139 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[1].type, 'tag');140 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[1].value, 'img');141});142(0, _helpers.test)('where pseudo class', 'a:where(:not(:hover))', function (t, tree) {143 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');144 t.deepEqual(tree.nodes[0].nodes[0].value, 'a');145 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');146 t.deepEqual(tree.nodes[0].nodes[1].value, ':where');147 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].type, 'pseudo');148 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, ':not');149 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[0].nodes[0].type, 'pseudo');150 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[0].nodes[0].value, ':hover');151});152(0, _helpers.test)('nested pseudo classes', "section:not( :has(h1, h2 ) )", function (t, tree) {153 t.deepEqual(tree.nodes[0].nodes[0].type, 'tag');154 t.deepEqual(tree.nodes[0].nodes[0].value, 'section');155 t.deepEqual(tree.nodes[0].nodes[1].type, 'pseudo');156 t.deepEqual(tree.nodes[0].nodes[1].value, ':not');157 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].type, 'pseudo');158 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].value, ':has');159 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[0].nodes[0].type, 'tag');160 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[0].nodes[0].value, 'h1');161 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[1].nodes[0].type, 'tag');162 t.deepEqual(tree.nodes[0].nodes[1].nodes[0].nodes[0].nodes[1].nodes[0].value, 'h2');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function bestFirstSearch(graph, start, end) {2 var queue = new PriorityQueue({ comparator: function (a, b) {3 return a.cost - b.cost;4 } });5 queue.queue({ cost: 0, path: [start] });6 while (queue.length > 0) {7 var node = queue.dequeue();8 var state = node.path[node.path.length - 1];9 if (state === end) {10 return node.path;11 }12 var cost = node.cost;13 var children = graph[state];14 for (var i = 0; i < children.length; i++) {15 var child = children[i];16 queue.queue({ cost: cost + child.cost, path: node.path.concat(child.state) });17 }18 }19 return null;20}21function aStarSearch(graph, start, end) {22 var queue = new PriorityQueue({ comparator: function (a, b) {23 return a.cost + a.heuristic - b.cost - b.heuristic;24 } });25 queue.queue({ cost: 0, path: [start], heuristic: heuristic(start, end) });26 while (queue.length > 0) {27 var node = queue.dequeue();28 var state = node.path[node.path.length - 1];29 if (state === end) {30 return node.path;31 }32 var cost = node.cost;33 var children = graph[state];34 for (var i = 0; i < children.length; i++) {35 var child = children[i];36 queue.queue({ cost: cost + child.cost, path: node.path.concat(child.state), heuristic: heuristic(child.state, end) });37 }38 }39 return null;40}41function greedyBestFirstSearch(graph, start, end) {42 var queue = new PriorityQueue({ comparator: function (a, b) {43 return a.heuristic - b.heuristic;44 } });45 queue.queue({ path: [start], heuristic: heuristic(start, end) });46 while (queue.length > 0) {47 var node = queue.dequeue();48 var state = node.path[node.path.length - 1];49 if (state === end) {50 return node.path;51 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var bfl = new BestFitLine();2var node1 = new Node(0, 0);3var node2 = new Node(1, 2);4var node3 = new Node(2, 4);5var node4 = new Node(3, 6);6bfl.addNode(node1);7bfl.addNode(node2);8bfl.addNode(node3);9bfl.addNode(node4);10var slope = bfl.getSlope();11var intercept = bfl.getIntercept();12console.log(slope);13console.log(intercept);14var bfl = new BestFitLine();15bfl.addNode({x: 0, y: 0});16bfl.addNode({x: 1, y: 2});17bfl.addNode({x: 2, y: 4});18bfl.addNode({x: 3, y: 6});19var slope = bfl.getSlope();20var intercept = bfl.getIntercept();21console.log(slope);22console.log(intercept);23var bfl = new BestFitLine();24bfl.addNode([0, 0]);25bfl.addNode([1, 2]);26bfl.addNode([2, 4]);27bfl.addNode([3, 6]);28var slope = bfl.getSlope();29var intercept = bfl.getIntercept();30console.log(slope);31console.log(intercept);32var bfl = new BestFitLine();33bfl.addNode([0, 0]);34bfl.addNode([1, 2]);35bfl.addNode([2, 4]);36bfl.addNode([3, 6]);37var slope = bfl.getSlope();38var intercept = bfl.getIntercept();39console.log(slope);40console.log(intercept);41var bfl = new BestFitLine();42bfl.addNode([0, 0]);43bfl.addNode([1, 2]);44bfl.addNode([2, 4]);45bfl.addNode([3, 6]);46var slope = bfl.getSlope();47var intercept = bfl.getIntercept();48console.log(slope);49console.log(intercept);

Full Screen

Using AI Code Generation

copy

Full Screen

1var nodes = new Array();2var node1 = new Node(1, 2);3var node2 = new Node(2, 4);4var node3 = new Node(3, 5);5var node4 = new Node(4, 6);6var node5 = new Node(5, 7);7var node6 = new Node(6, 8);8var node7 = new Node(7, 9);9var node8 = new Node(8, 10);10var node9 = new Node(9, 11);11var node10 = new Node(10, 12);12var node11 = new Node(11, 13);13var node12 = new Node(12, 14);14var node13 = new Node(13, 15);15var node14 = new Node(14, 16);16var node15 = new Node(15, 17);17var node16 = new Node(16, 18);18var node17 = new Node(17, 19);19var node18 = new Node(18, 20);20var node19 = new Node(19, 21);21var node20 = new Node(20, 22);22var node21 = new Node(21, 23);23var node22 = new Node(22, 24);24var node23 = new Node(23, 25);25var node24 = new Node(24, 26);26var node25 = new Node(25, 27);27var node26 = new Node(26, 28);28var node27 = new Node(27, 29);29var node28 = new Node(28, 30);30var node29 = new Node(29, 31);31var node30 = new Node(30, 32);32var node31 = new Node(31, 33);33var node32 = new Node(32, 34);34var node33 = new Node(33, 35);35var node34 = new Node(34, 36);36var node35 = new Node(35, 37);37var node36 = new Node(36, 38);38var node37 = new Node(37, 39);39var node38 = new Node(38, 40);40var node39 = new Node(39, 41);41var node40 = new Node(40, 42);42var node41 = new Node(41,

Full Screen

Using AI Code Generation

copy

Full Screen

1function BfsBestFirstSearch(node, goal) {2 var frontier = new PriorityQueue();3 frontier.push(node, 0);4 var cameFrom = {};5 cameFrom[node] = null;6 var costSoFar = {};7 costSoFar[node] = 0;8 while (frontier.length > 0) {9 var current = frontier.pop();10 if (current == goal) {11 break;12 }13 for (var i = 0; i < current.neighbors.length; i++) {14 var next = current.neighbors[i];15 var newCost = costSoFar[current] + current.costs[i];16 if (!costSoFar[next] || newCost < costSoFar[next]) {17 costSoFar[next] = newCost;18 var priority = newCost;19 frontier.push(next, priority);20 cameFrom[next] = current;21 }22 }23 }24 return cameFrom;25}26function AStarSearch(node, goal) {27 var frontier = new PriorityQueue();28 frontier.push(node, 0);29 var cameFrom = {};30 cameFrom[node] = null;31 var costSoFar = {};32 costSoFar[node] = 0;33 while (frontier.length > 0) {34 var current = frontier.pop();35 if (current == goal) {36 break;37 }38 for (var i = 0; i < current.neighbors.length; i++) {39 var next = current.neighbors[i];40 var newCost = costSoFar[current] + current.costs[i];41 if (!costSoFar[next] || newCost < costSoFar[next]) {42 costSoFar[next] = newCost;43 var priority = newCost + heuristic(goal, next);44 frontier.push(next, priority);45 cameFrom[next] = current;46 }47 }48 }49 return cameFrom;50}51function DijkstraSearch(node, goal) {52 var frontier = new PriorityQueue();53 frontier.push(node, 0);54 var cameFrom = {};55 cameFrom[node] = null;56 var costSoFar = {};57 costSoFar[node] = 0;58 while (frontier.length > 0) {59 var current = frontier.pop();60 if (current == goal) {61 break;62 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var data = fs.readFileSync('test4.txt', 'utf8');3var rows = data.split('4');5var graph = {};6rows.forEach(function(row) {7 var parts = row.split(' ');8 var node = parts[0];9 var children = parts.slice(1).map(function(part) {10 return part.split(',');11 });12 graph[node] = children;13});14console.log(graph);15var nodes = Object.keys(graph);16var start = 'A';17var end = 'G';18var queue = [];19var visited = {};20queue.push([start]);21while (queue.length > 0) {22 var path = queue.shift();23 var node = path[path.length - 1];24 if (node === end) {25 console.log(path);26 }27 if (!visited[node]) {28 visited[node] = true;29 var children = graph[node];30 children.forEach(function(child) {31 if (!visited[child[0]]) {32 var newPath = path.slice();33 newPath.push(child[0]);34 queue.push(newPath);35 }36 });37 }38}39var fs = require('fs');40var data = fs.readFileSync('test5.txt', 'utf8');41var rows = data.split('42');43var graph = {};44rows.forEach(function(row) {45 var parts = row.split(' ');46 var node = parts[0];47 var children = parts.slice(1).map(function(part) {48 return part.split(',');49 });50 graph[node] = children;51});52console.log(graph);53var nodes = Object.keys(graph);54var start = 'A';55var end = 'G';56var queue = [];57var visited = {};58queue.push([start]);59while (queue.length > 0) {60 var path = queue.shift();61 var node = path[path.length - 1];62 if (node === end) {63 console.log(path);64 }65 if (!visited[node]) {66 visited[node] = true;67 var children = graph[node];68 children.forEach(function(child) {69 if (!visited[child[0]]) {70 var newPath = path.slice();71 newPath.push(child[0]);72 queue.push(newPath);73 }74 });75 }76}77var fs = require('fs');

Full Screen

Using AI Code Generation

copy

Full Screen

1function test4()2{3 var nodes = new Array();4 var node1 = new Node(1,2,0,0);5 var node2 = new Node(2,0,1,0);6 var node3 = new Node(3,0,0,1);7 nodes.push(node1);8 nodes.push(node2);9 nodes.push(node3);10 var start = new Node(0,0,0,0);11 var goal = new Node(0,1,1,1);12 var bestFS = new BestFS();13 bestFS.setNodes(nodes);14 bestFS.setStart(start);15 bestFS.setGoal(goal);16 var path = bestFS.findPath();17 for(var i=0;i<path.length;i++)18 {19 var node = path[i];20 console.log(node.toString());21 }22}23function test5()24{25 var nodes = new Array();26 var node1 = new Node(1,2,0,0);27 var node2 = new Node(2,0,1,0);28 var node3 = new Node(3,0,0,1);29 nodes.push(node1);30 nodes.push(node2);31 nodes.push(node3);32 var start = new Node(0,0,0,0);33 var goal = new Node(0,1,1,1);34 var bestFS = new BestFS();35 bestFS.setNodes(nodes);36 bestFS.setStart(start);37 bestFS.setGoal(goal);38 var path = bestFS.findPath();39 for(var i=0;i<path.length;i++)40 {41 var node = path[i];42 console.log(node.toString());43 }44}45function test6()46{47 var nodes = new Array();48 var node1 = new Node(1,2,0,0);49 var node2 = new Node(2,0,1,0);50 var node3 = new Node(3,0,0,1);51 nodes.push(node1);52 nodes.push(node2);53 nodes.push(node3);54 var start = new Node(0,0,0,0);55 var goal = new Node(0,1,1,1);56 var bestFS = new BestFS();57 bestFS.setNodes(nodes);58 bestFS.setStart(start);59 bestFS.setGoal(goal);60 var path = bestFS.findPath();61 for(var i=0;i<path.length

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch.js');2var bfs = new BestFirstSearch();3var path = bfs.search('A', 'E');4console.log('path:', path);5var path = bfs.search('A', 'F');6console.log('path:', path);7var path = bfs.search('A', 'G');8console.log('path:', path);9var Node = require('./Node.js');10module.exports = function(){11 this.search = function(start, end){12 var startNode = new Node(start);13 var endNode = new Node(end);14 var open = [startNode];15 var closed = [];16 while(open.length > 0){17 var currentNode = open.shift();18 closed.push(currentNode);19 if(currentNode.value === end){20 return currentNode.getPath();21 }22 var children = this.getChildren(currentNode);23 for(var i = 0; i < children.length; i++){24 var child = children[i];25 if(!this.inList(child, closed) && !this.inList(child, open)){26 open.push(child);27 }28 }29 }30 return null;31 }32 this.inList = function(node, list){33 for(var i = 0; i < list.length; i++){34 if(node.value === list[i].value){35 return true;36 }37 }38 return false;39 }40 this.getChildren = function(node){41 var children = [];42 for(var i = 0; i < graph.length; i++){43 if(graph[i][0] === node.value){44 var child = new Node(graph[i][1]);45 child.previous = node;46 children.push(child);47 }48 }49 return children;50 }51}52module.exports = function(value){53 this.value = value;54 this.previous = null;55 this.getPath = function(){56 var path = [this.value];57 var previous = this.previous;58 while(previous){59 path.push(previous.value);60 previous = previous.previous;61 }62 return path.reverse();63 }64}

Full Screen

Using AI Code Generation

copy

Full Screen

1function BestFS() {2 var start = new Date().getTime();3 var open = new PriorityQueue();4 var closed = new PriorityQueue();5 var current = new Node();6 var goal = new Node();7 var startNode = new Node();8 var goalNode = new Node();9 var path = [];10 var nodes = [];11 var pathLength = 0;12 var nodesLength = 0;13 var pathFound = false;14 var goalFound = false;15 var pathIndex = 0;16 var pathLength = 0;17 var nodesLength = 0;18 var nodesVisited = 0;19 var nodesExpanded = 0;20 var totalCost = 0;21 var heuristic = 0;22 var maxQueueSize = 0;23 var queueSize = 0;24 var time = 0;25 var distance = 0;26 var heuristicCost = 0;27 var start = new Date().getTime();28 var end = new Date().getTime();29 var elapsed = end - start;30 var time = 0;31 var pathFound = false;32 var goalFound = false;33 var pathIndex = 0;34 var pathLength = 0;35 var nodesLength = 0;36 var nodesVisited = 0;37 var nodesExpanded = 0;38 var totalCost = 0;39 var heuristic = 0;40 var maxQueueSize = 0;41 var queueSize = 0;42 var time = 0;43 var distance = 0;44 var heuristicCost = 0;45 var start = new Date().getTime();46 var end = new Date().getTime();47 var elapsed = end - start;48 var time = 0;49 var pathFound = false;50 var goalFound = false;51 var pathIndex = 0;52 var pathLength = 0;53 var nodesLength = 0;54 var nodesVisited = 0;55 var nodesExpanded = 0;56 var totalCost = 0;57 var heuristic = 0;58 var maxQueueSize = 0;59 var queueSize = 0;60 var time = 0;61 var distance = 0;62 var heuristicCost = 0;63 var start = new Date().getTime();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful