more validators

This commit is contained in:
Sebastian Seedorf
2020-05-26 16:52:26 +02:00
parent 7367af7fe4
commit 9fa06685ba
13 changed files with 340 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ import {
isString,
isNumber,
isInteger,
isRequired,
} from "./mod.ts";
Deno.test("validate schema (match)", async () => {
@@ -17,6 +18,11 @@ Deno.test("validate schema (match)", async () => {
["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));
@@ -29,6 +35,10 @@ Deno.test("validate schema (no match)", async () => {
[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));