-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.test.ts
78 lines (72 loc) · 1.82 KB
/
mod.test.ts
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
import { assertEquals, assertMatch } from '@std/assert';
import * as mod from './mod.ts';
const defaultClassProperties = new Set(Object.getOwnPropertyNames(class {}));
Deno.test('class Symbol.toStringTag', () => {
for (const [k, v] of Object.entries(mod)) {
if (
typeof v !== 'function' ||
Object.getOwnPropertyDescriptor(v, 'prototype')?.writable
) {
continue;
}
const desc = Object.getOwnPropertyDescriptor(
v.prototype,
Symbol.toStringTag,
);
assertEquals(desc?.value, k, k);
}
});
Deno.test('class constants', () => {
for (const [k, v] of Object.entries(mod)) {
if (
typeof v !== 'function' ||
Object.getOwnPropertyDescriptor(v, 'prototype')?.writable
) {
continue;
}
for (const p of Object.getOwnPropertyNames(v)) {
if (defaultClassProperties.has(p)) {
continue;
}
const desc = Object.getOwnPropertyDescriptor(v, p)!;
assertMatch(p, /^[A-Z][A-Z0-9_]*$/, `${k}.${p}`);
assertEquals(desc.writable ?? false, false, `${k}.${p}`);
assertEquals(desc.enumerable ?? false, false, `${k}.${p}`);
assertEquals(
desc.configurable ?? false,
!('value' in desc),
`${k}.${p}`,
);
}
}
});
Deno.test('class names', () => {
for (const [k, v] of Object.entries(mod)) {
if (
typeof v !== 'function' ||
Object.getOwnPropertyDescriptor(v, 'prototype')?.writable
) {
continue;
}
assertMatch(k, /^[A-Z][a-zA-Z0-9_]*$/, k);
}
});
Deno.test('function names', () => {
for (const [k, v] of Object.entries(mod)) {
if (
typeof v !== 'function' ||
!Object.getOwnPropertyDescriptor(v, 'prototype')?.writable
) {
continue;
}
assertMatch(k, /^[a-z][a-zA-Z0-9_]*$/, k);
}
});
Deno.test('variable names', () => {
for (const [k, v] of Object.entries(mod)) {
if (typeof v === 'function') {
continue;
}
assertMatch(k, /^[A-Z][A-Z0-9_]*$/, k);
}
});