|
|
@@ -8,15 +8,13 @@ const Range = require('../lib/range')
|
|
|
|
|
|
describe('commentList', function () {
|
|
|
it('checks if toRaw() returns a correct comment list', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)])],
|
|
|
- ['comm2', new Comment([new Range(20, 5)])],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)]),
|
|
|
+ new Comment('comm2', [new Range(20, 5)]),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ ])
|
|
|
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 5 }], resolved: false },
|
|
|
{
|
|
|
@@ -28,16 +26,15 @@ describe('commentList', function () {
|
|
|
})
|
|
|
|
|
|
it('should get a comment by id', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)])],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ['comm2', new Comment([new Range(20, 5)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)]),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ new Comment('comm2', [new Range(20, 5)]),
|
|
|
+ ])
|
|
|
|
|
|
const comment = commentList.getComment('comm2')
|
|
|
expect(comment?.toRaw()).to.eql({
|
|
|
+ id: 'comm2',
|
|
|
ranges: [
|
|
|
{
|
|
|
pos: 20,
|
|
|
@@ -49,16 +46,14 @@ describe('commentList', function () {
|
|
|
})
|
|
|
|
|
|
it('should add new comment to the list', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)])],
|
|
|
- ['comm2', new Comment([new Range(20, 5)])],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)]),
|
|
|
+ new Comment('comm2', [new Range(20, 5)]),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ ])
|
|
|
|
|
|
- commentList.add('comm4', new Comment([new Range(40, 10)]))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ commentList.add(new Comment('comm4', [new Range(40, 10)]))
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 5 }], resolved: false },
|
|
|
{
|
|
|
@@ -75,18 +70,16 @@ describe('commentList', function () {
|
|
|
})
|
|
|
|
|
|
it('should overwrite existing comment if new one is added', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)], false)],
|
|
|
- ['comm2', new Comment([new Range(20, 5)], true)],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)], false),
|
|
|
+ new Comment('comm2', [new Range(20, 5)], true),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ ])
|
|
|
|
|
|
- commentList.add('comm1', new Comment([new Range(5, 10)], true))
|
|
|
- commentList.add('comm2', new Comment([new Range(40, 10)], true))
|
|
|
+ commentList.add(new Comment('comm1', [new Range(5, 10)], true))
|
|
|
+ commentList.add(new Comment('comm2', [new Range(40, 10)], true))
|
|
|
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: true },
|
|
|
{
|
|
|
id: 'comm2',
|
|
|
@@ -102,33 +95,29 @@ describe('commentList', function () {
|
|
|
})
|
|
|
|
|
|
it('should delete a comment from the list', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)])],
|
|
|
- ['comm2', new Comment([new Range(20, 5)])],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)]),
|
|
|
+ new Comment('comm2', [new Range(20, 5)]),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ ])
|
|
|
|
|
|
commentList.delete('comm3')
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 5 }], resolved: false },
|
|
|
])
|
|
|
})
|
|
|
|
|
|
it('should not throw an error if comment id does not exist', function () {
|
|
|
- const commentList = new CommentList(
|
|
|
- new Map([
|
|
|
- ['comm1', new Comment([new Range(5, 10)])],
|
|
|
- ['comm2', new Comment([new Range(20, 5)])],
|
|
|
- ['comm3', new Comment([new Range(30, 15)])],
|
|
|
- ])
|
|
|
- )
|
|
|
+ const commentList = new CommentList([
|
|
|
+ new Comment('comm1', [new Range(5, 10)]),
|
|
|
+ new Comment('comm2', [new Range(20, 5)]),
|
|
|
+ new Comment('comm3', [new Range(30, 15)]),
|
|
|
+ ])
|
|
|
|
|
|
commentList.delete('comm5')
|
|
|
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 5 }], resolved: false },
|
|
|
{
|
|
|
@@ -153,7 +142,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(15, 5), { commentIds: ['comm1'] })
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 15 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 10 }], resolved: false },
|
|
|
])
|
|
|
@@ -172,7 +161,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(15, 5), { commentIds: ['comm2'] })
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 15, length: 15 }], resolved: false },
|
|
|
])
|
|
|
@@ -192,7 +181,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyDelete(new Range(10, 10)) // 10-19
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 5 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 10, length: 5 }], resolved: false },
|
|
|
])
|
|
|
@@ -216,7 +205,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(7, 5), { commentIds: ['comm1'] })
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 15 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 25, length: 5 }], resolved: false },
|
|
|
{ id: 'comm3', ranges: [{ pos: 35, length: 15 }], resolved: false },
|
|
|
@@ -240,7 +229,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(7, 5), { commentIds: ['comm2'] })
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{
|
|
|
id: 'comm1',
|
|
|
ranges: [
|
|
|
@@ -280,7 +269,7 @@ describe('commentList', function () {
|
|
|
commentList.applyInsert(new Range(7, 5), {
|
|
|
commentIds: ['comm1', 'comm2'],
|
|
|
})
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{
|
|
|
id: 'comm1',
|
|
|
ranges: [{ pos: 5, length: 20 }],
|
|
|
@@ -315,7 +304,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(16, 5))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 25, length: 5 }], resolved: false },
|
|
|
{ id: 'comm3', ranges: [{ pos: 35, length: 15 }], resolved: false },
|
|
|
@@ -339,7 +328,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyInsert(new Range(50, 5))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 20, length: 5 }], resolved: false },
|
|
|
{ id: 'comm3', ranges: [{ pos: 30, length: 15 }], resolved: false },
|
|
|
@@ -363,7 +352,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyDelete(new Range(0, 4))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 1, length: 10 }], resolved: false },
|
|
|
{ id: 'comm2', ranges: [{ pos: 16, length: 5 }], resolved: false },
|
|
|
{ id: 'comm3', ranges: [{ pos: 26, length: 15 }], resolved: false },
|
|
|
@@ -380,7 +369,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyDelete(new Range(0, 6))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 0, length: 9 }], resolved: false },
|
|
|
])
|
|
|
})
|
|
|
@@ -393,7 +382,7 @@ describe('commentList', function () {
|
|
|
},
|
|
|
])
|
|
|
commentList.applyDelete(new Range(7, 10))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 2 }], resolved: false },
|
|
|
])
|
|
|
})
|
|
|
@@ -406,7 +395,7 @@ describe('commentList', function () {
|
|
|
},
|
|
|
])
|
|
|
commentList.applyDelete(new Range(6, 2))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{ id: 'comm1', ranges: [{ pos: 5, length: 8 }], resolved: false },
|
|
|
])
|
|
|
})
|
|
|
@@ -429,7 +418,7 @@ describe('commentList', function () {
|
|
|
])
|
|
|
|
|
|
commentList.applyDelete(new Range(19, 10))
|
|
|
- expect(commentList.getComments()).to.eql([
|
|
|
+ expect(commentList.toRaw()).to.eql([
|
|
|
{
|
|
|
id: 'comm1',
|
|
|
ranges: [{ pos: 5, length: 10 }],
|