From 466427bb82a9517c53d675665129c14e4e282fff Mon Sep 17 00:00:00 2001 From: Fei Chen Date: Wed, 14 Oct 2020 16:57:54 +0800 Subject: [PATCH 1/3] fix bug --- .../lu/src/parser/lufile/sectionOperator.js | 6 ++--- .../lu/test/parser/lufile/sectionapi.test.js | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/lu/src/parser/lufile/sectionOperator.js b/packages/lu/src/parser/lufile/sectionOperator.js index 72cc0570c..acfd872d1 100644 --- a/packages/lu/src/parser/lufile/sectionOperator.js +++ b/packages/lu/src/parser/lufile/sectionOperator.js @@ -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); } @@ -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); } }); diff --git a/packages/lu/test/parser/lufile/sectionapi.test.js b/packages/lu/test/parser/lufile/sectionapi.test.js index dd1bf4f8c..5668dbd9d 100644 --- a/packages/lu/test/parser/lufile/sectionapi.test.js +++ b/packages/lu/test/parser/lufile/sectionapi.test.js @@ -497,6 +497,32 @@ 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', () => { From 4de065f9efef63946c5280c35d425d36e52b8294 Mon Sep 17 00:00:00 2001 From: Fei Chen Date: Wed, 14 Oct 2020 17:20:41 +0800 Subject: [PATCH 2/3] add newline for test case --- packages/lu/test/parser/lufile/sectionapi.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/lu/test/parser/lufile/sectionapi.test.js b/packages/lu/test/parser/lufile/sectionapi.test.js index 5668dbd9d..96e8fbc2d 100644 --- a/packages/lu/test/parser/lufile/sectionapi.test.js +++ b/packages/lu/test/parser/lufile/sectionapi.test.js @@ -498,11 +498,12 @@ describe('Section range tests', () => { assert.equal(luresource.Sections[1].Range.End.Character, 7) }); - it('simple intent section with errors test', () => { + it.only('simple intent section with errors test', () => { let fileContent = `#WhoAreYou - my name is {@userName=luhan} -@ prebuilt personName hasRoles`; +@ prebuilt personName hasRoles +`; let updatedContent = `#WhoAreYou From 3af9e9d803a752ef6ea5893578966521f91bcbd4 Mon Sep 17 00:00:00 2001 From: Fei Chen Date: Wed, 14 Oct 2020 17:21:13 +0800 Subject: [PATCH 3/3] remove only --- packages/lu/test/parser/lufile/sectionapi.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lu/test/parser/lufile/sectionapi.test.js b/packages/lu/test/parser/lufile/sectionapi.test.js index 96e8fbc2d..d1df76781 100644 --- a/packages/lu/test/parser/lufile/sectionapi.test.js +++ b/packages/lu/test/parser/lufile/sectionapi.test.js @@ -498,7 +498,7 @@ describe('Section range tests', () => { assert.equal(luresource.Sections[1].Range.End.Character, 7) }); - it.only('simple intent section with errors test', () => { + it('simple intent section with errors test', () => { let fileContent = `#WhoAreYou - my name is {@userName=luhan}