Changed to constructor functions

This commit is contained in:
Sebastian Seedorf
2020-05-26 19:40:41 +02:00
parent 9fa06685ba
commit 836b1449bf
15 changed files with 281 additions and 168 deletions

View File

@@ -14,15 +14,42 @@ import {
Deno.test("validate schema (match)", async () => {
const values: [any, Validatable][] = [
["string", isString],
["string", [isString]],
[["arr", "ay"], { [ArraySymbol]: isString }],
[{ foo: 3.1415, lorem: "ipsum" }, { foo: isNumber, lorem: [isString] }],
[{}, { optional: [isString] }],
[{ foo: { bar: "" } }, { foo: { bar: [isRequired, isString] } }],
[{ foo: { bar: "" } }, { foo: { bar: [isString] } }],
[{ foo: {} }, { foo: { bar: [isString] } }],
[{}, { foo: { bar: [isString] } }],
[
"string",
isString(),
],
[
"string",
[isString()],
],
[
["arr", "ay"],
{ [ArraySymbol]: isString() },
],
[
{ foo: 3.1415, lorem: "ipsum" },
{ foo: isNumber(), lorem: [isString()] },
],
[
{},
{ optional: [isString()] },
],
[
{ foo: { bar: "" } },
{ foo: { bar: [isRequired(), isString()] } },
],
[
{ foo: { bar: "" } },
{ foo: { bar: [isString()] } },
],
[
{ foo: {} },
{ foo: { bar: [isString()] } },
],
[
{},
{ foo: { bar: [isString()] } },
],
];
for (const [value, constraints] of values) {
assertEquals([], await validate(value, constraints));
@@ -31,14 +58,38 @@ Deno.test("validate schema (match)", async () => {
Deno.test("validate schema (no match)", async () => {
const values: [any, Validatable][] = [
[6, isString],
[false, [isString]],
[["arr", ["ay"]], { [ArraySymbol]: isString }],
[{ foo: 3.1415, lorem: "ipsum" }, { foo: isInteger, lorem: [isString] }],
[{}, { required: [isRequired, isString] }],
[{ foo: { bar: 1 } }, { foo: { bar: [isRequired, isString] } }],
[{ foo: {} }, { foo: { bar: [isRequired, isString] } }],
[{}, { foo: { bar: [isRequired, isString] } }],
[
6,
isString(),
],
[
false,
[isString()],
],
[
["arr", ["ay"]],
{ [ArraySymbol]: isString() },
],
[
{ foo: 3.1415, lorem: "ipsum" },
{ foo: isInteger(), lorem: [isString()] },
],
[
{},
{ required: [isRequired(), isString()] },
],
[
{ foo: { bar: 1 } },
{ foo: { bar: [isRequired(), isString()] } },
],
[
{ foo: {} },
{ foo: { bar: [isRequired(), isString()] } },
],
[
{},
{ foo: { bar: [isRequired(), isString()] } },
],
];
for (const [value, constraints] of values) {
assertNotEquals([], await validate(value, constraints));