40 lines
1 KiB
TypeScript
40 lines
1 KiB
TypeScript
import {
|
|
assertEquals,
|
|
assertThrows,
|
|
} from "https://deno.land/std/testing/asserts.ts";
|
|
import { isinstance, nn, nnu, nu } from "./typing.ts";
|
|
|
|
Deno.test("isinstance", () => {
|
|
class A {}
|
|
class A1 extends A {}
|
|
class A2 extends A {}
|
|
class B {}
|
|
|
|
const f: any[] = [5, null, undefined, new A(), new A1(), new B(), new A2()];
|
|
const result = f.filter(isinstance(A));
|
|
assertEquals(result, [f[3], f[4], f[6]]);
|
|
});
|
|
|
|
Deno.test("nn", () => {
|
|
assertEquals(nn(undefined), undefined);
|
|
assertEquals(nn(0), 0);
|
|
assertEquals(nn(""), "");
|
|
assertEquals(nn([]), []);
|
|
assertThrows(() => nn(null), Error, "null value");
|
|
});
|
|
|
|
Deno.test("nu", () => {
|
|
assertEquals(nu(null), null);
|
|
assertEquals(nu(0), 0);
|
|
assertEquals(nu(""), "");
|
|
assertEquals(nu([]), []);
|
|
assertThrows(() => nu(undefined), Error, "undefined value");
|
|
});
|
|
|
|
Deno.test("nnu", () => {
|
|
assertEquals(nnu(0), 0);
|
|
assertEquals(nnu(""), "");
|
|
assertEquals(nnu([]), []);
|
|
assertThrows(() => nnu(undefined), Error, "undefined value");
|
|
assertThrows(() => nnu(null), Error, "null value");
|
|
});
|