Uname:Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64

403WebShell
403Webshell
Server IP : 82.148.16.210  /  Your IP : 216.73.216.32
Web Server : nginx/1.29.5
System : Linux mail.sarafai.ru 6.1.0-43-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.162-1 (2026-02-08) x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /srv/projects/env4/src/dev/frontend3/node_modules/table/node_modules/traverse/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /srv/projects/env4/src/dev/frontend3/node_modules/table/node_modules/traverse/test/mutability.js
'use strict';

var test = require('tape');
var assert = require('assert');
var traverse = require('../');
var deepEqual = require('./lib/deep_equal');

test('mutate', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).forEach(function (x) {
		if (typeof x === 'number' && x % 2 === 0) {
			this.update(x * 10);
		}
	});
	t.same(obj, res);
	t.same(obj, { a: 1, b: 20, c: [3, 40] });
	t.end();
});

test('mutateT', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse.forEach(obj, function (x) {
		if (typeof x === 'number' && x % 2 === 0) {
			this.update(x * 10);
		}
	});
	t.same(obj, res);
	t.same(obj, { a: 1, b: 20, c: [3, 40] });
	t.end();
});

test('map', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).map(function (x) {
		if (typeof x === 'number' && x % 2 === 0) {
			this.update(x * 10);
		}
	});
	t.same(obj, { a: 1, b: 2, c: [3, 4] });
	t.same(res, { a: 1, b: 20, c: [3, 40] });
	t.end();
});

test('mapT', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse.map(obj, function (x) {
		if (typeof x === 'number' && x % 2 === 0) {
			this.update(x * 10);
		}
	});
	t.same(obj, { a: 1, b: 2, c: [3, 4] });
	t.same(res, { a: 1, b: 20, c: [3, 40] });
	t.end();
});

test('clone', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).clone();
	t.same(obj, res);
	t.ok(obj !== res);
	obj.a += 1;
	t.same(res.a, 1);
	obj.c.push(5);
	t.same(res.c, [3, 4]);
	t.end();
});

test('cloneT', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse.clone(obj);
	t.same(obj, res);
	t.ok(obj !== res);
	obj.a += 1;
	t.same(res.a, 1);
	obj.c.push(5);
	t.same(res.c, [3, 4]);
	t.end();
});

test('cloneTypedArray', { skip: typeof Uint8Array !== 'function' }, function (t) {
	var obj = new Uint8Array([1]);
	var res = traverse.clone(obj);

	t.same(obj, res);
	t.ok(obj !== res);
	obj.set([2], 0);
	res.set([3], 0);
	t.same(obj, new Uint8Array([2]));
	t.same(res, new Uint8Array([3]));
	t.end();
});

test('reduce', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).reduce(function (acc, x) {
		if (this.isLeaf) { acc.push(x); }
		return acc;
	}, []);
	t.same(obj, { a: 1, b: 2, c: [3, 4] });
	t.same(res, [1, 2, 3, 4]);
	t.end();
});

test('reduceInit', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).reduce(function (acc) {
		if (this.isRoot) { assert.fail('got root'); }
		return acc;
	});
	t.same(obj, { a: 1, b: 2, c: [3, 4] });
	t.same(res, obj);
	t.end();
});

test('remove', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	traverse(obj).forEach(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.remove(); }
	});

	t.same(obj, { a: 1, c: [3] });
	t.end();
});

test('removeNoStop', function (t) {
	var obj = { a: 1, b: 2, c: { d: 3, e: 4 }, f: 5 };

	var keys = [];
	traverse(obj).forEach(function () {
		keys.push(this.key);
		if (this.key === 'c') { this.remove(); }
	});

	t.same(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f']);
	t.end();
});

test('removeStop', function (t) {
	var obj = { a: 1, b: 2, c: { d: 3, e: 4 }, f: 5 };

	var keys = [];
	traverse(obj).forEach(function () {
		keys.push(this.key);
		if (this.key === 'c') { this.remove(true); }
	});

	t.same(keys, [undefined, 'a', 'b', 'c', 'f']);
	t.end();
});

test('removeMap', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).map(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.remove(); }
	});

	t.same(obj, { a: 1, b: 2, c: [3, 4] });
	t.same(res, { a: 1, c: [3] });
	t.end();
});

test('delete', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	traverse(obj).forEach(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.delete(); }
	});

	t.ok(!deepEqual(obj, { a: 1, c: [3, undefined] }));

	t.ok(deepEqual(obj, { a: 1, c: [3] }));

	t.ok(!deepEqual(obj, { a: 1, c: [3, null] }));
	t.end();
});

test('deleteNoStop', function (t) {
	var obj = { a: 1, b: 2, c: { d: 3, e: 4 } };

	var keys = [];
	traverse(obj).forEach(function () {
		keys.push(this.key);
		if (this.key === 'c') { this.delete(); }
	});

	t.same(keys, [undefined, 'a', 'b', 'c', 'd', 'e']);
	t.end();
});

test('deleteStop', function (t) {
	var obj = { a: 1, b: 2, c: { d: 3, e: 4 } };

	var keys = [];
	traverse(obj).forEach(function () {
		keys.push(this.key);
		if (this.key === 'c') { this.delete(true); }
	});

	t.same(keys, [undefined, 'a', 'b', 'c']);
	t.end();
});

test('deleteRedux', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4, 5] };
	traverse(obj).forEach(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.delete(); }
	});

	t.ok(!deepEqual(obj, { a: 1, c: [3, undefined, 5] }));

	// eslint-disable-next-line no-sparse-arrays
	t.ok(deepEqual(obj, { a: 1, c: [3,, 5] }));

	t.ok(!deepEqual(obj, { a: 1, c: [3, null, 5] }));

	t.ok(!deepEqual(obj, { a: 1, c: [3, 5] }));

	t.end();
});

test('deleteMap', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).map(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.delete(); }
	});

	t.ok(deepEqual(
		obj,
		{ a: 1, b: 2, c: [3, 4] }
	));

	var xs = [3, 4];
	delete xs[1];

	t.ok(deepEqual(res, { a: 1, c: xs }));

	// eslint-disable-next-line comma-spacing, no-sparse-arrays
	t.ok(deepEqual(res, { a: 1, c: [3,,] }));

	t.ok(deepEqual(res, { a: 1, c: [3] }));

	t.end();
});

test('deleteMapRedux', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4, 5] };
	var res = traverse(obj).map(function (x) {
		if (this.isLeaf && x % 2 === 0) { this.delete(); }
	});

	t.ok(deepEqual(
		obj,
		{ a: 1, b: 2, c: [3, 4, 5] }
	));

	var xs = [3, 4, 5];
	delete xs[1];

	t.ok(deepEqual(res, { a: 1, c: xs }));

	t.ok(!deepEqual(res, { a: 1, c: [3, 5] }));

	// eslint-disable-next-line no-sparse-arrays
	t.ok(deepEqual(res, { a: 1, c: [3,, 5] }));

	t.end();
});

test('objectToString', function (t) {
	var obj = { a: 1, b: 2, c: [3, 4] };
	var res = traverse(obj).forEach(function (x) {
		if (typeof x === 'object' && !this.isRoot) {
			this.update(JSON.stringify(x));
		}
	});
	t.same(obj, res);
	t.same(obj, { a: 1, b: 2, c: '[3,4]' });
	t.end();
});

test('stringToObject', function (t) {
	var obj = { a: 1, b: 2, c: '[3,4]' };
	var res = traverse(obj).forEach(function (x) {
		if (typeof x === 'string') {
			this.update(JSON.parse(x));
		} else if (typeof x === 'number' && x % 2 === 0) {
			this.update(x * 10);
		}
	});
	t.deepEqual(obj, res);
	t.deepEqual(obj, { a: 1, b: 20, c: [3, 40] });
	t.end();
});

Youez - 2016 - github.com/yon3zu
LinuXploit