deno.land / std@0.224.0 / expect / _equal_test.ts

_equal_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
253
254
255
256
257
258
259
260
261
262
263
264
265
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This file is copied from `std/assert`.
import { assert, assertFalse, assertThrows } from "../assert/mod.ts";import { equal } from "./_equal.ts";
Deno.test("equal() matches with different zero", () => { assert(equal(0, -0)); assert(equal(0, +0)); assert(equal(+0, -0)); assert(equal([0], [-0])); assert(equal(["hello", 12.21, 0], ["hello", 12.21, -0])); assert(equal(["hello", 12.21, 0], ["hello", 12.21, +0])); assert(equal(["hello", 12.21, -0], ["hello", 12.21, +0])); assert(equal({ msg: "hello", case: 0 }, { msg: "hello", case: -0 })); assert(equal({ msg: "hello", array: [0] }, { msg: "hello", array: [-0] }));});
Deno.test("equal() matches when values are equal", function () { assert(equal("world", "world")); assert(!equal("hello", "world")); assertFalse(equal("hello", "world")); assert(equal(5, 5)); assert(!equal(5, 6)); assertFalse(equal(5, 6)); assert(equal(NaN, NaN)); assert(equal({ hello: "world" }, { hello: "world" })); assert(!equal({ world: "hello" }, { hello: "world" })); assertFalse(equal({ world: "hello" }, { hello: "world" })); assert( equal( { hello: "world", hi: { there: "everyone" } }, { hello: "world", hi: { there: "everyone" } }, ), ); assert( !equal( { hello: "world", hi: { there: "everyone" } }, { hello: "world", hi: { there: "everyone else" } }, ), ); assertFalse( equal( { hello: "world", hi: { there: "everyone" } }, { hello: "world", hi: { there: "everyone else" } }, ), ); assert(equal({ [Symbol.for("foo")]: "bar" }, { [Symbol.for("foo")]: "bar" })); assert(!equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" })); assertFalse(equal({ [Symbol("foo")]: "bar" }, { [Symbol("foo")]: "bar" }));
assert(equal(/deno/, /deno/)); assert(!equal(/deno/, /node/)); assertFalse(equal(/deno/, /node/)); assert(equal(new Date(2019, 0, 3), new Date(2019, 0, 3))); assert(!equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); assertFalse(equal(new Date(2019, 0, 3), new Date(2019, 1, 3))); assert( !equal( new Date(2019, 0, 3, 4, 20, 1, 10), new Date(2019, 0, 3, 4, 20, 1, 20), ), ); assertFalse( equal( new Date(2019, 0, 3, 4, 20, 1, 10), new Date(2019, 0, 3, 4, 20, 1, 20), ), ); assert(equal(new Date("Invalid"), new Date("Invalid"))); assert(!equal(new Date("Invalid"), new Date(2019, 0, 3))); assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3))); assert(!equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); assertFalse(equal(new Date("Invalid"), new Date(2019, 0, 3, 4, 20, 1, 10))); assert(equal(new Set([1]), new Set([1]))); assert(!equal(new Set([1]), new Set([2]))); assertFalse(equal(new Set([1]), new Set([2]))); assert(equal(new Set([1, 2, 3]), new Set([3, 2, 1]))); assert(equal(new Set([1, new Set([2, 3])]), new Set([new Set([3, 2]), 1]))); assert(!equal(new Set([1, 2]), new Set([3, 2, 1]))); assertFalse(equal(new Set([1, 2]), new Set([3, 2, 1]))); assert(!equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); assertFalse(equal(new Set([1, 2, 3]), new Set([4, 5, 6]))); assert(equal(new Set("denosaurus"), new Set("denosaurussss"))); assert(equal(new Map(), new Map())); assert( equal( new Map([ ["foo", "bar"], ["baz", "baz"], ]), new Map([ ["foo", "bar"], ["baz", "baz"], ]), ), ); assert( equal( new Map([["foo", new Map([["bar", "baz"]])]]), new Map([["foo", new Map([["bar", "baz"]])]]), ), ); assert( equal( new Map([["foo", { bar: "baz" }]]), new Map([["foo", { bar: "baz" }]]), ), ); assert( equal( new Map([ ["foo", "bar"], ["baz", "qux"], ]), new Map([ ["baz", "qux"], ["foo", "bar"], ]), ), ); assert(equal(new Map([["foo", ["bar"]]]), new Map([["foo", ["bar"]]]))); assert(!equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); assertFalse(equal(new Map([["foo", "bar"]]), new Map([["bar", "baz"]]))); assert( !equal( new Map([["foo", "bar"]]), new Map([ ["foo", "bar"], ["bar", "baz"], ]), ), ); assertFalse( equal( new Map([["foo", "bar"]]), new Map([ ["foo", "bar"], ["bar", "baz"], ]), ), ); assert( !equal( new Map([["foo", new Map([["bar", "baz"]])]]), new Map([["foo", new Map([["bar", "qux"]])]]), ), ); assert(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, true]]))); assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 1 }, false]]))); assert(!equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); assertFalse(equal(new Map([[{ x: 1 }, true]]), new Map([[{ x: 2 }, true]]))); assert(equal([1, 2, 3], [1, 2, 3])); assert(equal([1, [2, 3]], [1, [2, 3]])); assert(!equal([1, 2, 3, 4], [1, 2, 3])); assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); assert(!equal([1, 2, 3, 4], [1, 2, 3])); assertFalse(equal([1, 2, 3, 4], [1, 2, 3])); assert(!equal([1, 2, 3, 4], [1, 4, 2, 3])); assertFalse(equal([1, 2, 3, 4], [1, 4, 2, 3])); assert(equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([1, 2, 3, 4]))); assert(!equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3]))); assertFalse( equal(new Uint8Array([1, 2, 3, 4]), new Uint8Array([2, 1, 4, 3])), ); assert( equal(new URL("https://example.test"), new URL("https://example.test")), ); assert( !equal( new URL("https://example.test"), new URL("https://example.test/with-path"), ), ); assertFalse( equal( new URL("https://example.test"), new URL("https://example.test/with-path"), ), ); assert( equal({ a: undefined, b: undefined }, { a: undefined, c: undefined }), ); assert(equal({ a: undefined, b: undefined }, { a: undefined })); assertThrows(() => equal(new WeakMap(), new WeakMap())); assertThrows(() => equal(new WeakSet(), new WeakSet())); assert(!equal(new WeakMap(), new WeakSet())); assertFalse(equal(new WeakMap(), new WeakSet())); assert( equal(new WeakRef({ hello: "world" }), new WeakRef({ hello: "world" })), ); assert( !equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), ); assertFalse( equal(new WeakRef({ world: "hello" }), new WeakRef({ hello: "world" })), ); assert(!equal({ hello: "world" }, new WeakRef({ hello: "world" }))); assertFalse(equal({ hello: "world" }, new WeakRef({ hello: "world" }))); assert( equal( new WeakRef({ hello: "world" }), new (class<T extends object> extends WeakRef<T> {})({ hello: "world" }), ), ); assert( !equal( new WeakRef({ hello: "world" }), new (class<T extends object> extends WeakRef<T> { foo = "bar"; })({ hello: "world" }), ), ); assertFalse( equal( new WeakRef({ hello: "world" }), new (class<T extends object> extends WeakRef<T> { foo = "bar"; })({ hello: "world" }), ), );
assert( equal( new (class A { #hello = "world"; })(), new (class B { #hello = "world"; })(), ), );});
Deno.test("equal() does not match with different instances", () => { assert(!equal({}, [])); assert(!equal(/foo/, new Set())); assert(!equal(new Set(), new Map())); assert(!equal(null, 2)); assert(!equal(2, null));});
Deno.test("equal() does not match with different collection contents", () => { assert(!equal(new Set([1]), new Set([2]))); assert(!equal(new Map([[1, 2]]), new Map([[2, 1]]))); assert(equal(new Map([[1, 2]]), new Map([[1, 2]])));});
Deno.test("equal() matches when values have circular references", () => { const objA: { prop?: unknown } = {}; objA.prop = objA; const objB: { prop?: unknown } = {}; objB.prop = objB; assert(equal(objA, objB));
const mapA = new Map(); mapA.set("prop", mapA); const mapB = new Map(); mapB.set("prop", mapB); assert(equal(mapA, mapB));});
std

Version Info

Tagged at
3 weeks ago