How to use deepEqual method in mountebank

Best JavaScript code snippet using mountebank

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

1const assert = require('assert');2const mb = require('mountebank');3const imposter = {4 {5 {6 is: {7 }8 }9 }10};11mb.create(imposter).then(function (imposter) {12 const client = imposter.client();13 return client.get('/', { json: true })14 .then(function (response) {15 assert.deepEqual(response.body, 'Hello World!');16 return imposter.del();17 });18});19const assert = require('assert');20const mb = require('mountebank');21const imposter = {22 {23 {24 is: {25 }26 }27 }28};29mb.create(imposter).then(function (imposter) {30 const client = imposter.client();31 return client.get('/', { json: true })32 .then(function (response) {33 assert.deepEqual(response.body, 'Hello World!');34 return imposter.del();35 });36});37const assert = require('assert');38const mb = require('mountebank');39const imposter = {40 {41 {42 is: {43 }44 }45 }46};47mb.create(imposter).then(function (imposter) {48 const client = imposter.client();49 return client.get('/', { json: true })50 .then(function (response) {51 assert.deepEqual(response.body, 'Hello World!');52 return imposter.del();53 });54});55const assert = require('assert');56const mb = require('mountebank');57const imposter = {58 {59 {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var imposter = {4 {5 {6 is: {7 headers: {8 },9 }10 }11 }12};13mb.create(imposter, function (error, imposter) {14 assert.deepStrictEqual(error, null);15 assert.strictEqual(imposter.port, 3000);16 assert.strictEqual(imposter.protocol, 'http');17 assert.strictEqual(imposter.stubs[0].responses[0].is.statusCode, 200);18 assert.strictEqual(imposter.stubs[0].responses[0].is.headers['Content-Type'], 'text/plain');19 assert.strictEqual(imposter.stubs[0].responses[0].is.body, 'Hello world!');20});21var assert = require('assert');22var mb = require('mountebank');23var imposter = {24 {25 {26 is: {27 headers: {28 },29 }30 }31 }32};33mb.create(imposter, function (error, imposter) {34 assert.deepStrictEqual(error, null);35 assert.strictEqual(imposter.port, 3000);36 assert.strictEqual(imposter.protocol, 'http');37 assert.strictEqual(imposter.stubs[0].responses[0].is.statusCode, 200);38 assert.strictEqual(imposter.stubs[0].responses[0].is.headers['Content-Type'], 'text/plain');39 assert.strictEqual(imposter.stubs[0].responses[0].is.body, 'Hello world!');40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var imposter = {4 {5 {6 "is": {7 }8 }9 }10};11mb.create(imposter).then(function (server) {12 return mb.get('/').then(function (response) {13 assert.deepEqual(response.body, 'Hello world!');14 server.close();15 });16});17var assert = require('assert');18var supertest = require('supertest');19var app = require('../app');20describe('GET /', function () {21 it('respond with Hello world!', function (done) {22 supertest(app).get('/').expect(200).end(function (err, res) {23 assert.deepEqual(res.text, 'Hello world!');24 done();25 });26 });27});28var chai = require('chai');29var chaiHttp = require('chai-http');30var server = require('../app');31var should = chai.should();32chai.use(chaiHttp);33describe('GET /', function () {34 it('respond with Hello world!', function (done) {35 chai.request(server).get('/').end(function (err, res) {36 res.should.have.status(200);37 res.should.be.html;38 res.text.should.be.equal('Hello world!');39 done();40 });41 });42});43var assert = require('assert');44var request = require('request');45describe('GET /', function () {46 it('respond with Hello world!', function (done) {47 assert.deepEqual(body, 'Hello world!');48 done();49 });50 });51});52var assert = require('assert');53var supertest = require('supertest');54var app = require('../app');55describe('GET /', function () {56 it('respond with Hello world!', function (done) {57 supertest(app).get('/').expect(200).end(function (err, res) {58 assert.deepEqual(res.text, 'Hello world!');59 done();60 });61 });62});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var port = 2525;4var protocol = 'http';5var host = 'localhost';6var imposter = {7 {8 {9 equals: {10 }11 }12 {13 is: {14 headers: {15 },16 }17 }18 }19};20mb.create(url, imposter).then(function (response) {21 assert.deepEqual(response, {22 {23 {24 equals: {25 }26 }27 {28 is: {29 headers: {30 },31 }32 }33 }34 _links: {35 self: {36 }37 }38 });39});40var chai = require('chai');41var assert = chai.assert;42var expect = chai.expect;43var should = chai.should();44var mb = require('mountebank');45var port = 2525;46var protocol = 'http';47var host = 'localhost';48var imposter = {49 {50 {51 equals: {52 }53 }54 {55 is: {56 headers: {57 },58 }59 }60 }61};62mb.create(url, imposter).then(function (response) {63 assert.deepEqual(response, {

Full Screen

Using AI Code Generation

copy

Full Screen

1const assert = require('assert');2const mb = require('mountebank');3mb.create({4}).then(function (imposter) {5 return imposter.post('/test', {statusCode: 200, body: 'Hello, World!'});6}).then(function (response) {7 assert.deepEqual(response.body, 'Hello, World!');8}).then(function () {9 return mb.stopAll();10}).catch(function (error) {11 console.error(error);12 return mb.stopAll();13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var imposter = mb.create({4 {5 {6 "is": {7 }8 }9 }10});11mb.start().then(function () {12 return imposter.post();13}).then(function () {14 return imposter.get();15}).then(function (response) {16 assert.deepEqual(response.body, "Hello world!");17}).finally(function () {18 mb.stop();19});20var assert = require('assert');21var mb = require('mountebank');22var imposter = mb.create({23 {24 {25 "is": {26 }27 }28 }29});30mb.start().then(function () {31 return imposter.post();32}).then(function () {33 return imposter.get();34}).then(function (response) {35 assert.deepEqual(response.body, "Hello world!");36}).finally(function () {37 mb.stop();38});39var assert = require('assert');40var mb = require('mountebank');41var imposter = mb.create({42 {43 {44 "is": {45 }46 }47 }48});49mb.start().then(function () {50 return imposter.post();51}).then(function () {52 return imposter.get();53}).then(function (response) {54 assert.deepEqual(response.body, "Hello world!");55}).finally(function () {56 mb.stop();57});58var assert = require('assert');59var mb = require('mountebank');60var imposter = mb.create({61 {62 {63 "is": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var impostor = {4 {5 {6 is: {7 headers: {8 },9 body: {10 }11 }12 }13 }14};15var impostor2 = {16 {17 {18 is: {19 headers: {20 },21 body: {22 }23 }24 }25 }26};27mb.create(impostor, function (error, impostor) {28 assert.ifError(error);29 assert.deepEqual(impostor, impostor2);30});31mb.delete(impostor.port, function (error) {32 assert.ifError(error);33});34mb.deleteAll(function (error) {35 assert.ifError(error);36});37mb.get(function (error, impostors) {38 assert.ifError(error);39 assert.deepEqual(impostors, impostor2);40});41mb.get(impostor.port, function (error, impostor) {42 assert.ifError(error);43 assert.deepEqual(impostor, impostor2);44});45mb.logs(impostor.port, function (error, logs) {46 assert.ifError(error);47 assert.deepEqual(logs, impostor2);48});49mb.resetLogs(impostor.port, function (error) {50 assert.ifError(error);51});52mb.resetAllLogs(function (error) {53 assert.ifError(error);54});55mb.verify(impostor, function (error, result) {56 assert.ifError(error);57 assert.deepEqual(result, impostor2);

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var mb = require('mountebank');3var test = mb.test;4test('test deepEqual', function (done) {5 var expected = { "name": "test" };6 var actual = { "name": "test" };7 test.deepEqual(actual, expected);8 done();9});10test('test notDeepEqual', function (done) {11 var expected = { "name": "test" };12 var actual = { "name": "test1" };13 test.notDeepEqual(actual, expected);14 done();15});16test('test equal', function (done) {17 var expected = "test";18 var actual = "test";19 test.equal(actual, expected);20 done();21});22test('test notEqual', function (done) {23 var expected = "test";24 var actual = "test1";25 test.notEqual(actual, expected);26 done();27});28test('test ok', function (done) {29 var expected = true;30 test.ok(expected);31 done();32});33test('test notOk', function (done) {34 var expected = false;35 test.notOk(expected);36 done();37});38test('test strictEqual', function (done) {39 var expected = "test";40 var actual = "test";41 test.strictEqual(actual, expected);42 done();43});44test('test notStrictEqual', function (done) {45 var expected = "test";46 var actual = "test1";47 test.notStrictEqual(actual, expected);48 done();49});50test('test throws', function (done) {51 var expected = "test";52 var actual = "test1";53 test.throws(function () { test.notStrictEqual(actual, expected); }, Error, "test throws");54 done();55});56test('test doesNotThrow', function (done) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require("assert");2var config = require("./config.json");3var mb = require('mountebank');4var imposter = {5 {6 {7 is: {8 body: { "message": "Hello World" }9 }10 }11 }12};13mb.create(imposter).then(function () {14 return mb.get('/message', config.port);15}).then(function (response) {16 assert.deepEqual(response.body, { "message": "Hello World" });17 console.log(response.body);18 return mb.del(config.port);19}).then(function () {20 console.log('done');21});22{23}24{ message: 'Hello World' }

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