refactoring
This commit is contained in:
24
test/.eslintrc.js
Normal file
24
test/.eslintrc.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||
* This file is part of console-app which is released under MIT.
|
||||
* See file 'LICENSE' for full license details.
|
||||
* Created by Timo Hocker <timo@sapphirecode.ovh>, May 2020
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'@sapphirecode/eslint-config-ts'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018
|
||||
}
|
||||
}
|
39
test/PathType.ts
Normal file
39
test/PathType.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import test from 'ava';
|
||||
import { PathType } from '../lib/Types/PathType';
|
||||
|
||||
test ('no file', async (t) => {
|
||||
const validator = new PathType ('file');
|
||||
await t.throwsAsync (
|
||||
() => validator.to_type ('test'),
|
||||
{ message: 'cannot assign folder to file' }
|
||||
);
|
||||
});
|
||||
test ('file', async (t) => {
|
||||
const validator = new PathType ('file');
|
||||
const res = await validator.to_type ('package.json');
|
||||
t.is (res, 'package.json');
|
||||
});
|
||||
test ('no folder', async (t) => {
|
||||
const validator = new PathType ('folder');
|
||||
await t.throwsAsync (
|
||||
() => validator.to_type ('package.json'),
|
||||
{ message: 'cannot assign folder to file' }
|
||||
);
|
||||
});
|
||||
test ('folder', async (t) => {
|
||||
const validator = new PathType ('folder');
|
||||
const res = await validator.to_type ('test');
|
||||
t.is (res, 'test');
|
||||
});
|
||||
test ('no path', async (t) => {
|
||||
const validator = new PathType ('path');
|
||||
await t.throwsAsync (
|
||||
() => validator.to_type ('doesnotexist.file'),
|
||||
{ message: 'path does not exist' }
|
||||
);
|
||||
});
|
||||
test ('path', async (t) => {
|
||||
const validator = new PathType ('path');
|
||||
const res = await validator.to_type ('test');
|
||||
t.is (res, 'test');
|
||||
});
|
41
test/TypeValidation.ts
Normal file
41
test/TypeValidation.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import test from 'ava';
|
||||
import { TypeValidation } from '../lib/Types/TypeValidation';
|
||||
|
||||
test ('string', async (t) => {
|
||||
const validator = new TypeValidation ('string');
|
||||
const res = await validator.to_type ('foo');
|
||||
t.is (res, 'foo');
|
||||
});
|
||||
test ('no number', (t) => {
|
||||
const validator = new TypeValidation ('number');
|
||||
t.throws (
|
||||
() => validator.to_type ('foo'),
|
||||
{ message: 'value is not a number' }
|
||||
);
|
||||
});
|
||||
test ('number', async (t) => {
|
||||
const validator = new TypeValidation ('number');
|
||||
const res = await validator.to_type ('123');
|
||||
t.is (res, 123);
|
||||
});
|
||||
test ('no boolean', (t) => {
|
||||
const validator = new TypeValidation ('boolean');
|
||||
t.throws (
|
||||
() => validator.to_type ('foo'),
|
||||
{ message: 'value is not a boolean' }
|
||||
);
|
||||
});
|
||||
test ('boolean', async (t) => {
|
||||
const validator = new TypeValidation ('boolean');
|
||||
const r1 = await validator.to_type ('false');
|
||||
const r2 = await validator.to_type ('true');
|
||||
t.is (r1, false);
|
||||
t.is (r2, true);
|
||||
});
|
||||
test ('boolean number', async (t) => {
|
||||
const validator = new TypeValidation ('boolean');
|
||||
const r1 = await validator.to_type (0);
|
||||
const r2 = await validator.to_type (1);
|
||||
t.is (r1, false);
|
||||
t.is (r2, true);
|
||||
});
|
Reference in New Issue
Block a user