mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge branch 'dev' into yarn
Conflicts: dist/index.js package.json scripts/test-coveralls scripts/test-full scripts/test-mocha
This commit is contained in:
+2
-2
@@ -58,8 +58,6 @@ describe('BinaryExpressionControlFlowReplacer', () => {
|
||||
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp1);
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp2);
|
||||
assert.isOk(firstMatch);
|
||||
assert.isOk(secondMatch);
|
||||
|
||||
if (firstMatch === secondMatch) {
|
||||
equalsValue++;
|
||||
@@ -67,6 +65,8 @@ describe('BinaryExpressionControlFlowReplacer', () => {
|
||||
}
|
||||
|
||||
assert.closeTo(equalsValue / samplesCount, expectedValue, delta);
|
||||
|
||||
console.log(equalsValue / samplesCount);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -58,8 +58,6 @@ describe('CallExpressionControlFlowReplacer', () => {
|
||||
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp1);
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp2);
|
||||
assert.isOk(firstMatch);
|
||||
assert.isOk(secondMatch);
|
||||
|
||||
if (firstMatch === secondMatch) {
|
||||
equalsValue++;
|
||||
@@ -67,6 +65,8 @@ describe('CallExpressionControlFlowReplacer', () => {
|
||||
}
|
||||
|
||||
assert.closeTo(equalsValue / samplesCount, expectedValue, delta);
|
||||
|
||||
console.log(equalsValue / samplesCount);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+2
-2
@@ -58,8 +58,6 @@ describe('LogicalExpressionControlFlowReplacer', () => {
|
||||
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp1);
|
||||
assert.match(obfuscatedCode, controlFlowStorageCallRegExp2);
|
||||
assert.isOk(firstMatch);
|
||||
assert.isOk(secondMatch);
|
||||
|
||||
if (firstMatch === secondMatch) {
|
||||
equalsValue++;
|
||||
@@ -67,6 +65,8 @@ describe('LogicalExpressionControlFlowReplacer', () => {
|
||||
}
|
||||
|
||||
assert.closeTo(equalsValue / samplesCount, expectedValue, delta);
|
||||
|
||||
console.log(equalsValue / samplesCount);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+120
@@ -52,4 +52,124 @@ describe('FunctionTransformer', () => {
|
||||
assert.match(obfuscatedCode, functionBodyMatch);
|
||||
});
|
||||
});
|
||||
|
||||
describe('assignment pattern as parameter', () => {
|
||||
describe('literal as right value', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-1.js'),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
it('should transform function parameter assignment pattern identifier', () => {
|
||||
const functionParameterMatch: RegExp = /function *\(_0x[a-f0-9]{4,6} *= *0x1\) *\{/;
|
||||
const functionBodyMatch: RegExp = /return *_0x[a-f0-9]{4,6};/;
|
||||
|
||||
assert.match(obfuscatedCode, functionParameterMatch);
|
||||
assert.match(obfuscatedCode, functionBodyMatch);
|
||||
});
|
||||
});
|
||||
|
||||
describe('identifier as right value', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-2.js'),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
const variableDeclarationMatch: RegExp = /var *(_0x[a-f0-9]{4,6}) *= *0x1;/;
|
||||
const functionParameterMatch: RegExp = /function *\((_0x[a-f0-9]{4,6}) *= *(_0x[a-f0-9]{4,6})\) *\{/;
|
||||
const functionBodyMatch: RegExp = /return *(_0x[a-f0-9]{4,6});/;
|
||||
|
||||
const variableDeclarationIdentifierName: string = obfuscatedCode.match(variableDeclarationMatch)![1];
|
||||
const functionParameterIdentifierName: string = obfuscatedCode.match(functionParameterMatch)![1];
|
||||
const functionDefaultParameterIdentifierName: string = obfuscatedCode.match(functionParameterMatch)![2];
|
||||
|
||||
const functionBodyIdentifierName: string = obfuscatedCode.match(functionBodyMatch)![1];
|
||||
|
||||
it('should transform function parameter assignment pattern identifier', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationMatch);
|
||||
assert.match(obfuscatedCode, functionParameterMatch);
|
||||
assert.match(obfuscatedCode, functionBodyMatch);
|
||||
});
|
||||
|
||||
it('should keep same names for identifier in variable declaration and default value identifier of function parameter', () => {
|
||||
assert.equal(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName);
|
||||
});
|
||||
|
||||
it('should keep same names for identifiers in function params and function body', () => {
|
||||
assert.equal(functionParameterIdentifierName, functionBodyIdentifierName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('identifier as right value', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(__dirname + '/fixtures/assignment-pattern-as-parameter-3.js'),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
const variableDeclarationMatch: RegExp = /var *(_0x[a-f0-9]{4,6}) *= *0x1;/;
|
||||
const functionParameterMatch: RegExp = /function *\((_0x[a-f0-9]{4,6}), *(_0x[a-f0-9]{4,6}) *= *(_0x[a-f0-9]{4,6})\) *\{/;
|
||||
const functionBodyMatch: RegExp = /return *(_0x[a-f0-9]{4,6}) *\+ *(_0x[a-f0-9]{4,6});/;
|
||||
|
||||
const variableDeclarationIdentifierName: string = obfuscatedCode.match(variableDeclarationMatch)![1];
|
||||
const functionParameterIdentifierName: string = obfuscatedCode.match(functionParameterMatch)![1];
|
||||
const functionDefaultParameterIdentifierName1: string = obfuscatedCode.match(functionParameterMatch)![2];
|
||||
const functionDefaultParameterIdentifierName2: string = obfuscatedCode.match(functionParameterMatch)![3];
|
||||
|
||||
const functionBodyIdentifierName1: string = obfuscatedCode.match(functionBodyMatch)![1];
|
||||
const functionBodyIdentifierName2: string = obfuscatedCode.match(functionBodyMatch)![2];
|
||||
|
||||
it('should transform function parameter assignment pattern identifier', () => {
|
||||
assert.match(obfuscatedCode, variableDeclarationMatch);
|
||||
assert.match(obfuscatedCode, functionParameterMatch);
|
||||
assert.match(obfuscatedCode, functionBodyMatch);
|
||||
});
|
||||
|
||||
it('shouldn\'t keep same names variable declaration identifier and function parameters identifiers', () => {
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionParameterIdentifierName);
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName1);
|
||||
assert.notEqual(variableDeclarationIdentifierName, functionDefaultParameterIdentifierName2);
|
||||
});
|
||||
|
||||
it('should keep same names for identifier in first function parameter and default value identifier of second function parameter', () => {
|
||||
assert.equal(functionParameterIdentifierName, functionDefaultParameterIdentifierName2);
|
||||
});
|
||||
|
||||
it('should keep same names for identifiers in function params and function body', () => {
|
||||
assert.equal(functionParameterIdentifierName, functionBodyIdentifierName1);
|
||||
assert.equal(functionDefaultParameterIdentifierName1, functionBodyIdentifierName2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('array pattern as parameter', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(__dirname + '/fixtures/array-pattern-as-parameter.js'),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
const functionParameterMatch: RegExp = /function *\(\[(_0x[a-f0-9]{4,6}), *(_0x[a-f0-9]{4,6})\]\) *\{/;
|
||||
const functionBodyMatch: RegExp = /return *(_0x[a-f0-9]{4,6}) *\+ *(_0x[a-f0-9]{4,6});/;
|
||||
|
||||
const arrayPatternIdentifierName1: string = obfuscatedCode.match(functionParameterMatch)![1];
|
||||
const arrayPatternIdentifierName2: string = obfuscatedCode.match(functionParameterMatch)![2];
|
||||
const functionBodyIdentifierName1: string = obfuscatedCode.match(functionBodyMatch)![1];
|
||||
const functionBodyIdentifierName2: string = obfuscatedCode.match(functionBodyMatch)![2];
|
||||
|
||||
it('should keep same names for identifiers in function parameter array pattern and function body', () => {
|
||||
assert.equal(arrayPatternIdentifierName1, functionBodyIdentifierName1);
|
||||
assert.equal(arrayPatternIdentifierName2, functionBodyIdentifierName2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
var test = function ([foo, bar]) {
|
||||
return foo + bar;
|
||||
}
|
||||
})();
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
var test = function (bar = 1) {
|
||||
return bar;
|
||||
}
|
||||
})();
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
(function () {
|
||||
var foo = 1;
|
||||
var test = function (bar = foo) {
|
||||
return bar;
|
||||
}
|
||||
})();
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
(function () {
|
||||
var foo = 1;
|
||||
var test = function (foo, bar = foo) {
|
||||
return foo + bar;
|
||||
}
|
||||
})();
|
||||
+30
-2
@@ -200,11 +200,39 @@ describe('VariableDeclarationTransformer', () => {
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
it('shouldn\'t transform object pattern variable declarator', () => {
|
||||
const objectPatternVariableDeclarator: RegExp = /var *\{ *bar *\} *= *\{ *'\\x62\\x61\\x72' *: *'\\x66\\x6f\\x6f' *\};/;
|
||||
const objectPatternVariableDeclaratorMatch: RegExp = /var *\{ *bar *\} *= *\{ *'\\x62\\x61\\x72' *: *'\\x66\\x6f\\x6f' *\};/;
|
||||
const variableUsageMatch: RegExp = /console\['\\x6c\\x6f\\x67'\]\(bar\);/;
|
||||
|
||||
assert.match(obfuscatedCode, objectPatternVariableDeclarator);
|
||||
assert.match(obfuscatedCode, objectPatternVariableDeclaratorMatch);
|
||||
assert.match(obfuscatedCode, variableUsageMatch);
|
||||
});
|
||||
});
|
||||
|
||||
describe('array pattern as variable declarator', () => {
|
||||
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
|
||||
readFileAsString(__dirname + '/fixtures/array-pattern.js'),
|
||||
{
|
||||
...NO_CUSTOM_NODES_PRESET
|
||||
}
|
||||
);
|
||||
const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
|
||||
|
||||
const objectPatternVariableDeclaratorMatch: RegExp = /var *\[ *(_0x([a-f0-9]){4,6}), *(_0x([a-f0-9]){4,6}) *\] *= *\[0x1, *0x2\];/;
|
||||
const variableUsageMatch: RegExp = /console\['\\x6c\\x6f\\x67'\]\((_0x([a-f0-9]){4,6}), *(_0x([a-f0-9]){4,6})\);/;
|
||||
|
||||
const objectPatternIdentifierName1: string = obfuscatedCode.match(objectPatternVariableDeclaratorMatch)![1];
|
||||
const objectPatternIdentifierName2: string = obfuscatedCode.match(objectPatternVariableDeclaratorMatch)![2];
|
||||
const identifierName1: string = obfuscatedCode.match(variableUsageMatch)![1];
|
||||
const identifierName2: string = obfuscatedCode.match(variableUsageMatch)![2];
|
||||
|
||||
it('should transform array pattern variable declarator', () => {
|
||||
assert.match(obfuscatedCode, objectPatternVariableDeclaratorMatch);
|
||||
assert.match(obfuscatedCode, variableUsageMatch);
|
||||
});
|
||||
|
||||
it('should keep same identifier names same for identifiers in variable declaration and after variable declaration', () => {
|
||||
assert.equal(objectPatternIdentifierName1, identifierName1);
|
||||
assert.equal(objectPatternIdentifierName2, identifierName2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function foo () {
|
||||
var [bar, baz] = [1, 2];
|
||||
|
||||
console.log(bar, baz);
|
||||
}
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
(function () {
|
||||
var { bar } = { bar: 'foo' };
|
||||
|
||||
console.log(bar);
|
||||
})();
|
||||
|
||||
@@ -13,6 +13,8 @@ import './unit-tests/obfuscation-result/ObfuscationResult.spec';
|
||||
import './unit-tests/options/options-normalizer/OptionsNormalizer.spec';
|
||||
import './unit-tests/source-map-corrector/SourceMapCorrector.spec';
|
||||
import './unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec';
|
||||
import './unit-tests/storages/ArrayStorage.spec';
|
||||
import './unit-tests/storages/MapStorage.spec';
|
||||
import './unit-tests/utils/crypt-utils/CryptUtils.spec';
|
||||
import './unit-tests/utils/random-generator-utils/RandomGeneratorUtils.spec';
|
||||
import './unit-tests/utils/utils/Utils.spec';
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { IStorage } from '../../../src/interfaces/storages/IStorage';
|
||||
|
||||
import { ArrayStorage } from '../../../src/storages/ArrayStorage';
|
||||
|
||||
class ConcreteStorage extends ArrayStorage <string> {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
describe('ArrayStorage', () => {
|
||||
describe('initialize (...args: any[]): void', () => {
|
||||
it('should throws an error when storage isn\'t initialized', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
assert.throws(() => storage.set(0, 'foo'), Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorage (): T[]', () => {
|
||||
it('should returns storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
|
||||
assert.instanceOf(storage.getStorage(), Array);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get (key: number): T', () => {
|
||||
it('should returns value from storage by key', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, 'foo');
|
||||
|
||||
assert.equal(storage.get(0), 'foo');
|
||||
});
|
||||
|
||||
it('should throw an error if value isn\'t exist', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
|
||||
assert.throws(() => storage.get(0), Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLength (): number', () => {
|
||||
it('should returns length of storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, 'foo');
|
||||
|
||||
assert.equal(storage.getLength(), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getKeyOf (value: T): number | null', () => {
|
||||
it('should returns key of string value', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, 'foo');
|
||||
|
||||
assert.equal(storage.getKeyOf('foo'), 0);
|
||||
});
|
||||
|
||||
it('should returns key of object if objects in `set` and `get` are two linked objects', () => {
|
||||
const storage: IStorage <Object> = new ConcreteStorage();
|
||||
const object: Object = {
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, object);
|
||||
|
||||
assert.equal(storage.getKeyOf(object), 0);
|
||||
});
|
||||
|
||||
it('should return `null` if objects in `set` and `get` are two equal objects', () => {
|
||||
const storage: IStorage <Object> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, {
|
||||
foo: 'bar'
|
||||
});
|
||||
|
||||
assert.equal(storage.getKeyOf({
|
||||
foo: 'bar'
|
||||
}), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('set (key: number, value: T): void', () => {
|
||||
it('should set value to the storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set(0, 'foo');
|
||||
|
||||
assert.equal(storage.get(0), 'foo');
|
||||
assert.equal(storage.getLength(), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeWith (storage: this, mergeId: boolean = false): void', () => {
|
||||
it('should merge two storages', () => {
|
||||
const storage1: IStorage <string> = new ConcreteStorage();
|
||||
const storage2: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage1.initialize();
|
||||
storage1.set(0, 'foo');
|
||||
|
||||
storage2.initialize();
|
||||
storage2.set(1, 'bar');
|
||||
|
||||
storage1.mergeWith(storage2, false);
|
||||
|
||||
assert.deepEqual(storage1.getStorage(), ['foo', 'bar']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { IStorage } from '../../../src/interfaces/storages/IStorage';
|
||||
|
||||
import { MapStorage } from '../../../src/storages/MapStorage';
|
||||
|
||||
class ConcreteStorage extends MapStorage <string> {
|
||||
constructor () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
describe('MapStorage', () => {
|
||||
describe('initialize (...args: any[]): void', () => {
|
||||
it('should throws an error when storage isn\'t initialized', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
assert.throws(() => storage.set('foo', 'bar'), Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorage (): Map <string | number, T>', () => {
|
||||
it('should returns storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
|
||||
assert.instanceOf(storage.getStorage(), Map);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get (key: string | number): T', () => {
|
||||
it('should returns value from storage by key', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', 'bar');
|
||||
|
||||
assert.equal(storage.get('foo'), 'bar');
|
||||
});
|
||||
|
||||
it('should throw an error if value isn\'t exist', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
|
||||
assert.throws(() => storage.get('foo'), Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLength (): number', () => {
|
||||
it('should returns length of storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', 'bar');
|
||||
|
||||
assert.equal(storage.getLength(), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getKeyOf (value: T): string | number | null', () => {
|
||||
it('should returns key of string value', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', 'bar');
|
||||
|
||||
assert.equal(storage.getKeyOf('bar'), 'foo');
|
||||
});
|
||||
|
||||
it('should returns key of object if objects in `set` and `get` are two linked objects', () => {
|
||||
const storage: IStorage <Object> = new ConcreteStorage();
|
||||
const object: Object = {
|
||||
bar: 'baz'
|
||||
};
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', object);
|
||||
|
||||
assert.equal(storage.getKeyOf(object), 'foo');
|
||||
});
|
||||
|
||||
it('should return `null` if objects in `set` and `get` are two equal objects', () => {
|
||||
const storage: IStorage <Object> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', {
|
||||
bar: 'baz'
|
||||
});
|
||||
|
||||
assert.equal(storage.getKeyOf({
|
||||
bar: 'baz'
|
||||
}), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('set (key: string | number, value: T): void', () => {
|
||||
it('should set value to the storage', () => {
|
||||
const storage: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage.initialize();
|
||||
storage.set('foo', 'bar');
|
||||
|
||||
assert.equal(storage.get('foo'), 'bar');
|
||||
assert.equal(storage.getLength(), 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeWith (storage: this, mergeId: boolean = false): void', () => {
|
||||
it('should merge two storages', () => {
|
||||
const storage1: IStorage <string> = new ConcreteStorage();
|
||||
const storage2: IStorage <string> = new ConcreteStorage();
|
||||
|
||||
storage1.initialize();
|
||||
storage1.set('foo', 'bar');
|
||||
|
||||
storage2.initialize();
|
||||
storage2.set('baz', 'quux');
|
||||
|
||||
storage1.mergeWith(storage2, false);
|
||||
|
||||
assert.deepEqual(Array.from(storage1.getStorage()), [['foo', 'bar'], ['baz', 'quux']]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -53,34 +53,6 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('mapGetFirstKeyOf(map: Map <any, any>, value: any): any', () => {
|
||||
it('should returns key of map item', () => {
|
||||
const map: Map <any, any> = new Map();
|
||||
|
||||
map.set('number1', 1);
|
||||
map.set('number2', 2);
|
||||
map.set('number3', 2);
|
||||
|
||||
map.set('string1', 'foo');
|
||||
map.set('string2', 'bar');
|
||||
|
||||
map.set('object1', {item: 'value'});
|
||||
map.set('object2', {item: 'value'});
|
||||
map.set({key: 'object'}, [1, 2, 3]);
|
||||
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, 1), 'number1');
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, 2), 'number2');
|
||||
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, 'foo'), 'string1');
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, 'bar'), 'string2');
|
||||
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, {item: 'value'}), 'object1');
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, [1, 2, 3]), {key: 'object'});
|
||||
|
||||
assert.deepEqual(Utils.mapGetFirstKeyOf(map, 3), null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringRotate (string: string, times: number): string', () => {
|
||||
let string: string;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user