@fluid-experimental/property-common 0.49.0 → 0.50.0-41540
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/constants.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/chronometer.d.ts +55 -0
- package/lib/chronometer.d.ts.map +1 -0
- package/lib/chronometer.js +185 -0
- package/lib/chronometer.js.map +1 -0
- package/lib/consoleUtils.d.ts +16 -0
- package/lib/consoleUtils.d.ts.map +1 -0
- package/lib/consoleUtils.js +20 -0
- package/lib/consoleUtils.js.map +1 -0
- package/lib/constants.d.ts +1219 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +1274 -0
- package/lib/constants.js.map +1 -0
- package/lib/datastructures/collection.d.ts +203 -0
- package/lib/datastructures/collection.d.ts.map +1 -0
- package/lib/datastructures/collection.js +377 -0
- package/lib/datastructures/collection.js.map +1 -0
- package/lib/datastructures/dataArray.d.ts +275 -0
- package/lib/datastructures/dataArray.d.ts.map +1 -0
- package/lib/datastructures/dataArray.js +497 -0
- package/lib/datastructures/dataArray.js.map +1 -0
- package/lib/datastructures/index.d.ts +9 -0
- package/lib/datastructures/index.d.ts.map +1 -0
- package/lib/datastructures/index.js +9 -0
- package/lib/datastructures/index.js.map +1 -0
- package/lib/datastructures/integer64.d.ts +47 -0
- package/lib/datastructures/integer64.d.ts.map +1 -0
- package/lib/datastructures/integer64.js +140 -0
- package/lib/datastructures/integer64.js.map +1 -0
- package/lib/datastructures/sortedCollection.d.ts +77 -0
- package/lib/datastructures/sortedCollection.d.ts.map +1 -0
- package/lib/datastructures/sortedCollection.js +140 -0
- package/lib/datastructures/sortedCollection.js.map +1 -0
- package/lib/deferredPromise.d.ts +28 -0
- package/lib/deferredPromise.d.ts.map +1 -0
- package/lib/deferredPromise.js +43 -0
- package/lib/deferredPromise.js.map +1 -0
- package/lib/deterministicRandomGenerator.d.ts +39 -0
- package/lib/deterministicRandomGenerator.d.ts.map +1 -0
- package/lib/deterministicRandomGenerator.js +83 -0
- package/lib/deterministicRandomGenerator.js.map +1 -0
- package/lib/error_objects/flaggedError.d.ts +29 -0
- package/lib/error_objects/flaggedError.d.ts.map +1 -0
- package/lib/error_objects/flaggedError.js +45 -0
- package/lib/error_objects/flaggedError.js.map +1 -0
- package/lib/error_objects/httpError.d.ts +31 -0
- package/lib/error_objects/httpError.d.ts.map +1 -0
- package/lib/error_objects/httpError.js +58 -0
- package/lib/error_objects/httpError.js.map +1 -0
- package/lib/error_objects/httpErrorNoStack.d.ts +25 -0
- package/lib/error_objects/httpErrorNoStack.d.ts.map +1 -0
- package/lib/error_objects/httpErrorNoStack.js +29 -0
- package/lib/error_objects/httpErrorNoStack.js.map +1 -0
- package/lib/error_objects/index.d.ts +9 -0
- package/lib/error_objects/index.d.ts.map +1 -0
- package/lib/error_objects/index.js +9 -0
- package/lib/error_objects/index.js.map +1 -0
- package/lib/error_objects/operationError.d.ts +32 -0
- package/lib/error_objects/operationError.d.ts.map +1 -0
- package/lib/error_objects/operationError.js +73 -0
- package/lib/error_objects/operationError.js.map +1 -0
- package/lib/guidUtils.d.ts +16 -0
- package/lib/guidUtils.d.ts.map +1 -0
- package/lib/guidUtils.js +297 -0
- package/lib/guidUtils.js.map +1 -0
- package/lib/hashCalculator.d.ts +6 -0
- package/lib/hashCalculator.d.ts.map +1 -0
- package/lib/hashCalculator.js +14 -0
- package/lib/hashCalculator.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/joinPaths.d.ts +19 -0
- package/lib/joinPaths.d.ts.map +1 -0
- package/lib/joinPaths.js +28 -0
- package/lib/joinPaths.js.map +1 -0
- package/lib/packageVersion.d.ts +9 -0
- package/lib/packageVersion.d.ts.map +1 -0
- package/lib/packageVersion.js +9 -0
- package/lib/packageVersion.js.map +1 -0
- package/package.json +22 -2
- package/platform-dependent/package.json +1 -1
- package/src/constants.ts +5 -0
- package/src/packageVersion.ts +1 -1
- package/dist/test/chronometer.spec.js +0 -90
- package/dist/test/chronometer.spec.js.map +0 -1
- package/dist/test/datastructures/collection.spec.js +0 -401
- package/dist/test/datastructures/collection.spec.js.map +0 -1
- package/dist/test/datastructures/dataArray.spec.js +0 -79
- package/dist/test/datastructures/dataArray.spec.js.map +0 -1
- package/dist/test/datastructures/sortedCollection.spec.js +0 -106
- package/dist/test/datastructures/sortedCollection.spec.js.map +0 -1
- package/dist/test/deterministicRandomGenerator.spec.js +0 -18
- package/dist/test/deterministicRandomGenerator.spec.js.map +0 -1
- package/dist/test/error_objects/flaggedError.spec.js +0 -23
- package/dist/test/error_objects/flaggedError.spec.js.map +0 -1
- package/dist/test/error_objects/httpError.spec.js +0 -61
- package/dist/test/error_objects/httpError.spec.js.map +0 -1
- package/dist/test/error_objects/httpErrorNoStack.spec.js +0 -55
- package/dist/test/error_objects/httpErrorNoStack.spec.js.map +0 -1
- package/dist/test/error_objects/operationError.spec.js +0 -132
- package/dist/test/error_objects/operationError.spec.js.map +0 -1
- package/dist/test/guidUtils.spec.js +0 -184
- package/dist/test/guidUtils.spec.js.map +0 -1
- package/dist/test/strings/joinPaths.spec.js +0 -18
- package/dist/test/strings/joinPaths.spec.js.map +0 -1
- package/dist/test/tsconfig.tsbuildinfo +0 -2278
- package/nyc/mocha-junit-report.xml +0 -175
- package/src/test/chronometer.spec.ts +0 -99
- package/src/test/datastructures/collection.spec.ts +0 -567
- package/src/test/datastructures/dataArray.spec.ts +0 -81
- package/src/test/datastructures/sortedCollection.spec.ts +0 -128
- package/src/test/deterministicRandomGenerator.spec.ts +0 -18
- package/src/test/error_objects/flaggedError.spec.ts +0 -22
- package/src/test/error_objects/httpError.spec.ts +0 -68
- package/src/test/error_objects/httpErrorNoStack.spec.ts +0 -64
- package/src/test/error_objects/operationError.spec.ts +0 -152
- package/src/test/guidUtils.spec.ts +0 -213
- package/src/test/strings/joinPaths.spec.ts +0 -17
- package/src/test/tsconfig.json +0 -21
- package/tsconfig.esnext.tsbuildinfo +0 -824
- package/tsconfig.tsbuildinfo +0 -823
|
@@ -1,567 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @fileoverview In this file, we will test the functions exported by datastructres/collection.js
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import _ from "lodash";
|
|
11
|
-
import { expect } from "chai";
|
|
12
|
-
import { Collection } from "../../index";
|
|
13
|
-
|
|
14
|
-
describe("collection", function() {
|
|
15
|
-
const createObject = () => ({
|
|
16
|
-
item4: Number.NaN,
|
|
17
|
-
item5: undefined,
|
|
18
|
-
// eslint-disable-next-line no-null/no-null
|
|
19
|
-
item6: null,
|
|
20
|
-
item7: "",
|
|
21
|
-
item8: false,
|
|
22
|
-
item9: {},
|
|
23
|
-
item10: [],
|
|
24
|
-
item11: "test",
|
|
25
|
-
item12: 0,
|
|
26
|
-
item13: 1,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should add a value under a key", function(done) {
|
|
30
|
-
const collection = new Collection<string>();
|
|
31
|
-
|
|
32
|
-
expect(collection.add("item1", "test")).to.equal("test");
|
|
33
|
-
|
|
34
|
-
expect(collection.has("item1")).to.equal(true);
|
|
35
|
-
|
|
36
|
-
collection.add(0, "test2");
|
|
37
|
-
|
|
38
|
-
expect(collection.has(0)).to.equal(true);
|
|
39
|
-
|
|
40
|
-
done();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should bulk add a key-value object to the list of items", function(done) {
|
|
44
|
-
const collection = new Collection<any>();
|
|
45
|
-
|
|
46
|
-
const objectToAdd = createObject();
|
|
47
|
-
|
|
48
|
-
expect(collection.bulkAdd(objectToAdd)).to.equal(collection);
|
|
49
|
-
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
51
|
-
const itemExists = _.every(objectToAdd, (item, key) => collection.has(key));
|
|
52
|
-
|
|
53
|
-
expect(itemExists).to.equal(true);
|
|
54
|
-
|
|
55
|
-
done();
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should remove a value associated with a key", function(done) {
|
|
59
|
-
const collection = new Collection<string>();
|
|
60
|
-
|
|
61
|
-
collection.add("item1", "test");
|
|
62
|
-
|
|
63
|
-
expect(collection.remove("item1")).to.equal(true);
|
|
64
|
-
|
|
65
|
-
expect(collection.has("item1")).to.equal(false);
|
|
66
|
-
|
|
67
|
-
expect(collection.remove("item1")).to.equal(false);
|
|
68
|
-
|
|
69
|
-
done();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should bulk remove a key-value object from the list of items", function(done) {
|
|
73
|
-
const collection = new Collection();
|
|
74
|
-
|
|
75
|
-
const objectToAdd = createObject();
|
|
76
|
-
|
|
77
|
-
collection.bulkAdd(objectToAdd);
|
|
78
|
-
collection.bulkRemove(objectToAdd);
|
|
79
|
-
|
|
80
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
81
|
-
const itemExists = _.every(objectToAdd, (item, key) => collection.has(key));
|
|
82
|
-
|
|
83
|
-
expect(itemExists).to.equal(false);
|
|
84
|
-
|
|
85
|
-
done();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should check for emptyness", function(done) {
|
|
89
|
-
const collection = new Collection<string>();
|
|
90
|
-
|
|
91
|
-
expect(collection.isEmpty()).to.equal(true);
|
|
92
|
-
|
|
93
|
-
collection.add("item1", "test");
|
|
94
|
-
|
|
95
|
-
expect(collection.isEmpty()).to.equal(false);
|
|
96
|
-
done();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should get the first value in the collection", function(done) {
|
|
100
|
-
const collection = new Collection<string>();
|
|
101
|
-
|
|
102
|
-
collection.add("item1", "test1");
|
|
103
|
-
collection.add("item2", "test2");
|
|
104
|
-
|
|
105
|
-
expect(collection.getFirstItem()).to.equal("test1");
|
|
106
|
-
done();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("should get the last value in the collection", function(done) {
|
|
110
|
-
const collection = new Collection<string>();
|
|
111
|
-
|
|
112
|
-
collection.add("item1", "test1");
|
|
113
|
-
collection.add("item2", "test2");
|
|
114
|
-
|
|
115
|
-
expect(collection.getLastItem()).to.equal("test2");
|
|
116
|
-
done();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("should get the type of the collection", function(done) {
|
|
120
|
-
const collection = new Collection("collection1", Array);
|
|
121
|
-
|
|
122
|
-
expect(collection.getType()).to.equal(Array);
|
|
123
|
-
|
|
124
|
-
done();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should filter out values based on a predicate function", function(done) {
|
|
128
|
-
const collection = new Collection<number>();
|
|
129
|
-
|
|
130
|
-
const objectToAdd = {
|
|
131
|
-
item1: 0,
|
|
132
|
-
item2: 2,
|
|
133
|
-
item3: 3,
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
collection.bulkAdd(objectToAdd);
|
|
137
|
-
|
|
138
|
-
const filteredCollection = collection.filter((key, item) => item > 0);
|
|
139
|
-
|
|
140
|
-
expect(filteredCollection.has("item1")).to.equal(false);
|
|
141
|
-
expect(filteredCollection.has("item2")).to.equal(true);
|
|
142
|
-
expect(filteredCollection.has("item3")).to.equal(true);
|
|
143
|
-
|
|
144
|
-
done();
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("should filter out values based on a key predicate", function(done) {
|
|
148
|
-
const collection = new Collection();
|
|
149
|
-
|
|
150
|
-
const objectToAdd = {
|
|
151
|
-
item1: 0,
|
|
152
|
-
item2: 2,
|
|
153
|
-
item3: 3,
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
collection.bulkAdd(objectToAdd);
|
|
157
|
-
|
|
158
|
-
const filteredCollection = collection.filterByKey(["item2", "item3"]);
|
|
159
|
-
|
|
160
|
-
expect(filteredCollection.has("item1")).to.equal(false);
|
|
161
|
-
expect(filteredCollection.has("item2")).to.equal(true);
|
|
162
|
-
expect(filteredCollection.has("item3")).to.equal(true);
|
|
163
|
-
|
|
164
|
-
const filteredCollection2 = collection.filterByKey("item2");
|
|
165
|
-
|
|
166
|
-
expect(filteredCollection2.has("item1")).to.equal(false);
|
|
167
|
-
expect(filteredCollection2.has("item2")).to.equal(true);
|
|
168
|
-
expect(filteredCollection2.has("item3")).to.equal(false);
|
|
169
|
-
|
|
170
|
-
done();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should filter out values based on a value predicate", function(done) {
|
|
174
|
-
const collection = new Collection();
|
|
175
|
-
|
|
176
|
-
const objectToAdd = {
|
|
177
|
-
item1: 0,
|
|
178
|
-
item2: 2,
|
|
179
|
-
item3: 3,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
collection.bulkAdd(objectToAdd);
|
|
183
|
-
|
|
184
|
-
const filteredCollection = collection.filterByValue(objectToAdd.item1);
|
|
185
|
-
|
|
186
|
-
expect(filteredCollection.has("item1")).to.equal(true);
|
|
187
|
-
expect(filteredCollection.has("item2")).to.equal(false);
|
|
188
|
-
expect(filteredCollection.has("item3")).to.equal(false);
|
|
189
|
-
|
|
190
|
-
done();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("should return the number of elements in the collection", function(done) {
|
|
194
|
-
const collection = new Collection();
|
|
195
|
-
|
|
196
|
-
const objectToAdd = {
|
|
197
|
-
item1: 0,
|
|
198
|
-
item2: 2,
|
|
199
|
-
item3: 3,
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
collection.bulkAdd(objectToAdd);
|
|
203
|
-
|
|
204
|
-
expect(collection.getCount()).to.equal(3);
|
|
205
|
-
done();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("should return the list of items in an array", function(done) {
|
|
209
|
-
const collection = new Collection();
|
|
210
|
-
|
|
211
|
-
const objectToAdd = {
|
|
212
|
-
item1: 0,
|
|
213
|
-
item2: 2,
|
|
214
|
-
item3: 3,
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
collection.bulkAdd(objectToAdd);
|
|
218
|
-
|
|
219
|
-
const array = collection.getAsArray();
|
|
220
|
-
|
|
221
|
-
expect(array).to.be.an("array");
|
|
222
|
-
|
|
223
|
-
const exists = _.every(objectToAdd, (item) => _.includes(array, item));
|
|
224
|
-
|
|
225
|
-
expect(exists).to.equal(true);
|
|
226
|
-
|
|
227
|
-
done();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it("should check if an item exists", function(done) {
|
|
231
|
-
const collection = new Collection();
|
|
232
|
-
|
|
233
|
-
const objectToAdd = {
|
|
234
|
-
item1: 0,
|
|
235
|
-
item2: 2,
|
|
236
|
-
item3: 3,
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
collection.bulkAdd(objectToAdd);
|
|
240
|
-
|
|
241
|
-
expect(collection.has("item2")).to.equal(true);
|
|
242
|
-
expect(collection.has("foo")).to.equal(false);
|
|
243
|
-
|
|
244
|
-
done();
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it("should get an item from the collection", function(done) {
|
|
248
|
-
const collection = new Collection();
|
|
249
|
-
|
|
250
|
-
const objectToAdd = {
|
|
251
|
-
item1: 0,
|
|
252
|
-
item2: 2,
|
|
253
|
-
item3: 3,
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
collection.bulkAdd(objectToAdd);
|
|
257
|
-
|
|
258
|
-
expect(collection.item("item2")).to.equal(objectToAdd.item2);
|
|
259
|
-
|
|
260
|
-
done();
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("should set the value of a key", function(done) {
|
|
264
|
-
const collection = new Collection();
|
|
265
|
-
|
|
266
|
-
const objectToAdd = {
|
|
267
|
-
item1: 0,
|
|
268
|
-
item2: 2,
|
|
269
|
-
item3: 3,
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
collection.bulkAdd(objectToAdd);
|
|
273
|
-
|
|
274
|
-
collection.set("item1", 5);
|
|
275
|
-
|
|
276
|
-
expect(collection.item("item1")).to.equal(5);
|
|
277
|
-
|
|
278
|
-
done();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("should iterate over the set of items", function(done) {
|
|
282
|
-
const collection = new Collection();
|
|
283
|
-
|
|
284
|
-
const objectToAdd = {
|
|
285
|
-
item1: 0,
|
|
286
|
-
item2: 2,
|
|
287
|
-
item3: 3,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
collection.bulkAdd(objectToAdd);
|
|
291
|
-
|
|
292
|
-
const result = {};
|
|
293
|
-
collection.iterate(function(key, item) {
|
|
294
|
-
result[key] = item;
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
expect(result).to.deep.equal(objectToAdd);
|
|
298
|
-
|
|
299
|
-
done();
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("should iterate over the set of items starting from the tail", function(done) {
|
|
303
|
-
const collection = new Collection();
|
|
304
|
-
|
|
305
|
-
const objectToAdd = {
|
|
306
|
-
item1: 0,
|
|
307
|
-
item2: 2,
|
|
308
|
-
item3: 3,
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
collection.bulkAdd(objectToAdd);
|
|
312
|
-
|
|
313
|
-
const result = {};
|
|
314
|
-
const keys = collection.getKeys();
|
|
315
|
-
let i = keys.length - 1;
|
|
316
|
-
collection.iterateFromTail(function(key, item) {
|
|
317
|
-
result[key] = item;
|
|
318
|
-
expect(key).to.equal(keys[i]);
|
|
319
|
-
i--;
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
expect(result).to.deep.equal(objectToAdd);
|
|
323
|
-
|
|
324
|
-
done();
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("should return all items in an JSON format", function(done) {
|
|
328
|
-
const collection = new Collection();
|
|
329
|
-
|
|
330
|
-
const objectToAdd = {
|
|
331
|
-
item1: 0,
|
|
332
|
-
item2: 2,
|
|
333
|
-
item3: 3,
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
collection.bulkAdd(objectToAdd);
|
|
337
|
-
|
|
338
|
-
expect(collection.getItems()).to.deep.equal(objectToAdd);
|
|
339
|
-
|
|
340
|
-
done();
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
it("should return all keys in an array", function(done) {
|
|
344
|
-
const collection = new Collection();
|
|
345
|
-
|
|
346
|
-
const objectToAdd = {
|
|
347
|
-
item1: 0,
|
|
348
|
-
item2: 2,
|
|
349
|
-
item3: 3,
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
collection.bulkAdd(objectToAdd);
|
|
353
|
-
|
|
354
|
-
expect(collection.getKeys()).to.deep.equal(_.keys(objectToAdd));
|
|
355
|
-
|
|
356
|
-
done();
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
it("should return the first item in the collection along with the key", function(done) {
|
|
360
|
-
const collection = new Collection();
|
|
361
|
-
|
|
362
|
-
collection.add("item1", "test1");
|
|
363
|
-
collection.add("item2", "test2");
|
|
364
|
-
|
|
365
|
-
expect(collection.peak()).to.deep.equal({ key: "item1", item: "test1" });
|
|
366
|
-
|
|
367
|
-
done();
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
describe("clear", function() {
|
|
371
|
-
it("should empty the collection", function(done) {
|
|
372
|
-
const collection = new Collection();
|
|
373
|
-
|
|
374
|
-
const objectToAdd = {
|
|
375
|
-
item1: 0,
|
|
376
|
-
item2: 2,
|
|
377
|
-
item3: 3,
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
collection.bulkAdd(objectToAdd);
|
|
381
|
-
|
|
382
|
-
const ret = collection.clear();
|
|
383
|
-
|
|
384
|
-
expect(collection.isEmpty()).to.equal(true);
|
|
385
|
-
expect(ret).to.equal(collection);
|
|
386
|
-
|
|
387
|
-
done();
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
it("should return the collection itself", function(done) {
|
|
391
|
-
const collection = new Collection();
|
|
392
|
-
const ret = collection.clear();
|
|
393
|
-
expect(ret).to.equal(collection);
|
|
394
|
-
done();
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it("should clone the collection", function(done) {
|
|
399
|
-
const collection = new Collection();
|
|
400
|
-
|
|
401
|
-
const objectToAdd = {
|
|
402
|
-
item1: 0,
|
|
403
|
-
item2: 2,
|
|
404
|
-
item3: 3,
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
collection.bulkAdd(objectToAdd);
|
|
408
|
-
|
|
409
|
-
expect(collection.clone().items).to.deep.equal(collection.items);
|
|
410
|
-
|
|
411
|
-
done();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it("should copy the collection", function(done) {
|
|
415
|
-
const collection = new Collection();
|
|
416
|
-
|
|
417
|
-
const objectToAdd = {
|
|
418
|
-
item1: "test",
|
|
419
|
-
item2: true,
|
|
420
|
-
item3: 23,
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
collection.bulkAdd(objectToAdd);
|
|
424
|
-
|
|
425
|
-
const collection2 = new Collection();
|
|
426
|
-
|
|
427
|
-
collection2.copy(collection);
|
|
428
|
-
|
|
429
|
-
expect(collection2.items.item1).to.equal(objectToAdd.item1);
|
|
430
|
-
expect(collection2.items.item2).to.equal(objectToAdd.item2);
|
|
431
|
-
expect(collection2.items.item3).to.equal(objectToAdd.item3);
|
|
432
|
-
|
|
433
|
-
done();
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
it("should invoke the onAdd callback", function(done) {
|
|
437
|
-
const collection = new Collection();
|
|
438
|
-
|
|
439
|
-
let triggered = false;
|
|
440
|
-
|
|
441
|
-
collection.onAdd = function(key, item) {
|
|
442
|
-
triggered = true;
|
|
443
|
-
expect(key).to.equal("item");
|
|
444
|
-
expect(item).to.equal("value");
|
|
445
|
-
};
|
|
446
|
-
collection.add("item", "value");
|
|
447
|
-
|
|
448
|
-
expect(triggered).to.equal(true);
|
|
449
|
-
|
|
450
|
-
let callbackCounter = 0;
|
|
451
|
-
const objectToAdd = createObject();
|
|
452
|
-
|
|
453
|
-
// now override the onAdd function and check wiether we call it
|
|
454
|
-
// when we bulkAdd
|
|
455
|
-
collection.onAdd = function(key, item) {
|
|
456
|
-
callbackCounter++;
|
|
457
|
-
expect(Object.prototype.hasOwnProperty.call(objectToAdd, key)).to.equal(true);
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
collection.bulkAdd(objectToAdd);
|
|
461
|
-
expect(callbackCounter).to.equal(_.keys(objectToAdd).length);
|
|
462
|
-
|
|
463
|
-
done();
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it("should invoke the onRemove callback", function(done) {
|
|
467
|
-
const collection = new Collection();
|
|
468
|
-
|
|
469
|
-
let triggered = false;
|
|
470
|
-
|
|
471
|
-
collection.onRemove = function(key, item) {
|
|
472
|
-
triggered = true;
|
|
473
|
-
expect(key).to.equal("item");
|
|
474
|
-
expect(item).to.equal("value");
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
collection.add("item", "value");
|
|
478
|
-
collection.remove("item");
|
|
479
|
-
expect(triggered).to.equal(true);
|
|
480
|
-
|
|
481
|
-
// Should not invoke the onRemove here
|
|
482
|
-
triggered = false;
|
|
483
|
-
collection.remove("item");
|
|
484
|
-
|
|
485
|
-
expect(triggered).to.equal(false);
|
|
486
|
-
|
|
487
|
-
let callbackCounter = 0;
|
|
488
|
-
const objectToAdd = createObject();
|
|
489
|
-
|
|
490
|
-
// now override the onRemove function and check wiether we call it
|
|
491
|
-
// when we bulkRemove
|
|
492
|
-
collection.onRemove = function(key, item) {
|
|
493
|
-
callbackCounter++;
|
|
494
|
-
expect(Object.prototype.hasOwnProperty.call(objectToAdd, key)).to.equal(true);
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
collection.bulkAdd(objectToAdd);
|
|
498
|
-
collection.bulkRemove(objectToAdd);
|
|
499
|
-
|
|
500
|
-
expect(callbackCounter).to.equal(_.keys(objectToAdd).length);
|
|
501
|
-
|
|
502
|
-
done();
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it("should stop early when iterating", function() {
|
|
506
|
-
const collection = new Collection();
|
|
507
|
-
|
|
508
|
-
const objectToAdd = {
|
|
509
|
-
item1: "test",
|
|
510
|
-
item2: true,
|
|
511
|
-
item3: 23,
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
collection.bulkAdd(objectToAdd);
|
|
515
|
-
|
|
516
|
-
let iterator = 1;
|
|
517
|
-
|
|
518
|
-
collection.iterate(function() {
|
|
519
|
-
if (iterator === 2) {
|
|
520
|
-
return false;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
iterator++;
|
|
524
|
-
|
|
525
|
-
return true;
|
|
526
|
-
});
|
|
527
|
-
|
|
528
|
-
expect(iterator).to.equal(2);
|
|
529
|
-
|
|
530
|
-
iterator = 1;
|
|
531
|
-
|
|
532
|
-
collection.iterateFromTail(function() {
|
|
533
|
-
if (iterator === 2) {
|
|
534
|
-
return false;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
iterator++;
|
|
538
|
-
|
|
539
|
-
return true;
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
expect(iterator).to.equal(2);
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
it("should invoke the onClear callback", function(done) {
|
|
546
|
-
const collection = new Collection();
|
|
547
|
-
|
|
548
|
-
const objectToAdd = createObject();
|
|
549
|
-
let triggered = false;
|
|
550
|
-
collection.onClear = function(items) {
|
|
551
|
-
triggered = true;
|
|
552
|
-
expect(items).to.deep.equal(objectToAdd);
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
// this shouldn't invoke the callback
|
|
556
|
-
collection.clear();
|
|
557
|
-
|
|
558
|
-
expect(triggered).to.equal(false);
|
|
559
|
-
|
|
560
|
-
collection.bulkAdd(objectToAdd);
|
|
561
|
-
collection.clear();
|
|
562
|
-
|
|
563
|
-
expect(triggered).to.equal(true);
|
|
564
|
-
|
|
565
|
-
done();
|
|
566
|
-
});
|
|
567
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @fileoverview In this file, we will test the functions exported by deep_copy.js
|
|
7
|
-
*/
|
|
8
|
-
import { expect } from "chai";
|
|
9
|
-
import {
|
|
10
|
-
Int32DataArray,
|
|
11
|
-
UniversalDataArray,
|
|
12
|
-
Int8DataArray,
|
|
13
|
-
BoolDataArray,
|
|
14
|
-
} from "../../index";
|
|
15
|
-
let error;
|
|
16
|
-
|
|
17
|
-
describe("BaseDataArray", function() {
|
|
18
|
-
it("should set, insert and remove some values in a (TypedArray) DataArray", function() {
|
|
19
|
-
const myDataArray = new Int32DataArray(5);
|
|
20
|
-
try {
|
|
21
|
-
myDataArray.set(0, [1, 2, 3, 4, 5]);
|
|
22
|
-
myDataArray.insertRange(2, [31, 32, 33]);
|
|
23
|
-
myDataArray.removeRange(3, 4);
|
|
24
|
-
} catch (e) {
|
|
25
|
-
error = e;
|
|
26
|
-
} finally {
|
|
27
|
-
expect(error).to.equal(undefined);
|
|
28
|
-
expect(myDataArray.length).to.equal(4);
|
|
29
|
-
expect(Array.prototype.slice.call(myDataArray.getBuffer())).to.deep.equal([1, 2, 31, 5]);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("should set, insert and remove some values in a UniversalArray", function() {
|
|
34
|
-
const myDataArray = new UniversalDataArray(5);
|
|
35
|
-
try {
|
|
36
|
-
console.log("UniversalArray: ", myDataArray);
|
|
37
|
-
myDataArray.set(0, ["1", "2", "3", "4", "5"]);
|
|
38
|
-
myDataArray.insertRange(2, ["31", "32", "33"]);
|
|
39
|
-
myDataArray.removeRange(3, 4);
|
|
40
|
-
} catch (e) {
|
|
41
|
-
error = e;
|
|
42
|
-
} finally {
|
|
43
|
-
expect(error).to.equal(undefined);
|
|
44
|
-
expect(myDataArray.length).to.equal(4);
|
|
45
|
-
expect(Array.prototype.slice.call(myDataArray.getBuffer())).to.deep.equal(["1", "2", "31", "5"]);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should get all elements from array", function() {
|
|
50
|
-
const myDataArray = new Int8DataArray(5);
|
|
51
|
-
myDataArray.set(0, [1, 2, 3, 4, 5]);
|
|
52
|
-
const subArray = myDataArray.getValueRange(0, 5);
|
|
53
|
-
expect(subArray.length).to.equal(5);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("BoolDataArray", function() {
|
|
58
|
-
it("should set, insert and remove some values", function() {
|
|
59
|
-
const myDataArray = new BoolDataArray(5);
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
myDataArray.set(0, [1, 0, false, 1, true]);
|
|
63
|
-
myDataArray.insertRange(2, [1, 0, false]);
|
|
64
|
-
myDataArray.removeRange(3, 4);
|
|
65
|
-
} catch (e) {
|
|
66
|
-
error = e;
|
|
67
|
-
} finally {
|
|
68
|
-
expect(error).to.equal(undefined);
|
|
69
|
-
expect(myDataArray.length).to.equal(4);
|
|
70
|
-
expect(Array.prototype.slice.call(myDataArray.getBuffer())).to.deep.equal([true, false, true, true]);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should get all elements from array", function() {
|
|
75
|
-
const myDataArray = new BoolDataArray(5);
|
|
76
|
-
myDataArray.set(0, [true, false, true, false, false]);
|
|
77
|
-
const subArray = myDataArray.getValueRange(1, 4);
|
|
78
|
-
expect(subArray.length).to.equal(3);
|
|
79
|
-
expect(subArray).to.deep.equal([false, true, false]);
|
|
80
|
-
});
|
|
81
|
-
});
|