added number
This commit is contained in:
69
validators/number.test.ts
Normal file
69
validators/number.test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { isNumber, isInteger } from "./number.ts";
|
||||
import { validate } from "../mod.ts";
|
||||
import {
|
||||
assertEquals,
|
||||
assertNotEquals,
|
||||
} from "https://deno.land/std@0.53.0/testing/asserts.ts";
|
||||
|
||||
Deno.test("isNumber (match)", async () => {
|
||||
const values = [
|
||||
0,
|
||||
1,
|
||||
2e64,
|
||||
-1,
|
||||
0.1,
|
||||
Math.PI,
|
||||
];
|
||||
for (const value of values) {
|
||||
assertEquals(await validate(value, isNumber), []);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("isNumber (no match)", async () => {
|
||||
const values = [
|
||||
undefined,
|
||||
null,
|
||||
NaN,
|
||||
"0",
|
||||
true,
|
||||
false,
|
||||
() => {},
|
||||
function named() {},
|
||||
new Object(),
|
||||
Symbol(),
|
||||
];
|
||||
for (const value of values) {
|
||||
assertNotEquals(await validate(value, isNumber), []);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("isInteger (match)", async () => {
|
||||
const values = [
|
||||
0,
|
||||
1,
|
||||
2e64,
|
||||
-1,
|
||||
];
|
||||
for (const value of values) {
|
||||
assertEquals(await validate(value, isInteger), []);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("isInteger (no match)", async () => {
|
||||
const values = [
|
||||
undefined,
|
||||
null,
|
||||
NaN,
|
||||
"0",
|
||||
true,
|
||||
false,
|
||||
() => {},
|
||||
function named() {},
|
||||
new Object(),
|
||||
Symbol(),
|
||||
0.1,
|
||||
];
|
||||
for (const value of values) {
|
||||
assertNotEquals(await validate(value, isInteger), []);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user