|
@@ -13,8 +13,9 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
|
describe('generateWithPrefix', () => {
|
|
|
describe('Variant #1: should not generate same name for string array as existing name in code', () => {
|
|
|
describe('Variant #1: `renameGlobals` option is disabled', () => {
|
|
|
- const stringArrayStorageRegExp: RegExp = /const a[aB] *= *\['abc'];/;
|
|
|
- const variableDeclarationIdentifierNameRegExp: RegExp = /const ab *= *a[abAB]\(0x0\);/;
|
|
|
+ const stringArrayStorageRegExp: RegExp = /const a[cABC] *= *\['_aa', *'_ab'];/;
|
|
|
+ const variableDeclarationIdentifierNameRegExp1: RegExp = /const aa *= *a[cABC]\(0x0\);/;
|
|
|
+ const variableDeclarationIdentifierNameRegExp2: RegExp = /const ab *= *a[cABC]\(0x1\);/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
@@ -26,7 +27,7 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
|
{
|
|
|
...NO_ADDITIONAL_NODES_PRESET,
|
|
|
identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
|
|
|
- identifiersDictionary: ['a', 'b'],
|
|
|
+ identifiersDictionary: ['a', 'b', 'c'],
|
|
|
identifiersPrefix: 'a',
|
|
|
transformObjectKeys: true,
|
|
|
stringArray: true,
|
|
@@ -39,14 +40,19 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
|
assert.match(obfuscatedCode, stringArrayStorageRegExp);
|
|
|
});
|
|
|
|
|
|
- it('Match #2: should keep identifier name for last variable declaration', () => {
|
|
|
- assert.match(obfuscatedCode, variableDeclarationIdentifierNameRegExp);
|
|
|
+ it('Match #2: should keep identifier name for existing variable declaration', () => {
|
|
|
+ assert.match(obfuscatedCode, variableDeclarationIdentifierNameRegExp1);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Match #3: should keep identifier name for existing variable declaration', () => {
|
|
|
+ assert.match(obfuscatedCode, variableDeclarationIdentifierNameRegExp2);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('Variant #2: `renameGlobals` option is enabled', () => {
|
|
|
- const stringArrayStorageRegExp: RegExp = /const a[aB] *= *\['abc'];/;
|
|
|
- const lastVariableDeclarationIdentifierNameRegExp: RegExp = /const a[AB] *= *a[AB]\(0x0\);/;
|
|
|
+ const stringArrayStorageRegExp: RegExp = /const a[cABC] *= *\['_aa', *'_ab'];/;
|
|
|
+ const lastVariableDeclarationIdentifierNameRegExp1: RegExp = /const a[cABC] *= *a[cABC]\(0x0\);/;
|
|
|
+ const lastVariableDeclarationIdentifierNameRegExp2: RegExp = /const a[cABC] *= *a[cABC]\(0x1\);/;
|
|
|
|
|
|
let obfuscatedCode: string;
|
|
|
|
|
@@ -58,7 +64,7 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
|
{
|
|
|
...NO_ADDITIONAL_NODES_PRESET,
|
|
|
identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
|
|
|
- identifiersDictionary: ['a', 'b'],
|
|
|
+ identifiersDictionary: ['a', 'b', 'c'],
|
|
|
identifiersPrefix: 'a',
|
|
|
renameGlobals: true,
|
|
|
transformObjectKeys: true,
|
|
@@ -72,8 +78,12 @@ describe('DictionaryIdentifierNamesGenerator', () => {
|
|
|
assert.match(obfuscatedCode, stringArrayStorageRegExp);
|
|
|
});
|
|
|
|
|
|
- it('Match #2: should keep identifier name for last variable declaration', () => {
|
|
|
- assert.match(obfuscatedCode, lastVariableDeclarationIdentifierNameRegExp);
|
|
|
+ it('Match #2: should keep identifier name for existing variable declaration', () => {
|
|
|
+ assert.match(obfuscatedCode, lastVariableDeclarationIdentifierNameRegExp1);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('Match #3: should keep identifier name for existing variable declaration', () => {
|
|
|
+ assert.match(obfuscatedCode, lastVariableDeclarationIdentifierNameRegExp2);
|
|
|
});
|
|
|
});
|
|
|
});
|