-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime.js
More file actions
153 lines (153 loc) · 10.7 KB
/
Copy pathtest_runtime.js
File metadata and controls
153 lines (153 loc) · 10.7 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import {createTypeFromMapping} from './src-runtime/createTypeFromMapping.js';
import {expandType } from './src-transpiler/expandType.js';
import {validateType } from './src-runtime/validateType.js';
import {validateUnion } from './src-runtime/validateUnion.js';
import {validateTuple } from './src-runtime/validateTuple.js';
import {typedefs, typedefTemplates} from './src-runtime/registerTypedef.js';
// inspectType.js uses addEventListener/postMessage on import, bootstrapping them
// here allows running inspectIndexedAccess in the Node.js test environment.
globalThis.self = globalThis;
globalThis.postMessage = () => {};
globalThis.addEventListener = () => {};
/**
* @param {Object<string, any>} obj - The object to clear.
*/
function clearObject(obj) {
Object.keys(obj).forEach(_ => delete obj[_]);
}
const warn = () => undefined;
// We expect all functions to return true.
const tests = [
() => validateType({}, {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
// There is no type distinction between a "normal" and "prototype-less" object
() => validateType(Object.create(null), {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
// Every function is also an object
() => validateType(Math.sqrt, {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
() => validateType(new Date(), {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
// `{}` accepts every non-nullish value like TS (`1 extends {}`).
() => validateType(1, {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
() => validateType('nope', {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
() => validateType(Symbol('nope'), {type: 'object', optional: false}, 'loc', 'name', true, warn, 0),
() => validateUnion(1, {type: 'union', optional: false, members: [1, 2, 3 ]}, 'loc', 'name', true, warn, 0),
() => validateUnion(true, {type: 'union', optional: false, members: [false, true, 'null' ]}, 'loc', 'name', true, warn, 0),
() => validateUnion({}, {type: 'union', optional: false, members: ['object', 123 ]}, 'loc', 'name', true, warn, 0),
() => validateUnion([], {type: 'union', optional: false, members: ['array', 123 ]}, 'loc', 'name', true, warn, 0),
() => validateUnion(true, {type: 'union', optional: false, members: [false, 'null' ]}, 'loc', 'name', true, warn, 0) === false,
() => validateUnion(5, {type: 'union', optional: false, members: [1, 2, 3 ]}, 'loc', 'name', true, warn, 0) === false,
() => validateUnion('"str"', {type: 'union', optional: false, members: ['"foo"', '"bar"', '"baz"']}, 'loc', 'name', true, warn, 0) === false,
() => validateTuple([1, 1, 1], expandType('[1, 1, 1]' ), 'loc', 'name', true, warn, 0),
() => validateTuple([1, 1, 1], expandType('[1, 1]' ), 'loc', 'name', true, warn, 0) === false,
() => validateTuple([1, 1, 1], expandType('[1, 1, 1, 1]'), 'loc', 'name', true, warn, 0) === false,
() => {
const str = '{[Key in 1|2|3]: {testkey: [Key, Key, Key], bla: Key}}';
const mapping = expandType(str);
const type = createTypeFromMapping(mapping, warn);
const keys = Object.values(type.properties).map(_ => _.properties.bla);
const ret = keys[0] === 1 && keys[1] === 2 && keys[2] === 3;
return ret;
},
...(await import('./src-runtime/jsx.spec.js' )).tests,
...(await import('./src-runtime/base64.spec.js' )).tests,
...(await import('./src-runtime/createType.spec.js' )).tests,
...(await import('./src-runtime/createTypeFromKeyof.spec.js')).tests,
...(await import('./src-runtime/resolveType.spec.js' )).tests,
...(await import('./src-runtime/validateTemplateLiteral.spec.js')).tests,
...(await import('./src-runtime/validateReference.spec.js' )).tests,
...(await import('./src-runtime/componentMap.spec.js' )).tests,
...(await import('./src-runtime/componentOptions.spec.js' )).tests,
...(await import('./src-runtime/componentTowerStress.spec.js' )).tests,
...(await import('./src-runtime/templateNarrowing.spec.js' )).tests,
...(await import('./src-runtime/templateMemo.spec.js' )).tests,
...(await import('./src-runtime/substituteTypeof.spec.js' )).tests,
...(await import('./src-runtime/substitutes.spec.js' )).tests,
...(await import('./src-runtime/substituteArray.spec.js' )).tests,
...(await import('./src-runtime/substituteAtom.spec.js' )).tests,
...(await import('./src-runtime/substituteCondition.spec.js' )).tests,
...(await import('./src-runtime/substituteDescriptors.spec.js' )).tests,
...(await import('./src-runtime/substituteNew.spec.js' )).tests,
...(await import('./src-runtime/substituteFunction.spec.js' )).tests,
...(await import('./src-runtime/substituteIndexSignature.spec.js')).tests,
...(await import('./src-runtime/substituteIndexedAccess.spec.js')).tests,
...(await import('./src-runtime/substituteIntersection.spec.js' )).tests,
...(await import('./src-runtime/substituteKeyof.spec.js' )).tests,
...(await import('./src-runtime/substituteList.spec.js' )).tests,
...(await import('./src-runtime/substituteMapping.spec.js' )).tests,
...(await import('./src-runtime/substituteObject.spec.js' )).tests,
...(await import('./src-runtime/substitutePromise.spec.js' )).tests,
...(await import('./src-runtime/substituteSet.spec.js' )).tests,
...(await import('./src-runtime/substituteClass.spec.js' )).tests,
...(await import('./src-runtime/substituteRecord.spec.js' )).tests,
...(await import('./src-runtime/substituteRecordNode.spec.js' )).tests,
...(await import('./src-runtime/substituteMapNode.spec.js' )).tests,
...(await import('./src-runtime/substituteReference.spec.js' )).tests,
...(await import('./src-runtime/substituteRest.spec.js' )).tests,
...(await import('./src-runtime/substituteTemplateLiteral.spec.js')).tests,
...(await import('./src-runtime/substituteTuple.spec.js' )).tests,
...(await import('./src-runtime/substituteTupleMember.spec.js' )).tests,
...(await import('./src-runtime/substituteUnion.spec.js' )).tests,
...(await import('./src-runtime/templateCandidates.spec.js' )).tests,
...(await import('./src-runtime/firstBadIndex.spec.js' )).tests,
...(await import('./src-runtime/mappedOptionality.spec.js' )).tests,
...(await import('./src-runtime/tagSnapshot.spec.js' )).tests,
...(await import('./src-runtime/collectCandidates.spec.js' )).tests,
...(await import('./src-runtime/strictNullChecks.spec.js' )).tests,
...(await import('./src-runtime/stringifyValue.spec.js' )).tests,
...(await import('./src-runtime/validators.spec.js' )).tests,
...(await import('./src-runtime/validateCondition.spec.js' )).tests,
...(await import('./src-runtime/validateTypeof.spec.js' )).tests,
...(await import('./src-runtime/validateNamedType.spec.js' )).tests,
...(await import('./src-runtime/validateArguments.spec.js' )).tests,
...(await import('./src-runtime/validateMap.spec.js' )).tests,
...(await import('./src-runtime/validateArray.spec.js' )).tests,
...(await import('./src-runtime/validateObject.spec.js' )).tests,
...(await import('./src-runtime/ignoreChecks.spec.js' )).tests,
...(await import('./src-runtime/customChecks.spec.js' )).tests,
...(await import('./src-runtime/reportedKeys.spec.js' )).tests,
...(await import('./src-runtime/tagValue.spec.js' )).tests,
...(await import('./src-runtime/captureStack.spec.js' )).tests,
...(await import('./src-runtime/validateArrayLikeSparse.spec.js' )).tests,
...(await import('./src-runtime/validateRecord.spec.js' )).tests,
...(await import('./src-runtime/validatePromise.spec.js' )).tests,
...(await import('./src-runtime/validateNumber.spec.js' )).tests,
...(await import('./src-runtime/checkInfinity.spec.js' )).tests,
...(await import('./src-runtime/exactObjects.spec.js' )).tests,
...(await import('./src-runtime/version.spec.js' )).tests,
...(await import('./src-runtime/projectVersion.spec.js' )).tests,
...(await import('./src-runtime/valueStrings.spec.js' )).tests,
...(await import('./src-runtime/mapDisplay.spec.js' )).tests,
...(await import('./src-runtime/displayAnything.spec.js' )).tests,
...(await import('./src-runtime/typeDisplay.spec.js' )).tests,
...(await import('./src-runtime/humanizeExpect.spec.js' )).tests,
...(await import('./src-runtime/explainMismatch.spec.js' )).tests,
...(await import('./src-runtime/typeTree.spec.js' )).tests,
...(await import('./src-runtime/panelRefresh.spec.js' )).tests,
...(await import('./src-runtime/panelWindows.spec.js' )).tests,
...(await import('./src-runtime/customValidations.spec.js' )).tests,
...(await import('./src-transpiler/ignoreRti.spec.js' )).tests,
...(await import('./src-transpiler/headerImports.spec.js' )).tests,
...(await import('./src-transpiler/expandTypeParity.spec.js' )).tests,
...(await import('./src-transpiler/projectVersionHeader.spec.js')).tests,
...(await import('./src-transpiler/inferTypeFromDefault.spec.js')).tests,
...(await import('./src-transpiler/parseInlineParamType.spec.js')).tests,
...(await import('./src-transpiler/collectDefaultChecks.spec.js')).tests,
...(await import('./src-transpiler/harvestClassShape.spec.js')).tests,
...(await import('./src-transpiler/classTemplates.spec.js')).tests,
...(await import('./src-transpiler/functionTemplates.spec.js')).tests,
...(await import('./src-transpiler/indexedAccess.spec.js')).tests,
...(await import('./src-runtime/inspectIndexedAccess.spec.js' )).tests,
...(await import('./src-runtime/stringifyType.spec.js' )).tests,
...(await import('./src-transpiler/simplifyType.spec.js') ).tests,
//() => validateUnion(null, {type: 'union', members: ['a', 2, null] }, 'loc', 'name', true, warn),
//() => validateUnion(undefined, {type: 'union', members: ['str', 1, false] }, 'loc', 'name', true, warn) === false,
];
let errors = 0;
for (const test of tests) {
clearObject(typedefs); // Each test starts with a clean slate of typedefs
clearObject(typedefTemplates);
const ret = test();
if (!ret) {
console.error("Test failed: " + test);
errors++;
}
}
process.exit(errors); // 0 means success