Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Fix update section bug when there are errors #1017

Merged
merged 4 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/lu/src/parser/lufile/sectionOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class SectionOperator {
let index = -1;

while ((index = errors.findIndex(u =>
u.Range && ((u.Range.Start.Line >= startLine && u.Range.Start.Line <= endLine)
!u.Range || ((u.Range.Start.Line >= startLine && u.Range.Start.Line <= endLine)
|| (u.Range.End.Line >= startLine && u.Range.End.Line <= endLine)))) >= 0) {
this.Luresource.Errors.splice(index, 1);
}
Expand All @@ -156,13 +156,13 @@ class SectionOperator {
});
} else if (startLine >= 0 && (endLine === undefined || endLine < startLine)) {
errors.forEach(u => {
if (u.Range.Start.Line >= startLine) {
if (u.Range && u.Range.Start.Line >= startLine) {
this.adjustErrorRange(u, offset);
}
});
} else if (startLine >= 0 && endLine >= startLine) {
errors.forEach(u => {
if (u.Range.Start.Line >= startLine && u.Range.End.Line <= endLine) {
if (u.Range && u.Range.Start.Line >= startLine && u.Range.End.Line <= endLine) {
this.adjustErrorRange(u, offset);
}
});
Expand Down
27 changes: 27 additions & 0 deletions packages/lu/test/parser/lufile/sectionapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,33 @@ describe('Section range tests', () => {
assert.equal(luresource.Sections[1].Range.End.Line, 11)
assert.equal(luresource.Sections[1].Range.End.Character, 7)
});

it('simple intent section with errors test', () => {
let fileContent =
`#WhoAreYou
- my name is {@userName=luhan}
@ prebuilt personName hasRoles
`;

let updatedContent =
`#WhoAreYou
- my name is {@userName=luhan}
@ prebuilt personName hasRoles userName`;

let luresource = luparser.parse(fileContent);

assert.equal(luresource.Errors.length, 2);
assert.equal(luresource.Sections.length, 1);
assert.equal(luresource.Content.replace(/\r\n/g, "\n"), `${fileContent}`);
assert.equal(`#WhoAreYou${NEWLINE}${luresource.Sections[0].Body}`.replace(/\r\n/g, "\n"), fileContent);

luresource = new SectionOperator(luresource).updateSection(luresource.Sections[0].Id, updatedContent);

assert.equal(luresource.Errors.length, 0);
assert.equal(luresource.Sections.length, 1);
assert.equal(luresource.Content.replace(/\r\n/g, "\n"), updatedContent);
assert.equal(`#WhoAreYou${NEWLINE}${luresource.Sections[0].Body}`.replace(/\r\n/g, "\n"), updatedContent);
});
})

describe('Section CRUD tests for insert and update sections with newline', () => {
Expand Down