Refactoring related to ArrayUtils, NodeMetadata and StringArray transformets

This commit is contained in:
sanex
2021-08-08 23:56:45 +03:00
parent a7e0f5885a
commit 061bffe2c4
13 changed files with 137 additions and 54 deletions
@@ -11,7 +11,7 @@ describe('NodeMetadata', () => {
describe('set', () => {
const expectedMetadata: ESTree.LiteralNodeMetadata = {
ignoredNode: true,
replacedLiteral: true
stringArrayCallLiteralNode: true
};
let node: ESTree.Literal;
@@ -20,7 +20,7 @@ describe('NodeMetadata', () => {
node = NodeFactory.literalNode('foo');
NodeMetadata.set(node, {
ignoredNode: true,
replacedLiteral: true
stringArrayCallLiteralNode: true
})
});
@@ -38,8 +38,11 @@ describe('NodeMetadata', () => {
before(() => {
node = NodeFactory.literalNode('foo');
node.metadata = {};
node.metadata.replacedLiteral = true;
value = NodeMetadata.get<ESTree.LiteralNodeMetadata, 'replacedLiteral'>(node, 'replacedLiteral');
node.metadata.stringArrayCallLiteralNode = true;
value = NodeMetadata.get<
ESTree.LiteralNodeMetadata,
'stringArrayCallLiteralNode'
>(node, 'stringArrayCallLiteralNode');
});
it('should get metadata value of the node', () => {
@@ -83,7 +86,7 @@ describe('NodeMetadata', () => {
});
});
describe('isReplacedLiteral', () => {
describe('isStringArrayCallLiteralNode', () => {
const expectedValue: boolean = true;
let node: ESTree.Literal,
@@ -92,8 +95,8 @@ describe('NodeMetadata', () => {
before(() => {
node = NodeFactory.literalNode('foo');
node.metadata = {};
node.metadata.replacedLiteral = true;
value = NodeMetadata.isReplacedLiteral(node);
node.metadata.stringArrayCallLiteralNode = true;
value = NodeMetadata.isStringArrayCallLiteralNode(node);
});
it('should return metadata value', () => {
+62
View File
@@ -215,6 +215,68 @@ describe('ArrayUtils', () => {
});
});
describe('getLastElementByIndex', () => {
describe('empty array', () => {
const array: string[] = [];
const expectedLastElement: undefined = undefined;
let lastElement: string | undefined;
before(() => {
lastElement = arrayUtils.getLastElementByIndex(array, 1);
});
it('should return undefined if array is empty', () => {
assert.equal(lastElement, expectedLastElement);
});
});
describe('array length: `1` and index is out of array boundary', () => {
const array: string[] = ['foo'];
const expectedLastElement: undefined = undefined;
let lastElement: string | undefined;
before(() => {
lastElement = arrayUtils.getLastElementByIndex(array, 2);
});
it('should return undefined', () => {
assert.equal(lastElement, expectedLastElement);
});
});
describe('array length: `3` and index is `0`', () => {
const array: string[] = ['foo', 'bar', 'baz'];
const expectedLastElement: string = 'baz';
let lastElement: string | undefined;
before(() => {
lastElement = arrayUtils.getLastElementByIndex(array, 0);
});
it('should return element with a correct index', () => {
assert.equal(lastElement, expectedLastElement);
});
});
describe('array length: `3` and index is `1`', () => {
const array: string[] = ['foo', 'bar', 'baz'];
const expectedLastElement: string = 'bar';
let lastElement: string | undefined;
before(() => {
lastElement = arrayUtils.getLastElementByIndex(array, 1);
});
it('should return element with a correct index', () => {
assert.equal(lastElement, expectedLastElement);
});
});
});
describe('rotate', () => {
let array: number[],
rotatedArray: number[];