skiplist: Sanity check inserted entries
parent
9e2ef6ad5b
commit
e2eb7327c2
|
@ -95,6 +95,11 @@ class Point {
|
|||
}
|
||||
|
||||
insert(entry) {
|
||||
if (entry.key == null) throw new Error('entry.key must not be null');
|
||||
if (this._skipList.containsKey(entry.key)) {
|
||||
throw new Error(`an entry with key ${entry.key} already exists`);
|
||||
}
|
||||
|
||||
const newNode = new Node(entry);
|
||||
const pNodes = this.nodes;
|
||||
const pIdxs = this.idxs;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<div id="mocha"></div>
|
||||
<div id="iframe-container"></div>
|
||||
|
||||
<script src="/static/js/require-kernel.js"></script>
|
||||
<script src="/static/js/vendors/jquery.js"></script>
|
||||
<script src="/static/js/vendors/browser.js"></script>
|
||||
<script src="/static/plugins/js-cookie/src/js.cookie.js"></script>
|
||||
|
|
|
@ -159,6 +159,11 @@ $(() => {
|
|||
// get the list of specs and filter it if requested
|
||||
const specs = specs_list.slice();
|
||||
|
||||
const absUrl = (url) => new URL(url, window.location.href).href;
|
||||
require.setRootURI(absUrl('../../javascripts/src'));
|
||||
require.setLibraryURI(absUrl('../../javascripts/lib'));
|
||||
require.setGlobalKeyPath('require');
|
||||
|
||||
// inject spec scripts into the dom
|
||||
const $body = $('body');
|
||||
$.each(specs, (i, spec) => {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
'use strict';
|
||||
|
||||
const SkipList = require('ep_etherpad-lite/static/js/skiplist');
|
||||
|
||||
describe('skiplist.js', function () {
|
||||
it('rejects null keys', async function () {
|
||||
const skiplist = new SkipList();
|
||||
for (const key of [undefined, null]) {
|
||||
expect(() => skiplist.push({key})).to.throwError();
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects duplicate keys', async function () {
|
||||
const skiplist = new SkipList();
|
||||
skiplist.push({key: 'foo'});
|
||||
expect(() => skiplist.push({key: 'foo'})).to.throwError();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue