Skip to content

Commit

Permalink
Fixed M/C
Browse files Browse the repository at this point in the history
  • Loading branch information
songyuew committed Feb 6, 2023
1 parent a48637c commit b76305e
Show file tree
Hide file tree
Showing 9 changed files with 787 additions and 233 deletions.
139 changes: 80 additions & 59 deletions README.md

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions test/testFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import assert from 'assert';
import { format } from 'util';
import validator from '../src/index';

export default function test(options) {
const args = options.args || [];

args.unshift(null);

if (options.error) {
options.error.forEach((error) => {
args[0] = error;

try {
assert.throws(() => validator[options.validator](...args));
} catch (err) {
const warning = format(
'validator.%s(%s) passed but should error',
options.validator, args.join(', ')
);

throw new Error(warning);
}
});
}

if (options.valid) {
options.valid.forEach((valid) => {
args[0] = valid;

if (validator[options.validator](...args) !== true) {
const warning = format(
'validator.%s(%s) failed but should have passed',
options.validator, args.join(', ')
);

throw new Error(warning);
}
});
}

if (options.invalid) {
options.invalid.forEach((invalid) => {
args[0] = invalid;

if (validator[options.validator](...args) !== false) {
const warning = format(
'validator.%s(%s) passed but should have failed',
options.validator, args.join(', ')
);

throw new Error(warning);
}
});
}
}
File renamed without changes.
Loading

0 comments on commit b76305e

Please sign in to comment.