mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #17931 from overleaf/em-invalid-ranges
Throw error when constructing invalid ranges GitOrigin-RevId: 9451e0f8d35372610d08530048e7ee2ca1ff2052
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
// @ts-check
|
||||
|
||||
const OError = require('@overleaf/o-error')
|
||||
|
||||
class Range {
|
||||
/**
|
||||
* @param {number} pos
|
||||
* @param {number} length
|
||||
*/
|
||||
constructor(pos, length) {
|
||||
if (pos < 0 || length < 0) {
|
||||
throw new OError('Invalid range', { pos, length })
|
||||
}
|
||||
/** @readonly */
|
||||
this.pos = pos
|
||||
/** @readonly */
|
||||
|
||||
@@ -30,6 +30,14 @@ describe('Range', function () {
|
||||
expect(range0length.isEmpty()).to.be.true
|
||||
})
|
||||
|
||||
it('should not create a range with a negative position', function () {
|
||||
expect(() => new Range(-1, 10)).to.throw
|
||||
})
|
||||
|
||||
it('should not create a range with a negative length', function () {
|
||||
expect(() => new Range(0, -2)).to.throw
|
||||
})
|
||||
|
||||
describe('overlaps', function () {
|
||||
it('same ranges should overlap', function () {
|
||||
const range1 = new Range(1, 3)
|
||||
|
||||
Reference in New Issue
Block a user