diff --git a/test/index.spec.ts b/test/index.spec.ts index fcbac9f3..ed5d423e 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -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'; diff --git a/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts b/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts new file mode 100644 index 00000000..d4a656ae --- /dev/null +++ b/test/unit-tests/cli/sanitizers/BooleanSanitizer.spec.ts @@ -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); + }); + }); + }); +}); diff --git a/test/unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec.ts b/test/unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec.ts new file mode 100644 index 00000000..8e9a66fd --- /dev/null +++ b/test/unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec.ts @@ -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); + }); + }); + }); +}); diff --git a/test/unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec.ts b/test/unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec.ts new file mode 100644 index 00000000..036c4e4f --- /dev/null +++ b/test/unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec.ts @@ -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); + }); + }); + }); +}); diff --git a/test/unit-tests/cli/cli-utils/CLIUtils.spec.ts b/test/unit-tests/cli/utils/CLIUtils.spec.ts similarity index 100% rename from test/unit-tests/cli/cli-utils/CLIUtils.spec.ts rename to test/unit-tests/cli/utils/CLIUtils.spec.ts