Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,64 +1,64 @@
|
||||
import LinkedList from '../../../../src/ol/structs/LinkedList.js';
|
||||
|
||||
describe('ol.structs.LinkedList', function() {
|
||||
describe('ol.structs.LinkedList', function () {
|
||||
let ll;
|
||||
const item = {};
|
||||
const item2 = {};
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
ll = new LinkedList();
|
||||
});
|
||||
|
||||
it('defaults to circular', function() {
|
||||
it('defaults to circular', function () {
|
||||
expect(ll.circular_).to.be(true);
|
||||
});
|
||||
|
||||
it('creates an empty list', function() {
|
||||
it('creates an empty list', function () {
|
||||
expect(ll.length_).to.be(0);
|
||||
expect(ll.first_).to.be(undefined);
|
||||
expect(ll.last_).to.be(undefined);
|
||||
expect(ll.head_).to.be(undefined);
|
||||
});
|
||||
|
||||
describe('#insertItem', function() {
|
||||
beforeEach(function() {
|
||||
describe('#insertItem', function () {
|
||||
beforeEach(function () {
|
||||
ll.insertItem(item);
|
||||
});
|
||||
|
||||
it('inserts an item into the list', function() {
|
||||
it('inserts an item into the list', function () {
|
||||
expect(ll.length_).to.be(1);
|
||||
});
|
||||
|
||||
it('sets the cursor to the inserted item', function() {
|
||||
it('sets the cursor to the inserted item', function () {
|
||||
expect(ll.head_.data).to.be(item);
|
||||
});
|
||||
|
||||
it('links the previous item to the new one', function() {
|
||||
it('links the previous item to the new one', function () {
|
||||
ll.insertItem(item2);
|
||||
expect(ll.head_.prev.data).to.be(item);
|
||||
expect(ll.head_.prev.next.data).to.be(item2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeItem', function() {
|
||||
describe('#removeItem', function () {
|
||||
const item3 = {};
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
ll.insertItem(item3);
|
||||
});
|
||||
|
||||
it('removes the current item', function() {
|
||||
it('removes the current item', function () {
|
||||
ll.removeItem();
|
||||
expect(ll.length_).to.be(2);
|
||||
expect(ll.head_.data).not.to.be(item3);
|
||||
});
|
||||
|
||||
it('sets the cursor to the next item if possible', function() {
|
||||
it('sets the cursor to the next item if possible', function () {
|
||||
ll.removeItem();
|
||||
expect(ll.head_.data).to.be(item);
|
||||
});
|
||||
|
||||
it('otherwise sets the cursor to the previous item', function() {
|
||||
it('otherwise sets the cursor to the previous item', function () {
|
||||
ll = new LinkedList(false);
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
@@ -67,7 +67,7 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item2);
|
||||
});
|
||||
|
||||
it('empties a list with only one item', function() {
|
||||
it('empties a list with only one item', function () {
|
||||
ll = new LinkedList();
|
||||
ll.insertItem(item);
|
||||
ll.removeItem();
|
||||
@@ -78,8 +78,8 @@ describe('ol.structs.LinkedList', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#firstItem', function() {
|
||||
it('sets the cursor to the first item and returns its data', function() {
|
||||
describe('#firstItem', function () {
|
||||
it('sets the cursor to the first item and returns its data', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
const i = ll.firstItem();
|
||||
@@ -87,14 +87,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.firstItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#lastItem', function() {
|
||||
it('sets the cursor to the last item and returns its data', function() {
|
||||
describe('#lastItem', function () {
|
||||
it('sets the cursor to the last item and returns its data', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
ll.firstItem();
|
||||
@@ -103,14 +103,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item2);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.lastItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#nextItem', function() {
|
||||
it('sets the cursor to the next item and returns its data', function() {
|
||||
describe('#nextItem', function () {
|
||||
it('sets the cursor to the next item and returns its data', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
ll.firstItem();
|
||||
@@ -119,14 +119,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item2);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.nextItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#prevItem', function() {
|
||||
it('sets the cursor to the previous item and returns its data', function() {
|
||||
describe('#prevItem', function () {
|
||||
it('sets the cursor to the previous item and returns its data', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
const i = ll.prevItem();
|
||||
@@ -134,14 +134,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.prevItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getNextItem', function() {
|
||||
it('returns the data of the next item without stepping the cursor', function() {
|
||||
describe('#getNextItem', function () {
|
||||
it('returns the data of the next item without stepping the cursor', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
ll.firstItem();
|
||||
@@ -150,14 +150,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.getNextItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getPrevItem', function() {
|
||||
it('returns the data of the previous item without stepping the cursor', function() {
|
||||
describe('#getPrevItem', function () {
|
||||
it('returns the data of the previous item without stepping the cursor', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
const i = ll.getPrevItem();
|
||||
@@ -165,14 +165,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item2);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.getPrevItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCurrItem', function() {
|
||||
it('returns the data of the current item', function() {
|
||||
describe('#getCurrItem', function () {
|
||||
it('returns the data of the current item', function () {
|
||||
const item3 = {};
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
@@ -183,14 +183,14 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item2);
|
||||
});
|
||||
|
||||
it('returns undefined on empty list', function() {
|
||||
it('returns undefined on empty list', function () {
|
||||
const i = ll.getCurrItem();
|
||||
expect(i).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getLength', function() {
|
||||
it('returns the length of the list', function() {
|
||||
describe('#getLength', function () {
|
||||
it('returns the length of the list', function () {
|
||||
ll.insertItem(item);
|
||||
ll.insertItem(item2);
|
||||
const l = ll.getLength();
|
||||
@@ -198,9 +198,9 @@ describe('ol.structs.LinkedList', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#concat', function() {
|
||||
describe('#concat', function () {
|
||||
let ll2, item3;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
item3 = {};
|
||||
ll2 = new LinkedList();
|
||||
ll2.insertItem(item);
|
||||
@@ -208,7 +208,7 @@ describe('ol.structs.LinkedList', function() {
|
||||
ll2.insertItem(item3);
|
||||
});
|
||||
|
||||
it('concatenates a second list with the current one', function() {
|
||||
it('concatenates a second list with the current one', function () {
|
||||
const item4 = {};
|
||||
const item5 = {};
|
||||
const item6 = {};
|
||||
@@ -223,7 +223,7 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.next.next.next.next.data).to.be(item6);
|
||||
});
|
||||
|
||||
it('receives the second list if the current one is empty', function() {
|
||||
it('receives the second list if the current one is empty', function () {
|
||||
ll.concat(ll2);
|
||||
expect(ll.length_).to.be(3);
|
||||
expect(ll.first_.data).to.be(item);
|
||||
@@ -231,7 +231,7 @@ describe('ol.structs.LinkedList', function() {
|
||||
expect(ll.head_.data).to.be(item3);
|
||||
});
|
||||
|
||||
it('destroys the second list', function() {
|
||||
it('destroys the second list', function () {
|
||||
ll.concat(ll2);
|
||||
expect(ll2.length_).to.be(0);
|
||||
expect(ll2.first_).to.be(undefined);
|
||||
@@ -240,21 +240,21 @@ describe('ol.structs.LinkedList', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when circular', function() {
|
||||
beforeEach(function() {
|
||||
describe('when circular', function () {
|
||||
beforeEach(function () {
|
||||
ll = new LinkedList();
|
||||
ll.insertItem(item);
|
||||
});
|
||||
|
||||
describe('#insertItem', function() {
|
||||
it('initializes the list in a circular way', function() {
|
||||
describe('#insertItem', function () {
|
||||
it('initializes the list in a circular way', function () {
|
||||
expect(ll.head_.prev.data).to.be(item);
|
||||
expect(ll.head_.next.data).to.be(item);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#setFirstItem', function() {
|
||||
it('resets the first item to the current one', function() {
|
||||
describe('#setFirstItem', function () {
|
||||
it('resets the first item to the current one', function () {
|
||||
ll.insertItem(item2);
|
||||
ll.setFirstItem();
|
||||
expect(ll.first_.data).to.be(item2);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import LRUCache from '../../../../src/ol/structs/LRUCache.js';
|
||||
|
||||
|
||||
describe('ol.structs.LRUCache', function() {
|
||||
|
||||
describe('ol.structs.LRUCache', function () {
|
||||
let lruCache;
|
||||
|
||||
function fillLRUCache(lruCache) {
|
||||
@@ -12,36 +10,36 @@ describe('ol.structs.LRUCache', function() {
|
||||
lruCache.set('d', 3);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
lruCache = new LRUCache();
|
||||
});
|
||||
|
||||
describe('empty cache', function() {
|
||||
it('has size zero', function() {
|
||||
describe('empty cache', function () {
|
||||
it('has size zero', function () {
|
||||
expect(lruCache.getCount()).to.eql(0);
|
||||
});
|
||||
it('has no keys', function() {
|
||||
it('has no keys', function () {
|
||||
expect(lruCache.getKeys()).to.eql([]);
|
||||
});
|
||||
it('has no values', function() {
|
||||
it('has no values', function () {
|
||||
expect(lruCache.getValues()).to.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('populating', function() {
|
||||
it('returns the correct size', function() {
|
||||
describe('populating', function () {
|
||||
it('returns the correct size', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.getCount()).to.eql(4);
|
||||
});
|
||||
it('contains the correct keys in the correct order', function() {
|
||||
it('contains the correct keys in the correct order', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.getKeys()).to.eql(['d', 'c', 'b', 'a']);
|
||||
});
|
||||
it('contains the correct values in the correct order', function() {
|
||||
it('contains the correct values in the correct order', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.getValues()).to.eql([3, 2, 1, 0]);
|
||||
});
|
||||
it('reports which keys are contained', function() {
|
||||
it('reports which keys are contained', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.containsKey('a')).to.be.ok();
|
||||
expect(lruCache.containsKey('b')).to.be.ok();
|
||||
@@ -51,8 +49,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getting the oldest key', function() {
|
||||
it('moves the key to newest position', function() {
|
||||
describe('getting the oldest key', function () {
|
||||
it('moves the key to newest position', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.get('a');
|
||||
expect(lruCache.getCount()).to.eql(4);
|
||||
@@ -61,8 +59,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getting a key in the middle', function() {
|
||||
it('moves the key to newest position', function() {
|
||||
describe('getting a key in the middle', function () {
|
||||
it('moves the key to newest position', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.get('b');
|
||||
expect(lruCache.getCount()).to.eql(4);
|
||||
@@ -71,8 +69,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getting the newest key', function() {
|
||||
it('maintains the key to newest position', function() {
|
||||
describe('getting the newest key', function () {
|
||||
it('maintains the key to newest position', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.get('d');
|
||||
expect(lruCache.getCount()).to.eql(4);
|
||||
@@ -81,8 +79,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('replacing value of a key', function() {
|
||||
it('moves the key to newest position', function() {
|
||||
describe('replacing value of a key', function () {
|
||||
it('moves the key to newest position', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.replace('b', 4);
|
||||
expect(lruCache.getCount()).to.eql(4);
|
||||
@@ -91,8 +89,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setting a new value', function() {
|
||||
it('adds it as the newest value', function() {
|
||||
describe('setting a new value', function () {
|
||||
it('adds it as the newest value', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.set('e', 4);
|
||||
expect(lruCache.getKeys()).to.eql(['e', 'd', 'c', 'b', 'a']);
|
||||
@@ -100,40 +98,40 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setting an existing value', function() {
|
||||
it('raises an exception', function() {
|
||||
describe('setting an existing value', function () {
|
||||
it('raises an exception', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('a', 0);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('disallowed keys', function() {
|
||||
it('setting raises an exception', function() {
|
||||
expect(function() {
|
||||
describe('disallowed keys', function () {
|
||||
it('setting raises an exception', function () {
|
||||
expect(function () {
|
||||
lruCache.set('constructor', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('hasOwnProperty', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('isPrototypeOf', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('propertyIsEnumerable', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('toLocaleString', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('toString', 0);
|
||||
}).to.throwException();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
lruCache.set('valueOf', 0);
|
||||
}).to.throwException();
|
||||
});
|
||||
it('getting returns false', function() {
|
||||
it('getting returns false', function () {
|
||||
expect(lruCache.containsKey('constructor')).to.not.be();
|
||||
expect(lruCache.containsKey('hasOwnProperty')).to.not.be();
|
||||
expect(lruCache.containsKey('isPrototypeOf')).to.not.be();
|
||||
@@ -144,8 +142,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('popping a value', function() {
|
||||
it('returns the least-recent-used value', function() {
|
||||
describe('popping a value', function () {
|
||||
it('returns the least-recent-used value', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.pop()).to.eql(0);
|
||||
expect(lruCache.getCount()).to.eql(3);
|
||||
@@ -162,8 +160,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#peekFirstKey()', function() {
|
||||
it('returns the newest key in the cache', function() {
|
||||
describe('#peekFirstKey()', function () {
|
||||
it('returns the newest key in the cache', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
@@ -172,46 +170,46 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(cache.peekFirstKey()).to.eql('newest');
|
||||
});
|
||||
|
||||
it('works if the cache has one item', function() {
|
||||
it('works if the cache has one item', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('key', 'value');
|
||||
expect(cache.peekFirstKey()).to.eql('key');
|
||||
});
|
||||
|
||||
it('throws if the cache is empty', function() {
|
||||
it('throws if the cache is empty', function () {
|
||||
const cache = new LRUCache();
|
||||
expect(function() {
|
||||
expect(function () {
|
||||
cache.peekFirstKey();
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('peeking at the last value', function() {
|
||||
it('returns the last key', function() {
|
||||
describe('peeking at the last value', function () {
|
||||
it('returns the last key', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.peekLast()).to.eql(0);
|
||||
});
|
||||
it('throws an exception when the cache is empty', function() {
|
||||
expect(function() {
|
||||
it('throws an exception when the cache is empty', function () {
|
||||
expect(function () {
|
||||
lruCache.peekLast();
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('peeking at the last key', function() {
|
||||
it('returns the last key', function() {
|
||||
describe('peeking at the last key', function () {
|
||||
it('returns the last key', function () {
|
||||
fillLRUCache(lruCache);
|
||||
expect(lruCache.peekLastKey()).to.eql('a');
|
||||
});
|
||||
it('throws an exception when the cache is empty', function() {
|
||||
expect(function() {
|
||||
it('throws an exception when the cache is empty', function () {
|
||||
expect(function () {
|
||||
lruCache.peekLastKey();
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#remove()', function() {
|
||||
it('removes an item from the cache', function() {
|
||||
describe('#remove()', function () {
|
||||
it('removes an item from the cache', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
@@ -223,7 +221,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(cache.getValues()).to.eql(['newest', 'newish', 'oldest']);
|
||||
});
|
||||
|
||||
it('works when removing the oldest item', function() {
|
||||
it('works when removing the oldest item', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
@@ -236,7 +234,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(cache.getValues()).to.eql(['newest', 'newish', 'oldish']);
|
||||
});
|
||||
|
||||
it('works when removing the newest item', function() {
|
||||
it('works when removing the newest item', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('oldest', 'oldest');
|
||||
cache.set('oldish', 'oldish');
|
||||
@@ -249,7 +247,7 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(cache.getValues()).to.eql(['newish', 'oldish', 'oldest']);
|
||||
});
|
||||
|
||||
it('returns the removed item', function() {
|
||||
it('returns the removed item', function () {
|
||||
const cache = new LRUCache();
|
||||
const item = {};
|
||||
cache.set('key', item);
|
||||
@@ -258,20 +256,20 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(returned).to.be(item);
|
||||
});
|
||||
|
||||
it('throws if the key does not exist', function() {
|
||||
it('throws if the key does not exist', function () {
|
||||
const cache = new LRUCache();
|
||||
cache.set('foo', 'foo');
|
||||
cache.set('bar', 'bar');
|
||||
|
||||
const call = function() {
|
||||
const call = function () {
|
||||
cache.remove('bam');
|
||||
};
|
||||
expect(call).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearing the cache', function() {
|
||||
it('clears the cache', function() {
|
||||
describe('clearing the cache', function () {
|
||||
it('clears the cache', function () {
|
||||
fillLRUCache(lruCache);
|
||||
lruCache.clear();
|
||||
expect(lruCache.getCount()).to.eql(0);
|
||||
@@ -280,8 +278,8 @@ describe('ol.structs.LRUCache', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('setting the cache size', function() {
|
||||
it('sets the cache size', function() {
|
||||
describe('setting the cache size', function () {
|
||||
it('sets the cache size', function () {
|
||||
lruCache.setSize(2);
|
||||
expect(lruCache.highWaterMark).to.be(2);
|
||||
fillLRUCache(lruCache);
|
||||
@@ -291,5 +289,4 @@ describe('ol.structs.LRUCache', function() {
|
||||
expect(lruCache.getKeys().length).to.be(2);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
import PriorityQueue, {DROP} from '../../../../src/ol/structs/PriorityQueue.js';
|
||||
|
||||
|
||||
describe('ol.structs.PriorityQueue', function() {
|
||||
|
||||
const identity = function(a) {
|
||||
describe('ol.structs.PriorityQueue', function () {
|
||||
const identity = function (a) {
|
||||
return a;
|
||||
};
|
||||
|
||||
describe('when empty', function() {
|
||||
|
||||
describe('when empty', function () {
|
||||
let pq;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
pq = new PriorityQueue(identity, identity);
|
||||
});
|
||||
|
||||
it('is empty', function() {
|
||||
it('is empty', function () {
|
||||
expect(pq.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
it('enqueue adds an element', function() {
|
||||
it('enqueue adds an element', function () {
|
||||
const added = pq.enqueue(0);
|
||||
expect(added).to.be(true);
|
||||
expect(pq.elements_).to.eql([0]);
|
||||
expect(pq.priorities_).to.eql([0]);
|
||||
});
|
||||
|
||||
it('do not enqueue element with DROP priority', function() {
|
||||
it('do not enqueue element with DROP priority', function () {
|
||||
const added = pq.enqueue(Infinity);
|
||||
expect(added).to.be(false);
|
||||
expect(pq.elements_).to.eql([]);
|
||||
expect(pq.priorities_).to.eql([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('when populated', function() {
|
||||
|
||||
describe('when populated', function () {
|
||||
let elements, pq;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
elements = [];
|
||||
pq = new PriorityQueue(identity, identity);
|
||||
let element, i;
|
||||
@@ -48,7 +43,7 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('dequeues elements in the correct order', function() {
|
||||
it('dequeues elements in the correct order', function () {
|
||||
elements.sort();
|
||||
let i;
|
||||
for (i = 0; i < elements.length; ++i) {
|
||||
@@ -56,15 +51,13 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
}
|
||||
expect(pq.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with an impure priority function', function() {
|
||||
|
||||
describe('with an impure priority function', function () {
|
||||
let pq, target;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
target = 0.5;
|
||||
pq = new PriorityQueue(function(element) {
|
||||
pq = new PriorityQueue(function (element) {
|
||||
return Math.abs(element - target);
|
||||
}, identity);
|
||||
let i;
|
||||
@@ -73,7 +66,7 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('dequeue elements in the correct order', function() {
|
||||
it('dequeue elements in the correct order', function () {
|
||||
let lastDelta = 0;
|
||||
let delta;
|
||||
while (!pq.isEmpty()) {
|
||||
@@ -83,7 +76,7 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('allows reprioritization', function() {
|
||||
it('allows reprioritization', function () {
|
||||
const target = 0.5;
|
||||
pq.reprioritize();
|
||||
let lastDelta = 0;
|
||||
@@ -95,10 +88,10 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('allows dropping during reprioritization', function() {
|
||||
it('allows dropping during reprioritization', function () {
|
||||
const target = 0.5;
|
||||
let i = 0;
|
||||
pq.priorityFunction_ = function(element) {
|
||||
pq.priorityFunction_ = function (element) {
|
||||
if (i++ % 2 === 0) {
|
||||
return Math.abs(element - target);
|
||||
} else {
|
||||
@@ -115,36 +108,34 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
lastDelta = delta;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('tracks elements in the queue', function() {
|
||||
|
||||
describe('tracks elements in the queue', function () {
|
||||
let pq;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
pq = new PriorityQueue(identity, identity);
|
||||
pq.enqueue('a');
|
||||
pq.enqueue('b');
|
||||
pq.enqueue('c');
|
||||
});
|
||||
|
||||
it('tracks which elements have been queued', function() {
|
||||
it('tracks which elements have been queued', function () {
|
||||
expect(pq.isQueued('a')).to.be(true);
|
||||
expect(pq.isQueued('b')).to.be(true);
|
||||
expect(pq.isQueued('c')).to.be(true);
|
||||
});
|
||||
|
||||
it('tracks which elements have not been queued', function() {
|
||||
it('tracks which elements have not been queued', function () {
|
||||
expect(pq.isQueued('d')).to.be(false);
|
||||
});
|
||||
|
||||
it('raises an error when an queued element is re-queued', function() {
|
||||
expect(function() {
|
||||
it('raises an error when an queued element is re-queued', function () {
|
||||
expect(function () {
|
||||
pq.enqueue('a');
|
||||
}).to.throwException();
|
||||
});
|
||||
|
||||
it('tracks which elements have be dequeued', function() {
|
||||
it('tracks which elements have be dequeued', function () {
|
||||
expect(pq.isQueued('a')).to.be(true);
|
||||
expect(pq.isQueued('b')).to.be(true);
|
||||
expect(pq.isQueued('c')).to.be(true);
|
||||
@@ -161,7 +152,5 @@ describe('ol.structs.PriorityQueue', function() {
|
||||
expect(pq.isQueued('b')).to.be(false);
|
||||
expect(pq.isQueued('c')).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,42 +1,33 @@
|
||||
import RBush from '../../../../src/ol/structs/RBush.js';
|
||||
|
||||
|
||||
describe('ol.structs.RBush', function() {
|
||||
|
||||
describe('ol.structs.RBush', function () {
|
||||
let rBush;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
rBush = new RBush();
|
||||
});
|
||||
|
||||
describe('when empty', function() {
|
||||
|
||||
describe('#getAll', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('when empty', function () {
|
||||
describe('#getAll', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getAll()).to.be.empty();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns true', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns true', function () {
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a single object', function() {
|
||||
|
||||
describe('with a single object', function () {
|
||||
let obj;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
obj = {};
|
||||
rBush.insert([0, 0, 1, 1], obj);
|
||||
});
|
||||
|
||||
it('can update the object', function() {
|
||||
it('can update the object', function () {
|
||||
expect(rBush.getInExtent([0, 0, 1, 1])).to.eql([obj]);
|
||||
rBush.update([2, 2, 3, 3], obj);
|
||||
expect(rBush.getInExtent([0, 0, 1, 1])).to.be.empty();
|
||||
@@ -44,20 +35,18 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getInExtent([2, 2, 3, 3])).to.eql([obj]);
|
||||
});
|
||||
|
||||
it('don\'t throws an exception if the extent is not modified', function() {
|
||||
expect(function() {
|
||||
rBush.forEach(function(value) {
|
||||
it("don't throws an exception if the extent is not modified", function () {
|
||||
expect(function () {
|
||||
rBush.forEach(function (value) {
|
||||
rBush.update([0, 0, 1, 1], obj);
|
||||
});
|
||||
}).not.to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with a few objects', function() {
|
||||
|
||||
describe('with a few objects', function () {
|
||||
let objs;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
objs = [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}];
|
||||
rBush.insert([0, 0, 1, 1], objs[0]);
|
||||
rBush.insert([1, 1, 4, 4], objs[1]);
|
||||
@@ -72,30 +61,27 @@ describe('ol.structs.RBush', function() {
|
||||
rBush.insert([-3, -3, -2, -2], objs[10]);
|
||||
});
|
||||
|
||||
describe('#forEach', function() {
|
||||
|
||||
it('called for all the objects', function() {
|
||||
describe('#forEach', function () {
|
||||
it('called for all the objects', function () {
|
||||
let i = 0;
|
||||
rBush.forEach(function() {
|
||||
rBush.forEach(function () {
|
||||
++i;
|
||||
});
|
||||
expect(i).to.be(objs.length);
|
||||
});
|
||||
|
||||
it('stops when the function returns true', function() {
|
||||
it('stops when the function returns true', function () {
|
||||
let i = 0;
|
||||
const result = rBush.forEach(function() {
|
||||
const result = rBush.forEach(function () {
|
||||
return ++i >= 4;
|
||||
});
|
||||
expect(i).to.be(4);
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected objects', function () {
|
||||
let result;
|
||||
result = rBush.getInExtent([2, 2, 3, 3]);
|
||||
expect(result).to.contain(objs[1]);
|
||||
@@ -109,23 +95,19 @@ describe('ol.structs.RBush', function() {
|
||||
expect(result.length).to.be(4);
|
||||
});
|
||||
|
||||
it('returns an empty array when given a disjoint extent', function() {
|
||||
it('returns an empty array when given a disjoint extent', function () {
|
||||
expect(rBush.getInExtent([5, 5, 6, 6]).length).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove each object', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove each object', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getAll()).to.contain(objs[i]);
|
||||
@@ -133,15 +115,12 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll()).not.to.contain(objs[i]);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with 100 objects', function() {
|
||||
|
||||
describe('with 100 objects', function () {
|
||||
let extents, objs;
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
extents = [];
|
||||
objs = [];
|
||||
let i;
|
||||
@@ -152,28 +131,23 @@ describe('ol.structs.RBush', function() {
|
||||
}
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected objects', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove each object in turn', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove each object in turn', function () {
|
||||
let i, ii;
|
||||
for (i = 0, ii = objs.length; i < ii; ++i) {
|
||||
expect(rBush.getInExtent(extents[i])).to.eql([objs[i]]);
|
||||
@@ -184,7 +158,7 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
it('can remove objects in random order', function() {
|
||||
it('can remove objects in random order', function () {
|
||||
let i, ii, j;
|
||||
// http://en.wikipedia.org/wiki/Random_permutation
|
||||
const indexes = [];
|
||||
@@ -202,45 +176,42 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll()).to.be.empty();
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('with 1000 objects', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
describe('with 1000 objects', function () {
|
||||
beforeEach(function () {
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
rBush.insert(extent, {id: i});
|
||||
}
|
||||
});
|
||||
|
||||
describe('#getAll', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('#getAll', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getAll().length).to.be(1000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getInExtent', function() {
|
||||
|
||||
it('returns the expected number of objects', function() {
|
||||
describe('#getInExtent', function () {
|
||||
it('returns the expected number of objects', function () {
|
||||
expect(rBush.getInExtent([0, 0, 10600, 10600]).length).to.be(1000);
|
||||
});
|
||||
|
||||
it('can perform 1000 in-extent searches', function() {
|
||||
it('can perform 1000 in-extent searches', function () {
|
||||
let n = 0;
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
n += rBush.getInExtent(extent).length;
|
||||
@@ -248,46 +219,49 @@ describe('ol.structs.RBush', function() {
|
||||
expect(n).not.to.be(0);
|
||||
});
|
||||
|
||||
it('can perform 1000 out-of-extent searches', function() {
|
||||
it('can perform 1000 out-of-extent searches', function () {
|
||||
let n = 0;
|
||||
let i;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
const min = [-(Math.random() * 10000 + 501), -(Math.random() * 10000 + 501)];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const min = [
|
||||
-(Math.random() * 10000 + 501),
|
||||
-(Math.random() * 10000 + 501),
|
||||
];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
n += rBush.getInExtent(extent).length;
|
||||
}
|
||||
expect(n).to.be(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#insert', function() {
|
||||
|
||||
it('can insert another 1000 objects', function() {
|
||||
describe('#insert', function () {
|
||||
it('can insert another 1000 objects', function () {
|
||||
let i;
|
||||
for (i = 1000; i < 2000; ++i) {
|
||||
const min = [Math.random() * 10000, Math.random() * 10000];
|
||||
const max = [min[0] + Math.random() * 500, min[1] + Math.random() * 500];
|
||||
const max = [
|
||||
min[0] + Math.random() * 500,
|
||||
min[1] + Math.random() * 500,
|
||||
];
|
||||
const extent = [min[0], min[1], max[0], max[1]];
|
||||
rBush.insert(extent, {id: i});
|
||||
}
|
||||
expect(rBush.getInExtent([0, 0, 10600, 10600]).length).to.be(2000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#isEmpty', function() {
|
||||
|
||||
it('returns false', function() {
|
||||
describe('#isEmpty', function () {
|
||||
it('returns false', function () {
|
||||
expect(rBush.isEmpty()).to.be(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#remove', function() {
|
||||
|
||||
it('can remove all 1000 objects', function() {
|
||||
describe('#remove', function () {
|
||||
it('can remove all 1000 objects', function () {
|
||||
const objs = rBush.getAll();
|
||||
let i, value;
|
||||
for (i = objs.length - 1; i >= 0; --i) {
|
||||
@@ -296,24 +270,19 @@ describe('ol.structs.RBush', function() {
|
||||
}
|
||||
expect(rBush.isEmpty()).to.be(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getExtent', function() {
|
||||
|
||||
it('gets the extent', function() {
|
||||
describe('#getExtent', function () {
|
||||
it('gets the extent', function () {
|
||||
const obj = {};
|
||||
rBush.insert([0, 0, 1, 1], obj);
|
||||
expect(rBush.getExtent()).to.eql([0, 0, 1, 1]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#concat', function() {
|
||||
|
||||
it('concatenates two RBush objects', function() {
|
||||
describe('#concat', function () {
|
||||
it('concatenates two RBush objects', function () {
|
||||
const obj1 = {};
|
||||
const obj2 = {};
|
||||
const rBush2 = new RBush();
|
||||
@@ -324,7 +293,7 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getAll().length).to.be(2);
|
||||
});
|
||||
|
||||
it('preserves the concatenated object\'s references', function() {
|
||||
it("preserves the concatenated object's references", function () {
|
||||
const obj1 = {};
|
||||
const obj2 = {};
|
||||
const rBush2 = new RBush();
|
||||
@@ -335,5 +304,4 @@ describe('ol.structs.RBush', function() {
|
||||
expect(rBush.getExtent()).to.eql([0, 0, 3, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user