This commit is contained in:
2021-10-03 20:06:12 +03:00
parent dee5c19f48
commit a0a6a9b710
11 changed files with 459 additions and 168 deletions
+77
View File
@@ -0,0 +1,77 @@
<script src="../assets/config/config.js"></script>
<script src="../assets/core/core.js"></script>
<script src="../assets/core/core.register.js"></script>
<script>
kit.PluginManager.install('Collection');
function assertSame(value, need, msg) {
if(value === need) {
console.log(true, msg);
return;
}
console.error(msg, value, need);
}
</script>
<h1>в консоле</h1>
<script>
kit.ready(['collection'], function () {
console.warn('ARRAY');
var arr = [];
arr[10] = 100;
var collection = new kit.Collection(arr);
assertSame(collection.count(), 1, 'Количество');
assertSame(collection.has(10), true, 'has');
assertSame(collection.has('10'), true, 'has');
assertSame(collection.has('5'), false, 'has');
assertSame(collection.get(3, 2), 2, 'get');
assertSame(collection.get(10, 2), 100, 'get');
assertSame(collection.get(11), undefined, 'get');
console.warn('Object');
var ob = {
a: 1,
b: 2,
10: 3,
};
collection = new kit.Collection(ob);
assertSame(collection.count(), 3, 'Количество');
assertSame(collection.has(10), true, 'has');
assertSame(collection.has('10'), true, 'has');
assertSame(collection.has('5'), false, 'has');
assertSame(collection.get('a'), 1, 'get');
assertSame(collection.get(3, 2), 2, 'get');
assertSame(collection.get(10, 2), 3, 'get');
assertSame(collection.get(11), undefined, 'get');
assertSame(JSON.stringify(collection.set(5, 19).all()), JSON.stringify({
a: 1,
b: 2,
10: 3,
5: 19,
}), 'get');
var testFunction = function (q, w, e, r, t, y) {
var c = new kit.Collection(arguments);
assertSame(c.count(), 8, 'arguments count');
assertSame(c.get(0), 1, 'arguments get');
assertSame(c.get(7), 8, 'arguments get');
assertSame(c.get(8, 80), 80, 'arguments get');
}
testFunction(1, 2, 3, 4, 5, 6, 7, 8);
});
</script>