-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_test.ts
More file actions
101 lines (89 loc) · 2.1 KB
/
mod_test.ts
File metadata and controls
101 lines (89 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import name from "./mod.ts";
Deno.test({
name: "it is exported as a function",
fn(): void {
assertEquals(typeof name, "function");
},
});
Deno.test({
name: "can extract the name from a function declaration",
fn(): void {
function foobar() {}
assertEquals(name(foobar), "foobar");
},
});
Deno.test({
name: "can extract the name from a function expression",
fn(): void {
const a = function bar() {};
assertEquals(name(a), "bar");
},
});
Deno.test({
name: "can be overriden using displayName",
fn(): void {
const a = function bar() {};
(a as any).displayName = "bro";
assertEquals(name(a), "bro");
},
});
Deno.test({
name: "works with constructed instances",
fn(): void {
interface Bar {}
function Bar() {}
const foo: Bar = new (<any> Bar)();
assertEquals(name(foo as Function), "Bar");
},
});
Deno.test({
name: "works with anonymous",
fn(): void {
assertEquals(name(function () {}), "anonymous");
},
});
Deno.test({
name: "returns the className if we were not given a function",
fn(): void {
assertEquals(name(("string" as unknown) as StringConstructor), "String");
},
});
//
// Test if the env supports async functions, if so add a test to ensure
// that we will work with async functions.
//
let asyncfn = true;
try {
new Function("return async function hello() {}")();
} catch (e) {
asyncfn = false;
}
if (asyncfn) {
Deno.test({
name: "detects the name of async functions",
fn(): void {
const fn = new Function("return async function hello() {}")();
assertEquals(name(fn), "hello");
},
});
}
//
// Test that this env supports generators, if so add a test to ensure that
// we will work with generators.
//
let generators = true;
try {
new Function("return function* generator() {}")();
} catch (e) {
generators = false;
}
if (generators) {
Deno.test({
name: "detecs the name of a generator",
fn(): void {
const fn = new Function("return function* hello() {}")();
assertEquals(name(fn), "hello");
},
});
}