From 8545c0813cb93cbdf68e9e24938de9e6bd6486de Mon Sep 17 00:00:00 2001 From: JhontSouth Date: Mon, 4 Nov 2024 08:45:08 -0500 Subject: [PATCH 1/3] add PVA unit tests --- .../Fixtures/testLUPVA1.json | 51 ++++++++ .../Fixtures/testLUPVA1.txt | 5 + .../Fixtures/testLUPVA2.json | 26 ++++ .../Fixtures/testLUPVA2.txt | 1 + .../Fixtures/testLUPVA3.json | 44 +++++++ .../Fixtures/testLUPVA3.txt | 2 + .../Fixtures/testLUPVA4.json | 23 ++++ .../Fixtures/testLUPVA4.txt | 2 + ...rosoft.Bot.Builder.Parsers.LU.Tests.csproj | 36 +++++- .../Parser/LuParserTests.cs | 114 +++++++++++++++++- 10 files changed, 296 insertions(+), 8 deletions(-) create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json new file mode 100644 index 0000000000..294b7d07f6 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json @@ -0,0 +1,51 @@ +{ + "sections": [ + { + "Errors": [], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_getUserName", + "Body": " - my name is {username=vishwac}\r\n\r\n > Without an explicit entity definition, 'userName' defaults to 'ml' entity type\r\n", + "UtteranceAndEntitiesMap": [ + { + "utterance": "my name is vishwac", + "entities": [ + { + "type": "Entities", + "entity": "username", + "role": "", + "startPos": 11, + "endPos": 17 + } + ], + "errorMsgs": [], + "contextText": "- my name is {username=vishwac}", + "range": { + "Start": { + "Line": 3, + "Character": 4 + }, + "End": { + "Line": 3, + "Character": 35 + } + } + } + ], + "Entities": [], + "Name": "getUserName", + "IntentNameLine": "# getUserName", + "Range": { + "Start": { + "Line": 2, + "Character": 0 + }, + "End": { + "Line": 6, + "Character": 0 + } + } + } + ], + "content": "\n # getUserName\n - my name is {username=vishwac}\n\n > Without an explicit entity definition, 'userName' defaults to 'ml' entity type\n", + "errors": [] +} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt new file mode 100644 index 0000000000..5cba289b30 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt @@ -0,0 +1,5 @@ + + # getUserName + - my name is {username=vishwac} + + > Without an explicit entity definition, 'userName' defaults to 'ml' entity type diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json new file mode 100644 index 0000000000..0e11311c31 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json @@ -0,0 +1,26 @@ +{ + "sections": [ + { + "Errors": [], + "SectionType": "NewEntitySection", + "Id": "newEntitySection_number", + "Body": "", + "Name": "number", + "Range": { + "Start": { + "Line": 1, + "Character": 0 + }, + "End": { + "Line": 1, + "Character": 34 + } + }, + "Type": "prebuilt", + "ListBody": [], + "Roles": "numOfGuests, age" + } + ], + "content": "@ prebuilt number numOfGuests, age", + "errors": [] +} diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt new file mode 100644 index 0000000000..b42d8a6b00 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt @@ -0,0 +1 @@ +@ prebuilt number numOfGuests, age \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json new file mode 100644 index 0000000000..65e4e81718 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json @@ -0,0 +1,44 @@ +{ + "sections": [ + { + "Errors": [], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_None", + "Body": "- [None uttearnces](./all.lu#Help)", + "UtteranceAndEntitiesMap": [ + { + "utterance": "[None uttearnces](./all.lu#Help)", + "entities": [], + "errorMsgs": [], + "contextText": "- [None uttearnces](./all.lu#Help)", + "range": { + "Start": { + "Line": 2, + "Character": 0 + }, + "End": { + "Line": 2, + "Character": 34 + } + }, + "references": { "source": "./all.lu#Help" } + } + ], + "Entities": [], + "Name": "None", + "IntentNameLine": "# None", + "Range": { + "Start": { + "Line": 1, + "Character": 0 + }, + "End": { + "Line": 2, + "Character": 34 + } + } + } + ], + "content": "# None\n- [None uttearnces](./all.lu#Help)", + "errors": [] +} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt new file mode 100644 index 0000000000..b922782957 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt @@ -0,0 +1,2 @@ +# None +- [None uttearnces](./all.lu#Help) \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json new file mode 100644 index 0000000000..b0a6ee8103 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json @@ -0,0 +1,23 @@ +{ + "sections": [ + { + "Errors": [], + "SectionType": "ModelInfoSection", + "Id": "modelInfoSection_> !# @version = 1.0", + "Body": "", + "Range": { + "Start": { + "Line": 2, + "Character": 0 + }, + "End": { + "Line": 2, + "Character": 19 + } + }, + "ModelInfo": "> !# @version = 1.0" + } + ], + "content": "> Parser instruction - this is optional; unless specified, parser will default to the latest version.\n> !# @version = 1.0", + "errors": [] +} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt new file mode 100644 index 0000000000..fe1e5a4315 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt @@ -0,0 +1,2 @@ +> Parser instruction - this is optional; unless specified, parser will default to the latest version. +> !# @version = 1.0 \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj index 7e9e1d2442..b56776223e 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj @@ -9,16 +9,20 @@ Debug;Release + + + + + + + + - - - - Always @@ -1913,6 +1917,30 @@ Always + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs index ab77ce38e5..d79157dbee 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs @@ -4,9 +4,6 @@ using System; using System.IO; using System.Runtime.InteropServices; -using System.Text; -using System.Text.RegularExpressions; -using Microsoft.Bot.Builder.Parsers.LU; using Newtonsoft.Json; using Xunit; @@ -14,6 +11,35 @@ namespace Microsoft.Bot.Builder.Parsers.LU.Tests.Parser { public class LuParserTests { + private const string _validLUContentWithComments = @" +> this is the first comment outside of any section + +#noUtterences +- + +# cancel +> this comment is just after the intent +- cancel +- please cancel that +> this comment is in the middle of utterences +- stop that + +> this comment is between sections + +# help +- help +- I need help +- please help me +- can you help + +# weather +- get weather +- weather +- how is the weather + +> final comment +"; + [Theory] [InlineData("LU_Sections")] [InlineData("SectionsLU")] @@ -356,6 +382,10 @@ public void ParseLuContent(string fileName) [InlineData("testLU308")] [InlineData("testLU309")] [InlineData("testLU310")] + [InlineData("testLUPVA1")] + [InlineData("testLUPVA2")] + [InlineData("testLUPVA3")] + [InlineData("testLUPVA4")] public void ParseLuContentAutomated(string fileName) { var path = Path.Combine(Directory.GetCurrentDirectory(), "Fixtures", fileName + ".txt"); @@ -371,12 +401,88 @@ public void ParseLuContentAutomated(string fileName) LuResource expected = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Fixtures", fileName + ".json")).Replace("\r", string.Empty)); var serializedExpected = JsonConvert.SerializeObject(expected); - var serExpected = SanitizeString(serializedExpected); var serResult = SanitizeString(serializedResult); + var serExpected = SanitizeString(serializedExpected); Assert.Equal(serExpected, serResult); } + [Fact] + public void GetUtterancesPerIntent_SimpleCase() + { + var result = LuParser.Parse(_validLUContentWithComments); + + Assert.Equal(4, result.Sections.Count); + + Assert.Single(result.Sections[0].UtteranceAndEntitiesMap); + + Assert.Equal(3, result.Sections[1].UtteranceAndEntitiesMap.Count); + Assert.Equal("cancel", result.Sections[1].UtteranceAndEntitiesMap[0].Utterance); + Assert.Equal("please cancel that", result.Sections[1].UtteranceAndEntitiesMap[1].Utterance); + Assert.Equal("stop that", result.Sections[1].UtteranceAndEntitiesMap[2].Utterance); + + Assert.Equal(4, result.Sections[2].UtteranceAndEntitiesMap.Count); + Assert.Equal("help", result.Sections[2].UtteranceAndEntitiesMap[0].Utterance); + Assert.Equal("I need help", result.Sections[2].UtteranceAndEntitiesMap[1].Utterance); + Assert.Equal("please help me", result.Sections[2].UtteranceAndEntitiesMap[2].Utterance); + Assert.Equal("can you help", result.Sections[2].UtteranceAndEntitiesMap[3].Utterance); + + Assert.Equal(3, result.Sections[3].UtteranceAndEntitiesMap.Count); + Assert.Equal("get weather", result.Sections[3].UtteranceAndEntitiesMap[0].Utterance); + Assert.Equal("weather", result.Sections[3].UtteranceAndEntitiesMap[1].Utterance); + Assert.Equal("how is the weather", result.Sections[3].UtteranceAndEntitiesMap[2].Utterance); + } + + [Fact] + public void GetUtterancesPerIntent_OnlyComments() + { + var result = LuParser.Parse(@"> To learn more about the LU file format, read the documentation at +> https://aka.ms/lu-file-format"); + + Assert.Empty(result.Sections); + } + + [Fact] + public void SplitContentPerIntent_SimpleCase() + { + var result = LuParser.Parse(_validLUContentWithComments); + + Assert.Equal(4, result.Sections.Count); + + var expectedValue = @"- +"; + + Assert.Equal(expectedValue, result.Sections[0].Body); + + expectedValue = @"> this comment is just after the intent +- cancel +- please cancel that +> this comment is in the middle of utterences +- stop that + +> this comment is between sections +"; + + Assert.Equal(expectedValue, result.Sections[1].Body); + + expectedValue = @"- help +- I need help +- please help me +- can you help +"; + + Assert.Equal(expectedValue, result.Sections[2].Body); + + expectedValue = @"- get weather +- weather +- how is the weather + +> final comment +"; + + Assert.Equal(expectedValue, result.Sections[3].Body); + } + private string SanitizeString(string s) { return s.Replace("\\r\\n", "\\n"); From 1d118764e0bb928e02b936d8df62adc1f8bfe669 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Tue, 5 Nov 2024 15:33:51 -0300 Subject: [PATCH 2/3] Clean up tests --- .../Fixtures/ValidLUContentWithComments.json | 328 ++++++++++++++++++ .../Fixtures/ValidLUContentWithComments.txt | 26 ++ .../Fixtures/testLUPVA1.json | 51 --- .../Fixtures/testLUPVA1.txt | 5 - .../Fixtures/testLUPVA2.json | 26 -- .../Fixtures/testLUPVA2.txt | 1 - .../Fixtures/testLUPVA3.json | 44 --- .../Fixtures/testLUPVA3.txt | 2 - .../Fixtures/testLUPVA4.json | 23 -- .../Fixtures/testLUPVA4.txt | 2 - ...rosoft.Bot.Builder.Parsers.LU.Tests.csproj | 26 +- .../Parser/LuParserTests.cs | 110 +----- 12 files changed, 357 insertions(+), 287 deletions(-) create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.json create mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.txt delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json delete mode 100644 tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.json new file mode 100644 index 0000000000..2cb4f4f379 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.json @@ -0,0 +1,328 @@ +{ + "sections": [ + { + "Errors": [ + + ], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_noUtterences", + "Body": "- \n", + "UtteranceAndEntitiesMap": [ + { + "utterance": "", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- ", + "range": { + "Start": { + "Line": 4, + "Character": 0 + }, + "End": { + "Line": 4, + "Character": 2 + } + } + } + ], + "Entities": [ + + ], + "Name": "noUtterences", + "IntentNameLine": "#noUtterences", + "Range": { + "Start": { + "Line": 3, + "Character": 0 + }, + "End": { + "Line": 5, + "Character": 0 + } + } + }, + { + "Errors": [ + + ], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_cancel", + "Body": "> this comment is just after the intent\n- cancel\n- please cancel that\n> this comment is in the middle of utterences\n- stop that\n\n> this comment is between sections\n", + "UtteranceAndEntitiesMap": [ + { + "utterance": "cancel", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- cancel", + "range": { + "Start": { + "Line": 8, + "Character": 0 + }, + "End": { + "Line": 8, + "Character": 8 + } + } + }, + { + "utterance": "please cancel that", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- please cancel that", + "range": { + "Start": { + "Line": 9, + "Character": 0 + }, + "End": { + "Line": 9, + "Character": 20 + } + } + }, + { + "utterance": "stop that", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- stop that", + "range": { + "Start": { + "Line": 11, + "Character": 0 + }, + "End": { + "Line": 11, + "Character": 11 + } + } + } + ], + "Entities": [ + + ], + "Name": "cancel", + "IntentNameLine": "# cancel", + "Range": { + "Start": { + "Line": 6, + "Character": 0 + }, + "End": { + "Line": 14, + "Character": 0 + } + } + }, + { + "Errors": [ + + ], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_help", + "Body": "- help\n- I need help\n- please help me\n- can you help\n", + "UtteranceAndEntitiesMap": [ + { + "utterance": "help", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- help", + "range": { + "Start": { + "Line": 16, + "Character": 0 + }, + "End": { + "Line": 16, + "Character": 6 + } + } + }, + { + "utterance": "I need help", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- I need help", + "range": { + "Start": { + "Line": 17, + "Character": 0 + }, + "End": { + "Line": 17, + "Character": 13 + } + } + }, + { + "utterance": "please help me", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- please help me", + "range": { + "Start": { + "Line": 18, + "Character": 0 + }, + "End": { + "Line": 18, + "Character": 16 + } + } + }, + { + "utterance": "can you help", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- can you help", + "range": { + "Start": { + "Line": 19, + "Character": 0 + }, + "End": { + "Line": 19, + "Character": 14 + } + } + } + ], + "Entities": [ + + ], + "Name": "help", + "IntentNameLine": "# help", + "Range": { + "Start": { + "Line": 15, + "Character": 0 + }, + "End": { + "Line": 20, + "Character": 0 + } + } + }, + { + "Errors": [ + + ], + "SectionType": "SimpleIntentSection", + "Id": "simpleIntentSection_weather", + "Body": "- get weather\n- weather\n- how is the weather\n\n> final comment", + "UtteranceAndEntitiesMap": [ + { + "utterance": "get weather", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- get weather", + "range": { + "Start": { + "Line": 22, + "Character": 0 + }, + "End": { + "Line": 22, + "Character": 13 + } + } + }, + { + "utterance": "weather", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- weather", + "range": { + "Start": { + "Line": 23, + "Character": 0 + }, + "End": { + "Line": 23, + "Character": 9 + } + } + }, + { + "utterance": "how is the weather", + "entities": [ + + ], + "errorMsgs": [ + + ], + "contextText": "- how is the weather", + "range": { + "Start": { + "Line": 24, + "Character": 0 + }, + "End": { + "Line": 24, + "Character": 20 + } + } + } + ], + "Entities": [ + + ], + "Name": "weather", + "IntentNameLine": "# weather", + "Range": { + "Start": { + "Line": 21, + "Character": 0 + }, + "End": { + "Line": 26, + "Character": 15 + } + } + } + ], + "content": "> this is the first comment outside of any section\n\n#noUtterences\n- \n\n# cancel\n> this comment is just after the intent\n- cancel\n- please cancel that\n> this comment is in the middle of utterences\n- stop that\n\n> this comment is between sections\n\n# help\n- help\n- I need help\n- please help me\n- can you help\n\n# weather\n- get weather\n- weather\n- how is the weather\n\n> final comment", + "errors": [ + + ] +} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.txt new file mode 100644 index 0000000000..78f85f5f96 --- /dev/null +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/ValidLUContentWithComments.txt @@ -0,0 +1,26 @@ +> this is the first comment outside of any section + +#noUtterences +- + +# cancel +> this comment is just after the intent +- cancel +- please cancel that +> this comment is in the middle of utterences +- stop that + +> this comment is between sections + +# help +- help +- I need help +- please help me +- can you help + +# weather +- get weather +- weather +- how is the weather + +> final comment \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json deleted file mode 100644 index 294b7d07f6..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "sections": [ - { - "Errors": [], - "SectionType": "SimpleIntentSection", - "Id": "simpleIntentSection_getUserName", - "Body": " - my name is {username=vishwac}\r\n\r\n > Without an explicit entity definition, 'userName' defaults to 'ml' entity type\r\n", - "UtteranceAndEntitiesMap": [ - { - "utterance": "my name is vishwac", - "entities": [ - { - "type": "Entities", - "entity": "username", - "role": "", - "startPos": 11, - "endPos": 17 - } - ], - "errorMsgs": [], - "contextText": "- my name is {username=vishwac}", - "range": { - "Start": { - "Line": 3, - "Character": 4 - }, - "End": { - "Line": 3, - "Character": 35 - } - } - } - ], - "Entities": [], - "Name": "getUserName", - "IntentNameLine": "# getUserName", - "Range": { - "Start": { - "Line": 2, - "Character": 0 - }, - "End": { - "Line": 6, - "Character": 0 - } - } - } - ], - "content": "\n # getUserName\n - my name is {username=vishwac}\n\n > Without an explicit entity definition, 'userName' defaults to 'ml' entity type\n", - "errors": [] -} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt deleted file mode 100644 index 5cba289b30..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA1.txt +++ /dev/null @@ -1,5 +0,0 @@ - - # getUserName - - my name is {username=vishwac} - - > Without an explicit entity definition, 'userName' defaults to 'ml' entity type diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json deleted file mode 100644 index 0e11311c31..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "sections": [ - { - "Errors": [], - "SectionType": "NewEntitySection", - "Id": "newEntitySection_number", - "Body": "", - "Name": "number", - "Range": { - "Start": { - "Line": 1, - "Character": 0 - }, - "End": { - "Line": 1, - "Character": 34 - } - }, - "Type": "prebuilt", - "ListBody": [], - "Roles": "numOfGuests, age" - } - ], - "content": "@ prebuilt number numOfGuests, age", - "errors": [] -} diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt deleted file mode 100644 index b42d8a6b00..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA2.txt +++ /dev/null @@ -1 +0,0 @@ -@ prebuilt number numOfGuests, age \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json deleted file mode 100644 index 65e4e81718..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "sections": [ - { - "Errors": [], - "SectionType": "SimpleIntentSection", - "Id": "simpleIntentSection_None", - "Body": "- [None uttearnces](./all.lu#Help)", - "UtteranceAndEntitiesMap": [ - { - "utterance": "[None uttearnces](./all.lu#Help)", - "entities": [], - "errorMsgs": [], - "contextText": "- [None uttearnces](./all.lu#Help)", - "range": { - "Start": { - "Line": 2, - "Character": 0 - }, - "End": { - "Line": 2, - "Character": 34 - } - }, - "references": { "source": "./all.lu#Help" } - } - ], - "Entities": [], - "Name": "None", - "IntentNameLine": "# None", - "Range": { - "Start": { - "Line": 1, - "Character": 0 - }, - "End": { - "Line": 2, - "Character": 34 - } - } - } - ], - "content": "# None\n- [None uttearnces](./all.lu#Help)", - "errors": [] -} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt deleted file mode 100644 index b922782957..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA3.txt +++ /dev/null @@ -1,2 +0,0 @@ -# None -- [None uttearnces](./all.lu#Help) \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json deleted file mode 100644 index b0a6ee8103..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "sections": [ - { - "Errors": [], - "SectionType": "ModelInfoSection", - "Id": "modelInfoSection_> !# @version = 1.0", - "Body": "", - "Range": { - "Start": { - "Line": 2, - "Character": 0 - }, - "End": { - "Line": 2, - "Character": 19 - } - }, - "ModelInfo": "> !# @version = 1.0" - } - ], - "content": "> Parser instruction - this is optional; unless specified, parser will default to the latest version.\n> !# @version = 1.0", - "errors": [] -} \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt deleted file mode 100644 index fe1e5a4315..0000000000 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Fixtures/testLUPVA4.txt +++ /dev/null @@ -1,2 +0,0 @@ -> Parser instruction - this is optional; unless specified, parser will default to the latest version. -> !# @version = 1.0 \ No newline at end of file diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj index 65fa4966d0..53c80b3f33 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj @@ -13,10 +13,6 @@ - - - - @@ -1917,28 +1913,10 @@ Always - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - + Always - + Always diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs index d79157dbee..b8aa9ad3a0 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs @@ -11,40 +11,12 @@ namespace Microsoft.Bot.Builder.Parsers.LU.Tests.Parser { public class LuParserTests { - private const string _validLUContentWithComments = @" -> this is the first comment outside of any section - -#noUtterences -- - -# cancel -> this comment is just after the intent -- cancel -- please cancel that -> this comment is in the middle of utterences -- stop that - -> this comment is between sections - -# help -- help -- I need help -- please help me -- can you help - -# weather -- get weather -- weather -- how is the weather - -> final comment -"; - [Theory] [InlineData("LU_Sections")] [InlineData("SectionsLU")] [InlineData("ImportAllLu")] [InlineData("AllComments")] + [InlineData("ValidLUContentWithComments")] public void ParseLuContent(string fileName) { // var luContent = "# Help"+ Environment.NewLine + "- help" + Environment.NewLine + "- I need help" + Environment.NewLine + "- please help"; @@ -382,10 +354,6 @@ public void ParseLuContent(string fileName) [InlineData("testLU308")] [InlineData("testLU309")] [InlineData("testLU310")] - [InlineData("testLUPVA1")] - [InlineData("testLUPVA2")] - [InlineData("testLUPVA3")] - [InlineData("testLUPVA4")] public void ParseLuContentAutomated(string fileName) { var path = Path.Combine(Directory.GetCurrentDirectory(), "Fixtures", fileName + ".txt"); @@ -407,82 +375,6 @@ public void ParseLuContentAutomated(string fileName) Assert.Equal(serExpected, serResult); } - [Fact] - public void GetUtterancesPerIntent_SimpleCase() - { - var result = LuParser.Parse(_validLUContentWithComments); - - Assert.Equal(4, result.Sections.Count); - - Assert.Single(result.Sections[0].UtteranceAndEntitiesMap); - - Assert.Equal(3, result.Sections[1].UtteranceAndEntitiesMap.Count); - Assert.Equal("cancel", result.Sections[1].UtteranceAndEntitiesMap[0].Utterance); - Assert.Equal("please cancel that", result.Sections[1].UtteranceAndEntitiesMap[1].Utterance); - Assert.Equal("stop that", result.Sections[1].UtteranceAndEntitiesMap[2].Utterance); - - Assert.Equal(4, result.Sections[2].UtteranceAndEntitiesMap.Count); - Assert.Equal("help", result.Sections[2].UtteranceAndEntitiesMap[0].Utterance); - Assert.Equal("I need help", result.Sections[2].UtteranceAndEntitiesMap[1].Utterance); - Assert.Equal("please help me", result.Sections[2].UtteranceAndEntitiesMap[2].Utterance); - Assert.Equal("can you help", result.Sections[2].UtteranceAndEntitiesMap[3].Utterance); - - Assert.Equal(3, result.Sections[3].UtteranceAndEntitiesMap.Count); - Assert.Equal("get weather", result.Sections[3].UtteranceAndEntitiesMap[0].Utterance); - Assert.Equal("weather", result.Sections[3].UtteranceAndEntitiesMap[1].Utterance); - Assert.Equal("how is the weather", result.Sections[3].UtteranceAndEntitiesMap[2].Utterance); - } - - [Fact] - public void GetUtterancesPerIntent_OnlyComments() - { - var result = LuParser.Parse(@"> To learn more about the LU file format, read the documentation at -> https://aka.ms/lu-file-format"); - - Assert.Empty(result.Sections); - } - - [Fact] - public void SplitContentPerIntent_SimpleCase() - { - var result = LuParser.Parse(_validLUContentWithComments); - - Assert.Equal(4, result.Sections.Count); - - var expectedValue = @"- -"; - - Assert.Equal(expectedValue, result.Sections[0].Body); - - expectedValue = @"> this comment is just after the intent -- cancel -- please cancel that -> this comment is in the middle of utterences -- stop that - -> this comment is between sections -"; - - Assert.Equal(expectedValue, result.Sections[1].Body); - - expectedValue = @"- help -- I need help -- please help me -- can you help -"; - - Assert.Equal(expectedValue, result.Sections[2].Body); - - expectedValue = @"- get weather -- weather -- how is the weather - -> final comment -"; - - Assert.Equal(expectedValue, result.Sections[3].Body); - } - private string SanitizeString(string s) { return s.Replace("\\r\\n", "\\n"); From 591792a190157107a9138769b709c2cdca0d03e2 Mon Sep 17 00:00:00 2001 From: CeciliaAvila Date: Tue, 12 Nov 2024 09:47:35 -0300 Subject: [PATCH 3/3] Remove unnecessary changes --- .../Microsoft.Bot.Builder.Parsers.LU.Tests.csproj | 8 ++++---- .../Parser/LuParserTests.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj index 53c80b3f33..fcf9f0830b 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Microsoft.Bot.Builder.Parsers.LU.Tests.csproj @@ -9,16 +9,16 @@ Debug;Release - - - - + + + + Always diff --git a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs index b8aa9ad3a0..47d93dcd04 100644 --- a/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs +++ b/tests/Parsers/Microsoft.Bot.Builder.Parsers.LU.Tests/Parser/LuParserTests.cs @@ -369,8 +369,8 @@ public void ParseLuContentAutomated(string fileName) LuResource expected = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Fixtures", fileName + ".json")).Replace("\r", string.Empty)); var serializedExpected = JsonConvert.SerializeObject(expected); - var serResult = SanitizeString(serializedResult); var serExpected = SanitizeString(serializedExpected); + var serResult = SanitizeString(serializedResult); Assert.Equal(serExpected, serResult); }