How to use deepEqual method in chai

Best JavaScript code snippet using chai

parse.js

Source:parse.js Github

copy

Full Screen

...3var qs = require('../');4var iconv = require('iconv-lite');5test('parse()', function (t) {6 t.test('parses a simple string', function (st) {7 st.deepEqual(qs.parse('0=foo'), { 0: 'foo' });8 st.deepEqual(qs.parse('foo=c++'), { foo: 'c ' });9 st.deepEqual(qs.parse('a[>=]=23'), { a: { '>=': '23' } });10 st.deepEqual(qs.parse('a[<=>]==23'), { a: { '<=>': '=23' } });11 st.deepEqual(qs.parse('a[==]=23'), { a: { '==': '23' } });12 st.deepEqual(qs.parse('foo', { strictNullHandling: true }), { foo: null });13 st.deepEqual(qs.parse('foo'), { foo: '' });14 st.deepEqual(qs.parse('foo='), { foo: '' });15 st.deepEqual(qs.parse('foo=bar'), { foo: 'bar' });16 st.deepEqual(qs.parse(' foo = bar = baz '), { ' foo ': ' bar = baz ' });17 st.deepEqual(qs.parse('foo=bar=baz'), { foo: 'bar=baz' });18 st.deepEqual(qs.parse('foo=bar&bar=baz'), { foo: 'bar', bar: 'baz' });19 st.deepEqual(qs.parse('foo2=bar2&baz2='), { foo2: 'bar2', baz2: '' });20 st.deepEqual(qs.parse('foo=bar&baz', { strictNullHandling: true }), { foo: 'bar', baz: null });21 st.deepEqual(qs.parse('foo=bar&baz'), { foo: 'bar', baz: '' });22 st.deepEqual(qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World'), {23 cht: 'p3',24 chd: 't:60,40',25 chs: '250x100',26 chl: 'Hello|World'27 });28 st.end();29 });30 t.test('allows enabling dot notation', function (st) {31 st.deepEqual(qs.parse('a.b=c'), { 'a.b': 'c' });32 st.deepEqual(qs.parse('a.b=c', { allowDots: true }), { a: { b: 'c' } });33 st.end();34 });35 t.deepEqual(qs.parse('a[b]=c'), { a: { b: 'c' } }, 'parses a single nested string');36 t.deepEqual(qs.parse('a[b][c]=d'), { a: { b: { c: 'd' } } }, 'parses a double nested string');37 t.deepEqual(38 qs.parse('a[b][c][d][e][f][g][h]=i'),39 { a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } },40 'defaults to a depth of 5'41 );42 t.test('only parses one level when depth = 1', function (st) {43 st.deepEqual(qs.parse('a[b][c]=d', { depth: 1 }), { a: { b: { '[c]': 'd' } } });44 st.deepEqual(qs.parse('a[b][c][d]=e', { depth: 1 }), { a: { b: { '[c][d]': 'e' } } });45 st.end();46 });47 t.deepEqual(qs.parse('a=b&a=c'), { a: ['b', 'c'] }, 'parses a simple array');48 t.test('parses an explicit array', function (st) {49 st.deepEqual(qs.parse('a[]=b'), { a: ['b'] });50 st.deepEqual(qs.parse('a[]=b&a[]=c'), { a: ['b', 'c'] });51 st.deepEqual(qs.parse('a[]=b&a[]=c&a[]=d'), { a: ['b', 'c', 'd'] });52 st.end();53 });54 t.test('parses a mix of simple and explicit arrays', function (st) {55 st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });56 st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });57 st.deepEqual(qs.parse('a[0]=b&a=c'), { a: ['b', 'c'] });58 st.deepEqual(qs.parse('a=b&a[0]=c'), { a: ['b', 'c'] });59 st.deepEqual(qs.parse('a[1]=b&a=c', { arrayLimit: 20 }), { a: ['b', 'c'] });60 st.deepEqual(qs.parse('a[]=b&a=c', { arrayLimit: 0 }), { a: ['b', 'c'] });61 st.deepEqual(qs.parse('a[]=b&a=c'), { a: ['b', 'c'] });62 st.deepEqual(qs.parse('a=b&a[1]=c', { arrayLimit: 20 }), { a: ['b', 'c'] });63 st.deepEqual(qs.parse('a=b&a[]=c', { arrayLimit: 0 }), { a: ['b', 'c'] });64 st.deepEqual(qs.parse('a=b&a[]=c'), { a: ['b', 'c'] });65 st.end();66 });67 t.test('parses a nested array', function (st) {68 st.deepEqual(qs.parse('a[b][]=c&a[b][]=d'), { a: { b: ['c', 'd'] } });69 st.deepEqual(qs.parse('a[>=]=25'), { a: { '>=': '25' } });70 st.end();71 });72 t.test('allows to specify array indices', function (st) {73 st.deepEqual(qs.parse('a[1]=c&a[0]=b&a[2]=d'), { a: ['b', 'c', 'd'] });74 st.deepEqual(qs.parse('a[1]=c&a[0]=b'), { a: ['b', 'c'] });75 st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 20 }), { a: ['c'] });76 st.deepEqual(qs.parse('a[1]=c', { arrayLimit: 0 }), { a: { 1: 'c' } });77 st.deepEqual(qs.parse('a[1]=c'), { a: ['c'] });78 st.end();79 });80 t.test('limits specific array indices to arrayLimit', function (st) {81 st.deepEqual(qs.parse('a[20]=a', { arrayLimit: 20 }), { a: ['a'] });82 st.deepEqual(qs.parse('a[21]=a', { arrayLimit: 20 }), { a: { 21: 'a' } });83 st.end();84 });85 t.deepEqual(qs.parse('a[12b]=c'), { a: { '12b': 'c' } }, 'supports keys that begin with a number');86 t.test('supports encoded = signs', function (st) {87 st.deepEqual(qs.parse('he%3Dllo=th%3Dere'), { 'he=llo': 'th=ere' });88 st.end();89 });90 t.test('is ok with url encoded strings', function (st) {91 st.deepEqual(qs.parse('a[b%20c]=d'), { a: { 'b c': 'd' } });92 st.deepEqual(qs.parse('a[b]=c%20d'), { a: { b: 'c d' } });93 st.end();94 });95 t.test('allows brackets in the value', function (st) {96 st.deepEqual(qs.parse('pets=["tobi"]'), { pets: '["tobi"]' });97 st.deepEqual(qs.parse('operators=[">=", "<="]'), { operators: '[">=", "<="]' });98 st.end();99 });100 t.test('allows empty values', function (st) {101 st.deepEqual(qs.parse(''), {});102 st.deepEqual(qs.parse(null), {});103 st.deepEqual(qs.parse(undefined), {});104 st.end();105 });106 t.test('transforms arrays to objects', function (st) {107 st.deepEqual(qs.parse('foo[0]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });108 st.deepEqual(qs.parse('foo[bad]=baz&foo[0]=bar'), { foo: { bad: 'baz', 0: 'bar' } });109 st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar'), { foo: { bad: 'baz', 0: 'bar' } });110 st.deepEqual(qs.parse('foo[]=bar&foo[bad]=baz'), { foo: { 0: 'bar', bad: 'baz' } });111 st.deepEqual(qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo'), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });112 st.deepEqual(qs.parse('foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb'), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });113 st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: false }), { a: { 0: 'b', t: 'u' } });114 st.deepEqual(qs.parse('a[]=b&a[t]=u&a[hasOwnProperty]=c', { allowPrototypes: true }), { a: { 0: 'b', t: 'u', hasOwnProperty: 'c' } });115 st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: false }), { a: { 0: 'b', x: 'y' } });116 st.deepEqual(qs.parse('a[]=b&a[hasOwnProperty]=c&a[x]=y', { allowPrototypes: true }), { a: { 0: 'b', hasOwnProperty: 'c', x: 'y' } });117 st.end();118 });119 t.test('transforms arrays to objects (dot notation)', function (st) {120 st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: 'baz' } });121 st.deepEqual(qs.parse('foo[0].baz=bar&fool.bad.boo=baz', { allowDots: true }), { foo: [{ baz: 'bar' }], fool: { bad: { boo: 'baz' } } });122 st.deepEqual(qs.parse('foo[0][0].baz=bar&fool.bad=baz', { allowDots: true }), { foo: [[{ baz: 'bar' }]], fool: { bad: 'baz' } });123 st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15'], bar: '2' }] });124 st.deepEqual(qs.parse('foo[0].baz[0]=15&foo[0].baz[1]=16&foo[0].bar=2', { allowDots: true }), { foo: [{ baz: ['15', '16'], bar: '2' }] });125 st.deepEqual(qs.parse('foo.bad=baz&foo[0]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });126 st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar' } });127 st.deepEqual(qs.parse('foo[]=bar&foo.bad=baz', { allowDots: true }), { foo: { 0: 'bar', bad: 'baz' } });128 st.deepEqual(qs.parse('foo.bad=baz&foo[]=bar&foo[]=foo', { allowDots: true }), { foo: { bad: 'baz', 0: 'bar', 1: 'foo' } });129 st.deepEqual(qs.parse('foo[0].a=a&foo[0].b=b&foo[1].a=aa&foo[1].b=bb', { allowDots: true }), { foo: [{ a: 'a', b: 'b' }, { a: 'aa', b: 'bb' }] });130 st.end();131 });132 t.test('correctly prunes undefined values when converting an array to an object', function (st) {133 st.deepEqual(qs.parse('a[2]=b&a[99999999]=c'), { a: { 2: 'b', 99999999: 'c' } });134 st.end();135 });136 t.test('supports malformed uri characters', function (st) {137 st.deepEqual(qs.parse('{%:%}', { strictNullHandling: true }), { '{%:%}': null });138 st.deepEqual(qs.parse('{%:%}='), { '{%:%}': '' });139 st.deepEqual(qs.parse('foo=%:%}'), { foo: '%:%}' });140 st.end();141 });142 t.test('doesn\'t produce empty keys', function (st) {143 st.deepEqual(qs.parse('_r=1&'), { _r: '1' });144 st.end();145 });146 t.test('cannot access Object prototype', function (st) {147 qs.parse('constructor[prototype][bad]=bad');148 qs.parse('bad[constructor][prototype][bad]=bad');149 st.equal(typeof Object.prototype.bad, 'undefined');150 st.end();151 });152 t.test('parses arrays of objects', function (st) {153 st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });154 st.deepEqual(qs.parse('a[0][b]=c'), { a: [{ b: 'c' }] });155 st.end();156 });157 t.test('allows for empty strings in arrays', function (st) {158 st.deepEqual(qs.parse('a[]=b&a[]=&a[]=c'), { a: ['b', '', 'c'] });159 st.deepEqual(160 qs.parse('a[0]=b&a[1]&a[2]=c&a[19]=', { strictNullHandling: true, arrayLimit: 20 }),161 { a: ['b', null, 'c', ''] },162 'with arrayLimit 20 + array indices: null then empty string works'163 );164 st.deepEqual(165 qs.parse('a[]=b&a[]&a[]=c&a[]=', { strictNullHandling: true, arrayLimit: 0 }),166 { a: ['b', null, 'c', ''] },167 'with arrayLimit 0 + array brackets: null then empty string works'168 );169 st.deepEqual(170 qs.parse('a[0]=b&a[1]=&a[2]=c&a[19]', { strictNullHandling: true, arrayLimit: 20 }),171 { a: ['b', '', 'c', null] },172 'with arrayLimit 20 + array indices: empty string then null works'173 );174 st.deepEqual(175 qs.parse('a[]=b&a[]=&a[]=c&a[]', { strictNullHandling: true, arrayLimit: 0 }),176 { a: ['b', '', 'c', null] },177 'with arrayLimit 0 + array brackets: empty string then null works'178 );179 st.deepEqual(180 qs.parse('a[]=&a[]=b&a[]=c'),181 { a: ['', 'b', 'c'] },182 'array brackets: empty strings work'183 );184 st.end();185 });186 t.test('compacts sparse arrays', function (st) {187 st.deepEqual(qs.parse('a[10]=1&a[2]=2', { arrayLimit: 20 }), { a: ['2', '1'] });188 st.deepEqual(qs.parse('a[1][b][2][c]=1', { arrayLimit: 20 }), { a: [{ b: [{ c: '1' }] }] });189 st.deepEqual(qs.parse('a[1][2][3][c]=1', { arrayLimit: 20 }), { a: [[[{ c: '1' }]]] });190 st.deepEqual(qs.parse('a[1][2][3][c][1]=1', { arrayLimit: 20 }), { a: [[[{ c: ['1'] }]]] });191 st.end();192 });193 t.test('parses semi-parsed strings', function (st) {194 st.deepEqual(qs.parse({ 'a[b]': 'c' }), { a: { b: 'c' } });195 st.deepEqual(qs.parse({ 'a[b]': 'c', 'a[d]': 'e' }), { a: { b: 'c', d: 'e' } });196 st.end();197 });198 t.test('parses buffers correctly', function (st) {199 var b = new Buffer('test');200 st.deepEqual(qs.parse({ a: b }), { a: b });201 st.end();202 });203 t.test('continues parsing when no parent is found', function (st) {204 st.deepEqual(qs.parse('[]=&a=b'), { 0: '', a: 'b' });205 st.deepEqual(qs.parse('[]&a=b', { strictNullHandling: true }), { 0: null, a: 'b' });206 st.deepEqual(qs.parse('[foo]=bar'), { foo: 'bar' });207 st.end();208 });209 t.test('does not error when parsing a very long array', function (st) {210 var str = 'a[]=a';211 while (Buffer.byteLength(str) < 128 * 1024) {212 str = str + '&' + str;213 }214 st.doesNotThrow(function () {215 qs.parse(str);216 });217 st.end();218 });219 t.test('should not throw when a native prototype has an enumerable property', { parallel: false }, function (st) {220 Object.prototype.crash = '';221 Array.prototype.crash = '';222 st.doesNotThrow(qs.parse.bind(null, 'a=b'));223 st.deepEqual(qs.parse('a=b'), { a: 'b' });224 st.doesNotThrow(qs.parse.bind(null, 'a[][b]=c'));225 st.deepEqual(qs.parse('a[][b]=c'), { a: [{ b: 'c' }] });226 delete Object.prototype.crash;227 delete Array.prototype.crash;228 st.end();229 });230 t.test('parses a string with an alternative string delimiter', function (st) {231 st.deepEqual(qs.parse('a=b;c=d', { delimiter: ';' }), { a: 'b', c: 'd' });232 st.end();233 });234 t.test('parses a string with an alternative RegExp delimiter', function (st) {235 st.deepEqual(qs.parse('a=b; c=d', { delimiter: /[;,] */ }), { a: 'b', c: 'd' });236 st.end();237 });238 t.test('does not use non-splittable objects as delimiters', function (st) {239 st.deepEqual(qs.parse('a=b&c=d', { delimiter: true }), { a: 'b', c: 'd' });240 st.end();241 });242 t.test('allows overriding parameter limit', function (st) {243 st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: 1 }), { a: 'b' });244 st.end();245 });246 t.test('allows setting the parameter limit to Infinity', function (st) {247 st.deepEqual(qs.parse('a=b&c=d', { parameterLimit: Infinity }), { a: 'b', c: 'd' });248 st.end();249 });250 t.test('allows overriding array limit', function (st) {251 st.deepEqual(qs.parse('a[0]=b', { arrayLimit: -1 }), { a: { 0: 'b' } });252 st.deepEqual(qs.parse('a[-1]=b', { arrayLimit: -1 }), { a: { '-1': 'b' } });253 st.deepEqual(qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 }), { a: { 0: 'b', 1: 'c' } });254 st.end();255 });256 t.test('allows disabling array parsing', function (st) {257 st.deepEqual(qs.parse('a[0]=b&a[1]=c', { parseArrays: false }), { a: { 0: 'b', 1: 'c' } });258 st.end();259 });260 t.test('parses an object', function (st) {261 var input = {262 'user[name]': { 'pop[bob]': 3 },263 'user[email]': null264 };265 var expected = {266 user: {267 name: { 'pop[bob]': 3 },268 email: null269 }270 };271 var result = qs.parse(input);272 st.deepEqual(result, expected);273 st.end();274 });275 t.test('parses an object in dot notation', function (st) {276 var input = {277 'user.name': { 'pop[bob]': 3 },278 'user.email.': null279 };280 var expected = {281 user: {282 name: { 'pop[bob]': 3 },283 email: null284 }285 };286 var result = qs.parse(input, { allowDots: true });287 st.deepEqual(result, expected);288 st.end();289 });290 t.test('parses an object and not child values', function (st) {291 var input = {292 'user[name]': { 'pop[bob]': { test: 3 } },293 'user[email]': null294 };295 var expected = {296 user: {297 name: { 'pop[bob]': { test: 3 } },298 email: null299 }300 };301 var result = qs.parse(input);302 st.deepEqual(result, expected);303 st.end();304 });305 t.test('does not blow up when Buffer global is missing', function (st) {306 var tempBuffer = global.Buffer;307 delete global.Buffer;308 var result = qs.parse('a=b&c=d');309 global.Buffer = tempBuffer;310 st.deepEqual(result, { a: 'b', c: 'd' });311 st.end();312 });313 t.test('does not crash when parsing circular references', function (st) {314 var a = {};315 a.b = a;316 var parsed;317 st.doesNotThrow(function () {318 parsed = qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });319 });320 st.equal('foo' in parsed, true, 'parsed has "foo" property');321 st.equal('bar' in parsed.foo, true);322 st.equal('baz' in parsed.foo, true);323 st.equal(parsed.foo.bar, 'baz');324 st.deepEqual(parsed.foo.baz, a);325 st.end();326 });327 t.test('parses null objects correctly', { skip: !Object.create }, function (st) {328 var a = Object.create(null);329 a.b = 'c';330 st.deepEqual(qs.parse(a), { b: 'c' });331 var result = qs.parse({ a: a });332 st.equal('a' in result, true, 'result has "a" property');333 st.deepEqual(result.a, a);334 st.end();335 });336 t.test('parses dates correctly', function (st) {337 var now = new Date();338 st.deepEqual(qs.parse({ a: now }), { a: now });339 st.end();340 });341 t.test('parses regular expressions correctly', function (st) {342 var re = /^test$/;343 st.deepEqual(qs.parse({ a: re }), { a: re });344 st.end();345 });346 t.test('does not allow overwriting prototype properties', function (st) {347 st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: false }), {});348 st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: false }), {});349 st.deepEqual(350 qs.parse('toString', { allowPrototypes: false }),351 {},352 'bare "toString" results in {}'353 );354 st.end();355 });356 t.test('can allow overwriting prototype properties', function (st) {357 st.deepEqual(qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true }), { a: { hasOwnProperty: 'b' } });358 st.deepEqual(qs.parse('hasOwnProperty=b', { allowPrototypes: true }), { hasOwnProperty: 'b' });359 st.deepEqual(360 qs.parse('toString', { allowPrototypes: true }),361 { toString: '' },362 'bare "toString" results in { toString: "" }'363 );364 st.end();365 });366 t.test('params starting with a closing bracket', function (st) {367 st.deepEqual(qs.parse(']=toString'), { ']': 'toString' });368 st.deepEqual(qs.parse(']]=toString'), { ']]': 'toString' });369 st.deepEqual(qs.parse(']hello]=toString'), { ']hello]': 'toString' });370 st.end();371 });372 t.test('params starting with a starting bracket', function (st) {373 st.deepEqual(qs.parse('[=toString'), { '[': 'toString' });374 st.deepEqual(qs.parse('[[=toString'), { '[[': 'toString' });375 st.deepEqual(qs.parse('[hello[=toString'), { '[hello[': 'toString' });376 st.end();377 });378 t.test('add keys to objects', function (st) {379 st.deepEqual(380 qs.parse('a[b]=c&a=d'),381 { a: { b: 'c', d: true } },382 'can add keys to objects'383 );384 st.deepEqual(385 qs.parse('a[b]=c&a=toString'),386 { a: { b: 'c' } },387 'can not overwrite prototype'388 );389 st.deepEqual(390 qs.parse('a[b]=c&a=toString', { allowPrototypes: true }),391 { a: { b: 'c', toString: true } },392 'can overwrite prototype with allowPrototypes true'393 );394 st.deepEqual(395 qs.parse('a[b]=c&a=toString', { plainObjects: true }),396 { a: { b: 'c', toString: true } },397 'can overwrite prototype with plainObjects true'398 );399 st.end();400 });401 t.test('can return null objects', { skip: !Object.create }, function (st) {402 var expected = Object.create(null);403 expected.a = Object.create(null);404 expected.a.b = 'c';405 expected.a.hasOwnProperty = 'd';406 st.deepEqual(qs.parse('a[b]=c&a[hasOwnProperty]=d', { plainObjects: true }), expected);407 st.deepEqual(qs.parse(null, { plainObjects: true }), Object.create(null));408 var expectedArray = Object.create(null);409 expectedArray.a = Object.create(null);410 expectedArray.a[0] = 'b';411 expectedArray.a.c = 'd';412 st.deepEqual(qs.parse('a[]=b&a[c]=d', { plainObjects: true }), expectedArray);413 st.end();414 });415 t.test('can parse with custom encoding', function (st) {416 st.deepEqual(qs.parse('%8c%a7=%91%e5%8d%e3%95%7b', {417 decoder: function (str) {418 var reg = /%([0-9A-F]{2})/ig;419 var result = [];420 var parts = reg.exec(str);421 while (parts) {422 result.push(parseInt(parts[1], 16));423 parts = reg.exec(str);424 }425 return iconv.decode(new Buffer(result), 'shift_jis').toString();426 }427 }), { 県: '大阪府' });428 st.end();429 });430 t.test('throws error with wrong decoder', function (st) {...

Full Screen

Full Screen

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

array.builders.js

Source:array.builders.js Github

copy

Full Screen

1$(document).ready(function() {2 module("underscore.array.builders");3 test("cat", function() {4 // no args5 deepEqual(_.cat(), [], 'should return an empty array when given no args');6 7 // one arg8 deepEqual(_.cat([]), [], 'should concatenate one empty array');9 deepEqual(_.cat([1,2,3]), [1,2,3], 'should concatenate one homogenious array');10 var result = _.cat([1, "2", [3], {n: 4}]);11 deepEqual(result, [1, "2", [3], {n: 4}], 'should concatenate one heterogenious array');12 result = (function(){ return _.cat(arguments); })(1, 2, 3);13 deepEqual(result, [1, 2, 3], 'should concatenate the arguments object');14 // two args15 deepEqual(_.cat([1,2,3],[4,5,6]), [1,2,3,4,5,6], 'should concatenate two arrays');16 result = (function(){ return _.cat(arguments, [4,5,6]); })(1,2,3);17 deepEqual(result, [1,2,3,4,5,6], 'should concatenate an array and an arguments object');18 // > 2 args19 var a = [1,2,3];20 var b = [4,5,6];21 var c = [7,8,9];22 var d = [0,0,0];23 deepEqual(_.cat(a,b,c), [1,2,3,4,5,6,7,8,9], 'should concatenate three arrays');24 deepEqual(_.cat(a,b,c,d), [1,2,3,4,5,6,7,8,9,0,0,0], 'should concatenate four arrays');25 result = (function(){ return _.cat(arguments,b,c,d); }).apply(null, a);26 deepEqual(result, [1,2,3,4,5,6,7,8,9,0,0,0], 'should concatenate four arrays, including an arguments object');27 // heterogenious types28 deepEqual(_.cat([1],2), [1,2], 'should concatenate mixed types');29 deepEqual(_.cat([1],2,3), [1,2,3], 'should concatenate mixed types');30 deepEqual(_.cat(1,2,3), [1,2,3], 'should concatenate mixed types');31 result = (function(){ return _.cat(arguments, 4,5,6); })(1,2,3);32 deepEqual(result, [1,2,3,4,5,6], 'should concatenate mixed types, including an arguments object');33 });34 test("cons", function() {35 deepEqual(_.cons(0, []), [0], 'should insert the first arg into the array given as the second arg');36 deepEqual(_.cons(1, [2]), [1,2], 'should insert the first arg into the array given as the second arg');37 deepEqual(_.cons([0], [1,2,3]), [[0],1,2,3], 'should insert the first arg into the array given as the second arg');38 deepEqual(_.cons(1, 2), [1,2], 'should create a pair if the second is not an array');39 deepEqual(_.cons([1], 2), [[1],2], 'should create a pair if the second is not an array');40 result = (function(){ return _.cons(0, arguments); })(1,2,3);41 deepEqual(result, [0,1,2,3], 'should construct an array given an arguments object as the tail');42 var a = [1,2,3];43 var result = _.cons(0,a);44 deepEqual(a, [1,2,3], 'should not modify the original tail');45 });46 test("partition", function() {47 var a = _.range(4);48 var b = _.range(5);49 var c = _.range(7);50 deepEqual(_.partition(a, 2), [[0,1],[2,3]], 'should partition into the size given');51 deepEqual(_.partition(b, 2), [[0,1],[2,3]], 'should partition into the size given. Extras are dropped');52 var result = _.partition(a, 2);53 deepEqual(a, _.range(4), 'should not modify the original array');54 deepEqual(_.partition(c, 3, [7,8]), [[0,1,2],[3,4,5],[6,7,8]], 'should allow one to specify a padding array');55 deepEqual(_.partition(b, 3, 9), [[0,1,2],[3,4,9]], 'should allow one to specify a padding value');56 });57 test("partitionAll", function() {58 var a = _.range(4);59 var b = _.range(10);60 deepEqual(_.partitionAll(a, 2), [[0,1],[2,3]], 'should partition into the size given');61 deepEqual(_.partitionAll(b, 4), [[0,1,2,3],[4,5,6,7],[8,9]], 'should partition into the size given, with a small end');62 var result = _.partitionAll(a, 2);63 deepEqual(a, _.range(4), 'should not modify the original array');64 deepEqual(_.partitionAll(b, 2, 4), [[0,1],[4,5],[8,9]], 'should partition into the size given, with skips');65 deepEqual(_.partitionAll(b, 3, 4), [[0,1,2],[4,5,6],[8,9]], 'should partition into the size given, with skips and a small end');66 });67 test("mapcat", function() {68 var a = [1,2,3];69 var commaize = function(e) { return _.cons(e, [","]); };70 deepEqual(_.mapcat(a, commaize), [1, ",", 2, ",", 3, ","], 'should return an array with all intermediate mapped arrays concatenated');71 });72 test("interpose", function() {73 var a = [1,2,3];74 var b = [1,2];75 var c = [1];76 deepEqual(_.interpose(a, 0), [1,0,2,0,3], 'should put the 2nd arg between the elements of the array given');77 deepEqual(_.interpose(b, 0), [1,0,2], 'should put the 2nd arg between the elements of the array given');78 deepEqual(_.interpose(c, 0), [1], 'should return the array given if nothing to interpose');79 deepEqual(_.interpose([], 0), [], 'should return an empty array given an empty array');80 var result = _.interpose(b,0);81 deepEqual(b, [1,2], 'should not modify the original array');82 });83 test("weave", function() {84 var a = [1,2,3];85 var b = [1,2];86 var c = ['a', 'b', 'c'];87 var d = [1, [2]];88 // zero89 deepEqual(_.weave(), [], 'should weave zero arrays');90 // one91 deepEqual(_.weave([]), [], 'should weave one array');92 deepEqual(_.weave([1,[2]]), [1,[2]], 'should weave one array');93 // two94 deepEqual(_.weave(a,b), [1,1,2,2,3], 'should weave two arrays');95 deepEqual(_.weave(a,a), [1,1,2,2,3,3], 'should weave two arrays');96 deepEqual(_.weave(c,a), ['a',1,'b',2,'c',3], 'should weave two arrays');97 deepEqual(_.weave(a,d), [1,1,2,[2],3], 'should weave two arrays');98 // > 299 deepEqual(_.weave(a,b,c), [1,1,'a',2,2,'b',3,'c'], 'should weave more than two arrays');100 deepEqual(_.weave(a,b,c,d), [1,1,'a',1,2,2,'b',[2],3,'c'], 'should weave more than two arrays');101 });102 test("repeat", function() {103 deepEqual(_.repeat(3,1), [1,1,1], 'should build an array of size n with the specified element in each slot');104 deepEqual(_.repeat(0), [], 'should return an empty array if given zero and no repeat arg');105 deepEqual(_.repeat(0,9999), [], 'should return an empty array if given zero and some repeat arg');106 });107 test("cycle", function() {108 var a = [1,2,3];109 deepEqual(_.cycle(3, a), [1,2,3,1,2,3,1,2,3], 'should build an array with the specified array contents repeated n times');110 deepEqual(_.cycle(0, a), [], 'should return an empty array if told to repeat zero times');111 deepEqual(_.cycle(-1000, a), [], 'should return an empty array if told to repeat negative times');112 });113 test("splitAt", function() {114 var a = [1,2,3,4,5];115 deepEqual(_.splitAt(a, 2), [[1,2],[3,4,5]], 'should bifurcate an array at a given index');116 deepEqual(_.splitAt(a, 0), [[], [1,2,3,4,5]], 'should bifurcate an array at a given index');117 deepEqual(_.splitAt(a, 5), [[1,2,3,4,5],[]], 'should bifurcate an array at a given index');118 deepEqual(_.splitAt([], 5), [[],[]], 'should bifurcate an array at a given index');119 });120 test("iterateUntil", function() {121 var dec = function(n) { return n - 1; };122 var isPos = function(n) { return n > 0; };123 deepEqual(_.iterateUntil(dec, isPos, 6), [5,4,3,2,1], 'should build an array, decrementing a number while positive');124 });125 test("takeSkipping", function() {126 deepEqual(_.takeSkipping(_.range(5), 0), [], 'should take nothing if told to skip by zero');127 deepEqual(_.takeSkipping(_.range(5), -1), [], 'should take nothing if told to skip by negative');128 deepEqual(_.takeSkipping(_.range(5), 100), [0], 'should take first element if told to skip by big number');129 deepEqual(_.takeSkipping(_.range(5), 1), [0,1,2,3,4], 'should take every element in an array');130 deepEqual(_.takeSkipping(_.range(10), 2), [0,2,4,6,8], 'should take every 2nd element in an array');131 });132 test("reductions", function() {133 var result = _.reductions([1,2,3,4,5], function(agg, n) {134 return agg + n;135 }, 0);136 deepEqual(result, [1,3,6,10,15], 'should retain each intermediate step in a reduce');137 });138 test("keepIndexed", function() {139 var a = ['a', 'b', 'c', 'd', 'e'];140 var b = [-9, 0, 29, -7, 45, 3, -8];141 var oddy = function(k, v) { return _.isOdd(k) ? v : undefined; };142 var posy = function(k, v) { return _.isPositive(v) ? k : undefined; };143 deepEqual(_.keepIndexed(a, _.isOdd), [false,true,false,true,false], 'runs the predciate on the index, and not the element');144 deepEqual(_.keepIndexed(a, oddy), ['b', 'd'], 'keeps elements whose index passes a truthy test');145 deepEqual(_.keepIndexed(b, posy), [2,4,5], 'keeps elements whose index passes a truthy test');146 deepEqual(_.keepIndexed(_.range(10), oddy), [1,3,5,7,9], 'keeps elements whose index passes a truthy test');147 });...

Full Screen

Full Screen

juice.test.js

Source:juice.test.js Github

copy

Full Screen

...14 * Tests.15 */16it('extracting selectors', function() {17 var extract = utils.extract;18 assert.deepEqual(extract('#a'),['#a']);19 assert.deepEqual(extract('#a, .b'),['#a', '.b']);20 assert.deepEqual(extract('#a, .b,'),['#a', '.b']);21 assert.deepEqual(extract('.test.a, #a.b'),['.test.a', '#a.b']);22 assert.deepEqual(extract('a[type=text, a=b], .a, .b, #c #d'),['a[type=text, a=b]', '.a', '.b', '#c #d']);23 assert.deepEqual(extract('a:not(.a,.b,.c)'),['a:not(.a,.b,.c)']);24 assert.deepEqual(extract('a:not(.a,.b,.c), .b'),['a:not(.a,.b,.c)', '.b']);25 assert.deepEqual(extract('a:not(.a,.b,[type=text]), .b'),['a:not(.a,.b,[type=text])', '.b']);26 assert.deepEqual(extract('a:not(.a,.b,[type=text, a=b]), .b'),['a:not(.a,.b,[type=text, a=b])', '.b']);27});28it('selector specificity comparison', function() {29 var compare = utils.compare;30 assert.deepEqual(compare([0, 1, 2, 3], [0, 2, 0, 0]),[0, 2, 0, 0]);31 assert.deepEqual(compare([0, 2, 0, 0], [0, 1, 2, 3]),[0, 2, 0, 0]);32 // Check that the second reference is returned upon draws33 var b = [0, 1, 1, 4];34 assert.deepEqual(compare([0, 1, 1, 4], b),b);35 assert.deepEqual(compare([0, 0, 0, 4], [0, 0, 0, 10]),[0, 0, 0, 10]);36 assert.deepEqual(compare([0, 0, 0, 10], [0, 0, 0, 4]),[0, 0, 0, 10]);37 assert.deepEqual(compare([0, 4, 0, 0], [0, 0, 100, 4]),[0, 4, 0, 0]);38 assert.deepEqual(compare([0, 0, 100, 4], [0, 4, 0, 0]),[0, 4, 0, 0]);39 assert.deepEqual(compare([0, 1, 1, 5], [0, 1, 1, 15]),[0, 1, 1, 15]);40 assert.deepEqual(compare([0, 1, 1, 15], [0, 1, 1, 5]),[0, 1, 1, 15]);41});42it('selector specificity calculator', function() {43 function spec(selector) {44 return new Selector(selector).specificity();45 }46 assert.deepEqual(spec('#test'),[0, 1, 0, 0]);47 assert.deepEqual(spec('#a #b #c'),[0, 3, 0, 0]);48 assert.deepEqual(spec('.a .b .c'),[0, 0, 3, 0]);49 assert.deepEqual(spec('div.a div.b div.c'),[0, 0, 3, 3]);50 assert.deepEqual(spec('div a span'),[0, 0, 0, 3]);51 assert.deepEqual(spec('#test input[type=text]'),[0, 1, 1, 1]);52 assert.deepEqual(spec('[type=text]'), [0, 0, 1, 0]);53 assert.deepEqual(spec('*'),[0, 0, 0, 0]);54 assert.deepEqual(spec('div *'),[0, 0, 0, 1]);55 assert.deepEqual(spec('div.a.b'),[0, 0, 2, 1]);56 assert.deepEqual(spec('div:not(.a):not(.b)'),[0, 0, 2, 1]);57 assert.deepEqual(spec('div.a'),[0, 0, 1, 1]);58 assert.deepEqual(spec('.a:first-child'),[0, 0, 1, 1]);59 assert.deepEqual(spec('div:not(.c)'),[0, 0, 1, 1]);60});61it('property comparison based on selector specificity', function() {62 function prop(k, v, sel) {63 return new Property(k, v, new Selector(sel));64 }65 var a = prop('color', 'white', '#woot');66 var b = prop('color', 'red', '#a #woot');67 assert.deepEqual(a.compare(b),b);68 a = prop('background-color', 'red', '#a');69 b = prop('background-color', 'red', '.a.b.c');70 assert.deepEqual(a.compare(b),a);71 a = prop('background-color', 'red', '#a .b.c');72 b = prop('background-color', 'red', '.a.b.c #c');73 assert.deepEqual(a.compare(b),b);74});75it('property toString', function() {76 var a = new Property('color', 'white', new Selector('#woot'));77 assert.equal(a.toString(), 'color: white;');78});79it('parse simple css into a object structure', function() {80 var parse = utils.parseCSS;81 var actual = parse('a, b { c: e; }');82 var a = actual[0];83 var b = actual[1];84 assert.equal(a[0],'a');85 assert.deepEqual(a[1]['0'],{ type: 'property', name: 'c', value: 'e', position: { start: { line: 1, col: 8 }, end: { line: 1, col: 12 } }});86 assert.equal(a[1].length,1);87 assert.deepEqual(a[1],b[1]);88});89it('parse complex css into a object structure', function() {90 var parse = utils.parseCSS;91 var actual = parse(['a, b { c: e; }', 'b.e #d { d: e; }','c[a=b] { d: e; }'].join('\n'));92 var a = actual[0];93 var b = actual[1];94 var bed = actual[2];95 var cab = actual[3];96 /*97 delete bed[1].parentRule;98 delete cab[1].parentRule;99 delete bed[1].__starts;100 delete cab[1].__starts;101 */102 assert.deepEqual(a[1],b[1]);103 assert.equal(bed[1].name,cab[1].name);104 assert.equal(bed[1].value,cab[1].value);105});106it('test excludedProperties setting', function() {107 juice.excludedProperties = ['-webkit-font-smoothing'];108 assert.deepEqual(109 juice(110 '<div a="b">woot</div>',111 {extraCss: 'div { color: blue; -webkit-font-smoothing: antialiased; }'}112 ),113 '<div a="b" style="color: blue;">woot</div>'114 );115 // Reset global setting116 juice.excludedProperties = [];117});118it('test juice', function() {119 assert.deepEqual(120 juice('<div a="b">woot</div>', {extraCss: 'div { color: red; }'}),121 '<div a="b" style="color: red;">woot</div>');122});123it('test consecutive important rules', function() {124 assert.deepEqual(125 juice.inlineContent('<p><a>woot</a></p>', 'p a {color: red !important;} a {color: black !important;}'),126 '<p><a style="color: red;">woot</a></p>');127});128it('test * specificity', function() {129 assert.deepEqual(130 juice.inlineContent('<div class="a"></div><div class="b"></div>',131 '* { margin: 0; padding: 0; } .b { margin: 0 !important; } .a { padding: 20px; }'),132 '<div class="a" style="margin: 0; padding: 20px;"></div><div class="b" style="padding: 0; margin: 0;"></div>');133});134it('test style attributes priority', function() {135 assert.deepEqual(136 juice.inlineContent('<div style="color: red;"></div>', 'div { color: black; }'),137 '<div style="color: red;"></div>');138});139it('test style attributes and important priority', function() {140 assert.deepEqual(141 juice.inlineContent('<div style="color: red;"></div>', 'div { color: black !important; }'),142 '<div style="color: black;"></div>');143});144it('test style attributes and important priority', function() {145 assert.deepEqual(146 juice.inlineContent('<div style="color: red !important;"></div>', 'div { color: black !important; }'),147 '<div style="color: red;"></div>');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var expect = require('chai').expect;3var should = require('chai').should();4describe('Array', function() {5 describe('#indexOf()', function() {6 it('should return -1 when the value is not present', function() {7 assert.equal([1,2,3].indexOf(4), -1);8 });9 });10});11var assert = require('chai').assert;12var expect = require('chai').expect;13var should = require('chai').should();14describe('Array', function() {15 describe('#indexOf()', function() {16 it('should return -1 when the value is not present', function() {17 expect([1,2,3].indexOf(4)).to.equal(-1);18 });19 });20});21var assert = require('chai').assert;22var expect = require('chai').expect;23var should = require('chai').should();24describe('Array', function() {25 describe('#indexOf()', function() {26 it('should return -1 when the value is not present', function() {27 [1,2,3].indexOf(4).should.equal(-1);28 });29 });30});31var chai = require('chai');32describe('Array', function() {33 describe('#indexOf()', function() {34 it('should return -1 when the value is not present', function() {35 assert.equal(-1, [1,2,3].indexOf(4));36 });37 });38});39describe('Array', function() {40 describe('#indexOf()', function() {41 it('should return -1 when the value is not present', function() {42 expect([1,2,3].indexOf(4)).to.equal(-1);43 });44 });45});46describe('Array', function() {47 describe('#indexOf()', function()

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = chai.assert;2var expect = chai.expect;3var should = chai.should();4describe('Array', function() {5 describe('#indexOf()', function() {6 it('should return -1 when the value is not present', function() {7 assert.equal(-1, [1,2,3].indexOf(4));8 });9 });10});11describe('myArray', function() {12 describe('#indexOf()', function() {13 it('should return -1 when the value is not present', function() {14 expect([1,2,3].indexOf(4)).to.equal(-1);15 });16 });17});18describe('myArray', function() {19 describe('#indexOf()', function() {20 it('should return -1 when the value is not present', function() {21 [1,2,3].indexOf(4).should.equal(-1);22 });23 });24});25var assert = chai.assert;26var expect = chai.expect;27var should = chai.should();28describe('Array', function() {29 describe('#indexOf()', function() {30 it('should return -1 when the value is not present', function() {31 assert.equal(-1, [1,2,3].indexOf(4));32 });33 });34});35describe('myArray', function() {36 describe('#indexOf()', function() {37 it('should return -1 when the value is not present', function() {38 expect([1,2,3].indexOf(4)).to.equal(-1);39 });40 });41});42describe('myArray', function() {43 describe('#indexOf()', function() {44 it('should return -1 when the value is not present', function() {45 [1,2,3].indexOf(4).should.equal(-1);46 });47 });48});49let chai = require('chai');50let chaiHttp = require('chai-http');51let server = require('../app');52let should = chai.should();53chai.use(chaiHttp);54describe('Users', () => {55 describe('/GET user', () => {56 it('it should GET all the users', (done) => {57 chai.request(server)58 .get('/users')59 .end((err, res) => {60 res.should.have.status(200);61 res.body.should.be.a('array');62 res.body.length.should.be.eql(0);

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2var assert = require('chai').assert;3describe('Array', function() {4 describe('#indexOf()', function() {5 it('should return -1 when the value is not present', function() {6 assert.equal(-1, [1,2,3].indexOf(4));7 });8 });9});10var expect = require('chai').expect;11var assert = require('chai').assert;12describe('Array', function() {13 describe('#indexOf()', function() {14 it('should return -1 when the value is not present', function() {15 expect([1,2,3].indexOf(4)).to.equal(-1);16 });17 });18});19var expect = require('chai').expect;20var assert = require('chai').assert;21describe('Array', function() {22 describe('#indexOf()', function() {23 it('should return -1 when the value is not present', function() {24 assert.deepEqual([1,2,3].indexOf(4), -1);25 });26 });27});28var expect = require('chai').expect;29var assert = require('chai').assert;30describe('Array', function() {31 describe('#indexOf()', function() {32 it('should return -1 when the value is not present', function() {33 expect([1,2,3].indexOf(4)).to.not.equal(4);34 });35 });36});37var expect = require('chai').expect;38var assert = require('chai').assert;39describe('Array', function() {40 describe('#indexOf()', function() {41 it('should return -1 when the value is not present', function() {42 assert.notEqual([1,2,3].indexOf(4), 4);43 });44 });45});46var expect = require('chai').expect;47var assert = require('chai').assert;48describe('Array', function() {49 describe('#indexOf()', function() {50 it('should return -1 when the value is not present', function() {

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const app = require('../app');3sayHelloResult = app.sayHello();4addNumbersResult = app.addNumbers(5,5);5describe('App', function(){6 describe('sayHello()', function(){7 it('sayHello should return hello', function(){8 assert.equal(sayHelloResult, 'hello');9 });10 it('sayHello should return type string', function(){11 assert.typeOf(sayHelloResult, 'string');12 });13 });14 describe('addNumbers()', function(){15 it('addNumbers should be above 5', function(){16 assert.isAbove(addNumbersResult, 5);17 });18 it('addNumbers should return type number', function(){19 assert.typeOf(addNumbersResult, 'number');20 });21 });22});23const sayHello = function(){24 return 'hello';25}26const addNumbers = function(value1, value2){27 return value1 + value2;28}29module.exports = {30}31const assert = require('chai').assert;32const app = require('../app');33sayHelloResult = app.sayHello();34describe('App', function(){35 describe('sayHello()', function(){36 it('sayHello should return hello', function(){37 assert.equal(sayHelloResult, 'hello');38 });39 it('sayHello should return type string', function(){

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const expect = require('chai').expect;3const should = require('chai').should();4describe('Array', function() {5 describe('#indexOf()', function() {6 it('should return -1 when the value is not present', function() {7 assert.equal([1,2,3].indexOf(4), -1);8 });9 });10});11const assert = require('chai').assert;12const expect = require('chai').expect;13const should = require('chai').should();14describe('Array', function() {15 describe('#indexOf()', function() {16 it('should return -1 when the value is not present', function() {17 expect([1,2,3].indexOf(4)).to.equal(-1);18 });19 });20});21const assert = require('chai').assert;22const expect = require('chai').expect;23const should = require('chai').should();24describe('Array', function() {25 describe('#indexOf()', function() {26 it('should return -1 when the value is not present', function() {27 [1,2,3].indexOf(4).should.equal(-1);28 });29 });30});31const assert = require('chai').assert;32const expect = require('chai').expect;33const should = require('chai').should();34describe('Array', function() {35 describe('#indexOf()', function() {36 it('should return -1 when the value is not present', function() {37 assert.equal([1,2,3].indexOf(4), -1);38 });39 });40});41const assert = require('chai').assert;42const expect = require('chai').expect;43const should = require('chai').should();44describe('Array', function() {45 describe('#indexOf()', function() {46 it('should return -1 when the value is not present', function() {47 assert.notEqual([1,2,3].indexOf(4), -1);48 });49 });50});51const assert = require('chai').assert;52const expect = require('chai').expect;53const should = require('chai').should();54describe('Array', function() {55 describe('#indexOf()',

Full Screen

Using AI Code Generation

copy

Full Screen

1var expect = require('chai').expect;2var assert = require('chai').assert;3var should = require('chai').should();4var equal = require('chai').equal;5var be = require('chai').be;6var a = require('chai').a;7var an = require('chai').an;8var include = require('chai').include;9var ok = require('chai').ok;10var true = require('chai').true;11var false = require('chai').false;12var null = require('chai').null;13var undefined = require('chai').undefined;14var typeof = require('chai').typeof;15var instanceOf = require('chai').instanceOf;16var property = require('chai').property;17var lengthOf = require('chai').lengthOf;18var match = require('chai').match;19var string = require('chai').string;20var keys = require('chai').keys;21var throw = require('chai').throw;22var respondTo = require('chai').respondTo;23var itself = require('chai').itself;24var satisfy = require('chai').satisfy;25var closeTo = require('chai').closeTo;26var members = require('chai').members;27var oneOf = require('chai').oneOf;

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('chai').assert;2const { sayHello, addNumbers } = require('../app');3sayHelloResult = sayHello();4addNumbersResult = addNumbers(5,5);5describe('App', function(){6 describe('sayHello()', function(){7 it('sayHello should return hello', function(){8 assert.equal(sayHelloResult, 'hello');9 });10 it('sayHello should return type string', function(){11 assert.typeOf(sayHelloResult, 'string');12 });13 });14 describe('addNumbers()', function(){15 it('addNumbers should be above 5', function(){16 assert.isAbove(addNumbersResult, 5);17 });18 it('addNumbers should return type number', function(){19 assert.typeOf(addNumbersResult, 'number');20 });21 });22});23module.exports = {24 sayHello: function(){25 return 'hello';26 },27 addNumbers: function(value1, value2){28 return value1 + value2;29 }30};

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('chai').assert;2var expect = require('chai').expect;3var should = require('chai').should();4var obj1 = {5};6var obj2 = {7};8var obj3 = {9};10describe('Test for deepEqual method of chai', function(){11 it('Should return true if both objects are equal', function(){12 assert.deepEqual(obj1, obj2);13 });14 it('Should return false if both objects are not equal', function(){15 assert.notDeepEqual(obj1, obj3);16 });17});18 AssertionError: expected { a: 1, b: 2, c: 3 } to deeply equal { a: 1, b: 2, c: 3 }19 -{"a":1,"b":2,"c":3}20 +{"a":1,"b":2,"c":3}21 AssertionError: expected { a: 1, b: 2, c: 3 } to not deeply equal { a: 1, b: 2, d: 4 }22 -{"a":1,"b":2,"c":3}23 +{"a":1,"b":2,"d":4}24 0 passing (12ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const expect = require('chai').expect;3const should = require('chai').should();4const {deepEqual} = require('chai').assert;5const {deepStrictEqual} = require('chai').assert;6describe('Test Suite', function() {7 it('should be equal', function() {8 assert.equal(1, '1');9 });10 it('should be deep equal', function() {11 assert.deepEqual({a:1}, {a:'1'});12 });13 it('should be deep equal', function() {14 assert.deepStrictEqual({a:1}, {a:'1'});15 });16 it('should be equal', function() {17 expect(1).to.equal('1');18 });19 it('should be deep equal', function() {20 expect({a:1}).to.deep.equal({a:'1'});21 });22 it('should be deep equal', function() {23 expect({a:1}).to.deep.equal({a:'1'});24 });25 it('should be equal', function() {26 (1).should.equal('1');27 });28 it('should be deep equal', function() {29 ({a:1}).should.deep.equal({a:'1'});30 });31 it('should be deep equal', function() {32 ({a:1}).should.deep.equal({a:'1'});33 });34 it('should be equal', function() {35 deepEqual(1, '1');36 });37 it('should be deep equal', function() {38 deepEqual({a:1}, {a:'1'});39 });40 it('should be deep equal', function() {41 deepStrictEqual({a:1}, {a:'1'});42 });43});44 12 passing (12ms)

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 chai 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