mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #17931 from overleaf/em-invalid-ranges
Throw error when constructing invalid ranges GitOrigin-RevId: 9451e0f8d35372610d08530048e7ee2ca1ff2052
This commit is contained in:
parent
b8195f537d
commit
0e54a1078f
2 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue