<commit_before>/**
 * Copyright (c) 2014, 2016 <NAME>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

'use strict';

var assert = require('assert');

var escaper = require('./index');

var obj;

/* escape */

/* don't fall over numbers */
obj = 0;
escaper.escape(obj);
assert.deepEqual(obj, 0, 'don\'t fall over numbers');

/* don't fall over strings */
obj = '';
escaper.escape(obj);
assert.deepEqual(obj, '', 'don\'t fall over empty string');

obj = '$set';
escaper.escape(obj);
assert.deepEqual(obj, '$set', 'don\'t fall over string');

obj = {};
escaper.escape(obj);
assert.deepEqual(obj, {}, 'escape empty object');

obj = { $: '$', 'foo.bar': { $: '$' } };
escaper.escape(obj, false);
assert.deepEqual(obj, { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } }, 'should not recurse');

obj = { $: '$', 'foo.bar': { $: '$' } };
escaper.escape(obj, false);
escaper.escape(obj, false);
assert.deepEqual(obj, { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } }, 'should be idempotent');

obj = { $: '$', foo: { $: '$', bar: { 'some.foo': 'other' } }, a: 'b' };
escaper.escape(obj);
assert.deepEqual(obj, { '\uFF04': '$', foo: { '\uFF04': '$', bar: { 'some\uFF0Efoo': 'other' } }, a: 'b' }, 'should recurse by default');

obj = [ { $: '$', 'foo.bar': { $: '$' } }, { $: [ '$', { 'foo.qux': { $: '$' } } ], 'foo.baz': { $: '$' } } ];
escaper.escape(obj);
assert.deepEqual(obj, [ { '\uFF04': '$', 'foo\uFF0Ebar': { '\uFF04': '$' } }, { '\uFF04': [ '$', { 'foo\uFF0Equx': { '\uFF04': '$' } } ], 'foo\uFF0Ebaz': { '\uFF04': '$' } } ], 'should recurse on array values');

/* unescape */

/* don't fall over strings */
obj = '';
escaper.unescape(obj);
assert.deepEqual(obj, '', 'don\'t fall over empty string');

obj = '$set';
escaper.unescape(obj);
assert.deepEqual(obj, '$set', 'don\'t fall over string');

obj = {};
escaper.unescape(obj);
assert.deepEqual(obj, {}, 'unescape empty object');

obj = { 'a': 'b' };
escaper.escape(obj, true);
assert.deepEqual(obj, { 'a': 'b' }, 'should return original object');

obj = { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } };
escaper.unescape(obj, false);
assert.deepEqual(obj, { $: '$', 'foo.bar': { $: '$' } }, 'should not recurse');

obj = { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } };
escaper.unescape(obj, false);
escaper.unescape(obj, false);
assert.deepEqual(obj, { $: '$', 'foo.bar': { $: '$' } }, 'should be idempotent');

obj = { '\uFF04': '$', foo: { '\uFF04': '$', bar: { 'some\uFF0Efoo': 'other' } }, a: 'b' };
escaper.unescape(obj);
assert.deepEqual(obj, { $: '$', foo: { $: '$', bar: { 'some.foo': 'other' } }, a: 'b' }, 'should recurse by default');<commit_msg>tests: use strict check for non-object checking<commit_after>/**
 * Copyright (c) 2014, 2016 <NAME>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

'use strict';

var assert = require('assert');

var escaper = require('./index');

var obj;

/* escape */

/* don't fall over numbers */
obj = 0;
escaper.escape(obj);
assert.strictEqual(obj, 0, 'don\'t fall over numbers');

/* don't fall over strings */
obj = '';
escaper.escape(obj);
assert.strictEqual(obj, '', 'don\'t fall over empty string');

obj = '$set';
escaper.escape(obj);
assert.strictEqual(obj, '$set', 'don\'t fall over string');

obj = {};
escaper.escape(obj);
assert.deepEqual(obj, {}, 'escape empty object');

obj = { $: '$', 'foo.bar': { $: '$' } };
escaper.escape(obj, false);
assert.deepEqual(obj, { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } }, 'should not recurse');

obj = { $: '$', 'foo.bar': { $: '$' } };
escaper.escape(obj, false);
escaper.escape(obj, false);
assert.deepEqual(obj, { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } }, 'should be idempotent');

obj = { $: '$', foo: { $: '$', bar: { 'some.foo': 'other' } }, a: 'b' };
escaper.escape(obj);
assert.deepEqual(obj, { '\uFF04': '$', foo: { '\uFF04': '$', bar: { 'some\uFF0Efoo': 'other' } }, a: 'b' }, 'should recurse by default');

obj = [ { $: '$', 'foo.bar': { $: '$' } }, { $: [ '$', { 'foo.qux': { $: '$' } } ], 'foo.baz': { $: '$' } } ];
escaper.escape(obj);
assert.deepEqual(obj, [ { '\uFF04': '$', 'foo\uFF0Ebar': { '\uFF04': '$' } }, { '\uFF04': [ '$', { 'foo\uFF0Equx': { '\uFF04': '$' } } ], 'foo\uFF0Ebaz': { '\uFF04': '$' } } ], 'should recurse on array values');

/* unescape */

/* don't fall over strings */
obj = '';
escaper.unescape(obj);
assert.strictEqual(obj, '', 'don\'t fall over empty string');

obj = '$set';
escaper.unescape(obj);
assert.strictEqual(obj, '$set', 'don\'t fall over string');

obj = {};
escaper.unescape(obj);
assert.deepEqual(obj, {}, 'unescape empty object');

obj = { 'a': 'b' };
escaper.escape(obj, true);
assert.deepEqual(obj, { 'a': 'b' }, 'should return original object');

obj = { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } };
escaper.unescape(obj, false);
assert.deepEqual(obj, { $: '$', 'foo.bar': { $: '$' } }, 'should not recurse');

obj = { '\uFF04': '$', 'foo\uFF0Ebar': { $: '$' } };
escaper.unescape(obj, false);
escaper.unescape(obj, false);
assert.deepEqual(obj, { $: '$', 'foo.bar': { $: '$' } }, 'should be idempotent');

obj = { '\uFF04': '$', foo: { '\uFF04': '$', bar: { 'some\uFF0Efoo': 'other' } }, a: 'b' };
escaper.unescape(obj);
assert.deepEqual(obj, { $: '$', foo: { $: '$', bar: { 'some.foo': 'other' } }, a: 'b' }, 'should recurse by default');
{'fraction_non_alphanumeric': 0.2338368580060423, 'fraction_numerical': 0.013595166163141994, 'mean_word_length': 4.229857819905213, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5019360', 'n_tokens_mistral': 2462, 'n_tokens_neox': 2409, 'n_words': 631}