refactor extra code, duplicates, complexity

- refactor array equality check and add tests
- remove OperatingSystem.Unknown causing extra logic, return undefined instead
- refactor enum validation to share same logic
- refactor scripting language factories to share same logic
- refactor too many args in runCodeAsync
- refactor ScriptCode constructor to reduce complexity
- fix writing useless write to member object since another property write always override it
This commit is contained in:
undergroundwires
2021-04-11 14:37:02 +01:00
parent 3e9c99f5f8
commit 00d8e551db
37 changed files with 512 additions and 233 deletions

View File

@@ -1,6 +1,8 @@
import 'mocha';
import { expect } from 'chai';
import { getEnumNames, getEnumValues, createEnumParser } from '@/application/Common/Enum';
import { getEnumNames, getEnumValues, createEnumParser, assertInRange } from '@/application/Common/Enum';
import { EnumRangeTestRunner } from './EnumRangeTestRunner';
import { scrambledEqual } from '@/application/Common/Array';
describe('Enum', () => {
describe('createEnumParser', () => {
@@ -78,7 +80,7 @@ describe('Enum', () => {
// act
const actual = getEnumNames(TestEnum);
// assert
expect(expected.sort()).to.deep.equal(actual.sort());
expect(scrambledEqual(expected, actual));
});
});
describe('getEnumValues', () => {
@@ -89,7 +91,19 @@ describe('Enum', () => {
// act
const actual = getEnumValues(TestEnum);
// assert
expect(expected.sort()).to.deep.equal(actual.sort());
expect(scrambledEqual(expected, actual));
});
});
describe('assertInRange', () => {
// arrange
enum TestEnum { Red, Green, Blue }
const validValue = TestEnum.Red;
// act
const act = (value: TestEnum) => assertInRange(value, TestEnum);
// assert
new EnumRangeTestRunner(act)
.testOutOfRangeThrows()
.testUndefinedValueThrows()
.testValidValueDoesNotThrow(validValue);
});
});