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
3 changes: 3 additions & 0 deletions packages/lu/src/parser/lufile/luParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ class LUParser {
if (section.SectionType === SectionType.NESTEDINTENTSECTION) {
LUParser.extractIntentBody(section.SimpleIntentSections, originList.slice(0, stopLine).join(NEWLINE))
}
} else {
section.StartLine = section.ParseTree.start.line
section.StopLine = section.ParseTree.stop.line - 1
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions packages/lu/src/parser/lufile/sectionOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class SectionOperator {
return this.Luresource;
}

var startLine = section.StartLine;
var stopLine = section.StopLine;
const startLine = section.StartLine;
const stopLine = section.StopLine;

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

return luParser.parse(newContent);
}
Expand All @@ -41,10 +41,10 @@ class SectionOperator {
return this;
}

var startLine = section.StartLine;
var stopLine = section.StopLine;
const startLine = section.StartLine;
const stopLine = section.StopLine;

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

return luParser.parse(newContent);
}
Expand Down
60 changes: 59 additions & 1 deletion packages/lu/test/parser/lufile/sectionapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const SectionOperator = require('./../../../src/parser/lufile/sectionOperator');
const LUSectionTypes = require('./../../../src/parser/utils/enums/lusectiontypes');
const NEWLINE = require('os').EOL;

describe('Section CRUD test', () => {
describe('Section CRUD tests for intent', () => {
let luresource = undefined;

it('init section test', () => {
Expand Down Expand Up @@ -211,4 +211,62 @@ describe('Section CRUD test', () => {
assert.equal(luresource.Sections[4].SimpleIntentSections[1].Body, simpleIntentBody2);
assert.equal(luresource.Sections[4].Body, nestedIntentBody);
});
});

describe('Section CRUD tests for entity', () => {
let luresource = undefined;

it('init section test', () => {
let fileContent =
`@ list BreadEntity =
- multiGrainWheat:
- multi
- rye:
- rye

# Greeting
- hi`;

luresource = luparser.parse(fileContent);

assert.equal(luresource.Errors.length, 0);
assert.equal(luresource.Sections.length, 2);
assert.equal(luresource.Sections[0].SectionType, LUSectionTypes.NEWENTITYSECTION);
assert.equal(luresource.Sections[0].Name, 'BreadEntity');
assert.equal(luresource.Sections[0].Type, 'list');
assert.equal(luresource.Sections[0].ListBody.length, 4);
assert.equal(luresource.Sections[0].ListBody[0], ' - multiGrainWheat:');
assert.equal(luresource.Sections[0].ListBody[1], ' - multi');
assert.equal(luresource.Sections[0].ListBody[2], ' - rye:');
assert.equal(luresource.Sections[0].ListBody[3], ' - rye');
assert.equal(luresource.Sections[1].SectionType, LUSectionTypes.SIMPLEINTENTSECTION);
assert.equal(luresource.Sections[1].Name, 'Greeting');
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap.length, 1);
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[0].utterance, 'hi');
});

it('update entity section test', () => {
let newFileConent =
` - multiGrainWheat:
- multi grain
- white:
- white`;

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

assert.equal(luresource.Errors.length, 0);
assert.equal(luresource.Sections.length, 2);
assert.equal(luresource.Sections[0].SectionType, LUSectionTypes.NEWENTITYSECTION);
assert.equal(luresource.Sections[0].Name, 'BreadEntity');
assert.equal(luresource.Sections[0].Type, 'list');
assert.equal(luresource.Sections[0].ListBody.length, 4);
assert.equal(luresource.Sections[0].ListBody[0], ' - multiGrainWheat:');
assert.equal(luresource.Sections[0].ListBody[1], ' - multi grain');
assert.equal(luresource.Sections[0].ListBody[2], ' - white:');
assert.equal(luresource.Sections[0].ListBody[3], ' - white');
assert.equal(luresource.Sections[1].SectionType, LUSectionTypes.SIMPLEINTENTSECTION);
assert.equal(luresource.Sections[1].Name, 'Greeting');
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap.length, 1);
assert.equal(luresource.Sections[1].UtteranceAndEntitiesMap[0].utterance, 'hi');
});
});