Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions packages/lu/src/parser/lufile/luParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class LUParser {

const destList = originList.slice(startLine + 1, stopLine)
section.Body = destList.join(NEWLINE)
section.StartLine = startLine
section.StopLine = stopLine - 1

if (section.SectionType === SectionType.NESTEDINTENTSECTION) {
LUParser.extractIntentBody(section.SimpleIntentSections, originList.slice(0, stopLine).join(NEWLINE))
Expand Down
10 changes: 5 additions & 5 deletions packages/lu/src/parser/lufile/sectionOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SectionOperator {
return this.Luresource;
}

var startLine = section.ParseTree.start.line - 1;
var stopLine = section.ParseTree.stop.line - 1;
var startLine = section.StartLine;
var stopLine = section.StopLine;

var newContent = this.replaceRangeContent(this.Luresource.Content, startLine, stopLine, sectionContent);

Expand All @@ -41,8 +41,8 @@ class SectionOperator {
return this;
}

var startLine = section.ParseTree.start.line - 1;
var stopLine = section.ParseTree.stop.line - 1;
var startLine = section.StartLine;
var stopLine = section.StopLine;

var newContent = this.replaceRangeContent(this.Luresource.Content, startLine, stopLine, undefined);

Expand All @@ -57,7 +57,7 @@ class SectionOperator {

const originList = originString.split(/\r?\n/);
let destList = [];
if (isNaN(startLine) || isNaN(stopLine) || startLine < 0 || startLine > stopLine || originList.Length <= stopLine) {
if (isNaN(startLine) || isNaN(stopLine) || startLine < 0 || startLine > stopLine || originList.length <= stopLine) {
throw new Error("index out of range.");
}

Expand Down
14 changes: 10 additions & 4 deletions packages/lu/test/parser/lufile/sectionapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('Section CRUD test', () => {
let newFileConent =
`# CheckEmail
- check my email
- show my emails`;
- show my emails

> this is comment when adding simpleIntentSection`;

luresource = new SectionOperator(luresource).addSection(newFileConent);

Expand All @@ -55,11 +57,12 @@ describe('Section CRUD test', () => {
`# CheckEmail
- check my email
- show my emails
- check my mail box please`;
- check my mail box please

> this is comment when updating simpleIntentSection`;

let sectionId = luresource.Sections[1].Id;
luresource = new SectionOperator(luresource).updateSection(luresource.Sections[1].Id, newFileConent);

assert.equal(luresource.Errors.length, 0);
assert.equal(luresource.Sections.length, 2);
assert.equal(luresource.Sections[1].Errors.length, 0);
Expand All @@ -70,9 +73,10 @@ describe('Section CRUD test', () => {
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[0].utterance, 'check my email');
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[1].utterance, 'show my emails');
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[2].utterance, 'check my mail box please');
assert.isTrue(luresource.Sections[1].Body.includes('> this is comment when updating simpleIntentSection'));
assert.isFalse(luresource.Sections[1].Body.includes('> this is comment when adding simpleIntentSection'));
});


it('delete section test', () => {
luresource = new SectionOperator(luresource).deleteSection(luresource.Sections[1].Id);

Expand All @@ -81,6 +85,8 @@ describe('Section CRUD test', () => {
assert.equal(luresource.Sections[0].Errors.length, 0);
assert.equal(luresource.Sections[0].SectionType, LUSectionTypes.SIMPLEINTENTSECTION);
assert.equal(luresource.Sections[0].Name, 'Greeting');
assert.isFalse(luresource.Sections[0].Body.includes('> this is comment when adding simpleIntentSection'));
assert.isFalse(luresource.Sections[0].Body.includes('> this is comment when updating simpleIntentSection'));
});

it('add nestedIntentSection test with enableSections flag unset', () => {
Expand Down