Added tests for CLI sanitizers

This commit is contained in:
sanex3339
2017-07-12 22:04:32 +03:00
parent 1c54dca136
commit 1996ba9e72
5 changed files with 190 additions and 1 deletions
+4 -1
View File
@@ -5,7 +5,10 @@ require('source-map-support').install();
/**
* Unit tests
*/
import './unit-tests/cli/cli-utils/CLIUtils.spec';
import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
import './unit-tests/cli/utils/CLIUtils.spec';
import './unit-tests/decorators/initializable/Initializable.spec';
import './unit-tests/node/node-appender/NodeAppender.spec';
import './unit-tests/node/node-utils/NodeUtils.spec';
@@ -0,0 +1,68 @@
import { assert } from 'chai';
import { BooleanSanitizer } from '../../../../src/cli/sanitizers/BooleanSanitizer';
describe('BooleanSanitizer', () => {
describe('BooleanSanitizer: TCLISanitizer = (value: string): boolean', () => {
describe('variant #1: input value `true`', () => {
const inputValue: string = 'true';
const expectedValue: boolean = true;
let value: boolean;
before(() => {
value = BooleanSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #2: input value `1`', () => {
const inputValue: string = '1';
const expectedValue: boolean = true;
let value: boolean;
before(() => {
value = BooleanSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #3: input value `false`', () => {
const inputValue: string = 'false';
const expectedValue: boolean = false;
let value: boolean;
before(() => {
value = BooleanSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #4: input value `foo`', () => {
const inputValue: string = 'foo';
const expectedValue: boolean = false;
let value: boolean;
before(() => {
value = BooleanSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
});
});
@@ -0,0 +1,36 @@
import { assert } from 'chai';
import { SourceMapModeSanitizer } from '../../../../src/cli/sanitizers/SourceMapModeSanitizer';
describe('SourceMapModeSanitizer', () => {
describe('SourceMapModeSanitizer: TCLISanitizer = (value: string): string', () => {
describe('variant #1: valid source map mode', () => {
const inputValue: string = 'inline';
const expectedValue: string = inputValue;
let value: string;
before(() => {
value = SourceMapModeSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #2: invalid source map mode', () => {
const inputValue: string = 'foo';
let testFunc: () => void;
before(() => {
testFunc = () => SourceMapModeSanitizer(inputValue);
});
it('should throw error', () => {
assert.throw(testFunc, ReferenceError);
});
});
});
});
@@ -0,0 +1,82 @@
import { assert } from 'chai';
import { StringArrayEncodingSanitizer } from '../../../../src/cli/sanitizers/StringArrayEncodingSanitizer';
describe('StringArrayEncodingSanitizer', () => {
describe('StringArrayEncodingSanitizer: TCLISanitizer = (value: string): TStringArrayEncoding', () => {
describe('variant #1: string array encoding `base64`', () => {
const inputValue: string = 'base64';
const expectedValue: boolean = true;
let value: boolean;
before(() => {
value = StringArrayEncodingSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #2: string array encoding `true`', () => {
const inputValue: string = 'true';
const expectedValue: boolean = true;
let value: boolean;
before(() => {
value = StringArrayEncodingSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #3: string array encoding `1`', () => {
const inputValue: string = '1';
const expectedValue: boolean = true;
let value: boolean;
before(() => {
value = StringArrayEncodingSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #4: string array encoding `rc4`', () => {
const inputValue: string = 'rc4';
const expectedValue: string = 'rc4';
let value: string;
before(() => {
value = StringArrayEncodingSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
describe('variant #5: string array encoding `foo`', () => {
const inputValue: string = 'foo';
const expectedValue: boolean = false;
let value: boolean;
before(() => {
value = StringArrayEncodingSanitizer(inputValue);
});
it('should sanitize value', () => {
assert.equal(value, expectedValue);
});
});
});
});