deno.land / std@0.166.0 / node / util_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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertStrictEquals, assertThrows,} from "../testing/asserts.ts";import { stripColor } from "../fmt/colors.ts";import * as util from "./util.ts";
// Note: Need to import this to lazily initialize error classesimport "./internal/errors.ts";
Deno.test({ name: "[util] format", fn() { assertEquals(util.format("%o", [10, 11]), "[ 10, 11, [length]: 2 ]"); },});
Deno.test({ name: "[util] inspect.custom", fn() { assertEquals(util.inspect.custom, Symbol.for("nodejs.util.inspect.custom")); },});
Deno.test({ name: "[util] inspect", fn() { assertEquals(stripColor(util.inspect({ foo: 123 })), "{ foo: 123 }"); assertEquals(stripColor(util.inspect("foo")), "'foo'"); assertEquals( stripColor(util.inspect("Deno's logo is so cute.")), `"Deno's logo is so cute."`, ); assertEquals( stripColor(util.inspect([1, 2, 3, 4, 5, 6, 7])), `[ 1, 2, 3, 4, 5, 6, 7]`, ); },});
Deno.test({ name: "[util] isBoolean", fn() { assert(util.isBoolean(true)); assert(util.isBoolean(new Boolean())); assert(util.isBoolean(new Boolean(true))); assert(util.isBoolean(false)); assert(!util.isBoolean("deno")); assert(!util.isBoolean("true")); },});
Deno.test({ name: "[util] isNull", fn() { let n; assert(util.isNull(null)); assert(!util.isNull(n)); assert(!util.isNull(0)); assert(!util.isNull({})); },});
Deno.test({ name: "[util] isNullOrUndefined", fn() { let n; assert(util.isNullOrUndefined(null)); assert(util.isNullOrUndefined(n)); assert(!util.isNullOrUndefined({})); assert(!util.isNullOrUndefined("undefined")); },});
Deno.test({ name: "[util] isNumber", fn() { assert(util.isNumber(666)); assert(util.isNumber(new Number(666))); assert(!util.isNumber("999")); assert(!util.isNumber(null)); },});
Deno.test({ name: "[util] isString", fn() { assert(util.isString("deno")); assert(util.isString(new String("DIO"))); assert(!util.isString(1337)); },});
Deno.test({ name: "[util] isSymbol", fn() { assert(util.isSymbol(Symbol())); assert(!util.isSymbol(123)); assert(!util.isSymbol("string")); },});
Deno.test({ name: "[util] isUndefined", fn() { let t; assert(util.isUndefined(t)); assert(!util.isUndefined("undefined")); assert(!util.isUndefined({})); },});
Deno.test({ name: "[util] isObject", fn() { const dio = { stand: "Za Warudo" }; assert(util.isObject(dio)); assert(util.isObject(new RegExp(/Toki Wo Tomare/))); assert(!util.isObject("Jotaro")); },});
Deno.test({ name: "[util] isError", fn() { const java = new Error(); const nodejs = new TypeError(); const deno = "Future"; assert(util.isError(java)); assert(util.isError(nodejs)); assert(!util.isError(deno)); },});
Deno.test({ name: "[util] isFunction", fn() { const f = function () {}; assert(util.isFunction(f)); assert(!util.isFunction({})); assert(!util.isFunction(new RegExp(/f/))); },});
Deno.test({ name: "[util] isRegExp", fn() { assert(util.isRegExp(new RegExp(/f/))); assert(util.isRegExp(/fuManchu/)); assert(!util.isRegExp({ evil: "eye" })); assert(!util.isRegExp(null)); },});
Deno.test({ name: "[util] isArray", fn() { assert(util.isArray([])); assert(!util.isArray({ yaNo: "array" })); assert(!util.isArray(null)); },});
Deno.test({ name: "[util] isPrimitive", fn() { const stringType = "hasti"; const booleanType = true; const integerType = 2; const symbolType = Symbol("anything");
const functionType = function doBest() {}; const objectType = { name: "ali" }; const arrayType = [1, 2, 3];
assert(util.isPrimitive(stringType)); assert(util.isPrimitive(booleanType)); assert(util.isPrimitive(integerType)); assert(util.isPrimitive(symbolType)); assert(util.isPrimitive(null)); assert(util.isPrimitive(undefined)); assert(!util.isPrimitive(functionType)); assert(!util.isPrimitive(arrayType)); assert(!util.isPrimitive(objectType)); },});
Deno.test({ name: "[util] TextDecoder", fn() { assert(util.TextDecoder === TextDecoder); const td: util.TextDecoder = new util.TextDecoder(); assert(td instanceof TextDecoder); },});
Deno.test({ name: "[util] TextEncoder", fn() { assert(util.TextEncoder === TextEncoder); const te: util.TextEncoder = new util.TextEncoder(); assert(te instanceof TextEncoder); },});
Deno.test({ name: "[util] isDate", fn() { // Test verifies the method is exposed. See _util/_util_types_test for details assert(util.types.isDate(new Date())); },});
Deno.test({ name: "[util] getSystemErrorName()", fn() { type FnTestInvalidArg = (code?: unknown) => void;
assertThrows( () => (util.getSystemErrorName as FnTestInvalidArg)(), TypeError, ); assertThrows( () => (util.getSystemErrorName as FnTestInvalidArg)(1), RangeError, );
assertStrictEquals(util.getSystemErrorName(-424242), undefined);
switch (Deno.build.os) { case "windows": assertStrictEquals(util.getSystemErrorName(-4091), "EADDRINUSE"); break;
case "darwin": assertStrictEquals(util.getSystemErrorName(-48), "EADDRINUSE"); break;
case "linux": assertStrictEquals(util.getSystemErrorName(-98), "EADDRINUSE"); break; } },});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2447

Version Info

Tagged at
2 months ago