This commit is contained in:
Sebastian Seedorf
2020-05-26 00:20:44 +02:00
parent cd6ed23d47
commit 218e596ede
5 changed files with 72 additions and 39 deletions

View File

@@ -1,15 +1,20 @@
import { assertEquals, assertNotEquals } from "https://deno.land/std@0.53.0/testing/asserts.ts";
import {
validate, Validatable, ArraySymbol,
isString
assertEquals,
assertNotEquals,
} from "https://deno.land/std@0.53.0/testing/asserts.ts";
import {
validate,
Validatable,
ArraySymbol,
isString,
} from "./mod.ts";
Deno.test("validate schema (match)", async () => {
const values: [any, Validatable][] = [
["string", isString],
["string", [isString]],
[["arr", "ay"], {[ArraySymbol]: isString}],
[{foo: "bar", lorem: "ipsum"}, {foo: isString, lorem: [isString]}],
[["arr", "ay"], { [ArraySymbol]: isString }],
[{ foo: "bar", lorem: "ipsum" }, { foo: isString, lorem: [isString] }],
];
for (const [value, constraints] of values) {
assertEquals([], await validate(value, constraints));
@@ -20,10 +25,10 @@ Deno.test("validate schema (no match)", async () => {
const values: [any, Validatable][] = [
[6, isString],
[false, [isString]],
[["arr", ["ay"]], {[ArraySymbol]: isString}],
[{foo: {}, lorem: "ipsum"}, {foo: isString, lorem: [isString]}],
[["arr", ["ay"]], { [ArraySymbol]: isString }],
[{ foo: {}, lorem: "ipsum" }, { foo: isString, lorem: [isString] }],
];
for (const [value, constraints] of values) {
assertNotEquals([], await validate(value, constraints));
}
});
});