Пример #1
0
        public void TestExpressionextract()
        {
            var lgFile = LGParser.ParseFile(GetExampleFilePath("ExpressionExtract.lg"));

            var evaled1        = lgFile.EvaluateTemplate("templateWithBrackets");
            var evaled2        = lgFile.EvaluateTemplate("templateWithBrackets2");
            var evaled3        = lgFile.EvaluateTemplate("templateWithBrackets3").ToString().Trim();
            var espectedResult = "don't mix {} and '{}'";

            Assert.AreEqual(evaled1, espectedResult);
            Assert.AreEqual(evaled2, espectedResult);
            Assert.AreEqual(evaled3, espectedResult);

            evaled1        = lgFile.EvaluateTemplate("templateWithQuotationMarks");
            evaled2        = lgFile.EvaluateTemplate("templateWithQuotationMarks2");
            evaled3        = lgFile.EvaluateTemplate("templateWithQuotationMarks3").ToString().Trim();
            espectedResult = "don't mix {\"} and \"\"'\"";
            Assert.AreEqual(evaled1, espectedResult);
            Assert.AreEqual(evaled2, espectedResult);
            Assert.AreEqual(evaled3, espectedResult);

            evaled1        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets1");
            evaled2        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets12");
            evaled3        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets13").ToString().Trim();
            espectedResult = "{prefix 5 sufix";
            Assert.AreEqual(evaled1, espectedResult);
            Assert.AreEqual(evaled2, espectedResult);
            Assert.AreEqual(evaled3, espectedResult);

            evaled1        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets2");
            evaled2        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets22");
            evaled3        = lgFile.EvaluateTemplate("templateWithUnpairedBrackets23").ToString().Trim();
            espectedResult = "prefix 5 sufix}";
            Assert.AreEqual(evaled1, espectedResult);
            Assert.AreEqual(evaled2, espectedResult);
            Assert.AreEqual(evaled3, espectedResult);
        }
Пример #2
0
        public void TestExpandTemplateWithRef()
        {
            var lgFile = LGParser.ParseFile(GetExampleFilePath("Expand.lg"));

            var alarms = new[]
            {
                new
                {
                    time = "7 am",
                    date = "tomorrow"
                },
                new
                {
                    time = "8 pm",
                    date = "tomorrow"
                }
            };

            var evaled = lgFile.ExpandTemplate("ShowAlarmsWithLgTemplate", new { alarms = alarms });

            Assert.AreEqual(2, evaled.Count);
            Assert.AreEqual("You have 2 alarms, they are 8 pm at tomorrow", evaled[0]);
            Assert.AreEqual("You have 2 alarms, they are 8 pm of tomorrow", evaled[1]);
        }
Пример #3
0
        public void TestCaseInsensitive()
        {
            var lgFile = LGParser.ParseFile(GetExampleFilePath("CaseInsensitive.lg"));
            var alarms = new[]
            {
                new
                {
                    time = "7 am",
                    date = "tomorrow"
                },
                new
                {
                    time = "8 pm",
                    date = "tomorrow"
                }
            };

            var evaled = lgFile.EvaluateTemplate("ShowAlarms", new { alarms = alarms });

            Assert.AreEqual("You have two alarms", evaled);

            evaled = lgFile.EvaluateTemplate("greetInAWeek", new { day = "Saturday" });
            Assert.AreEqual("Happy Saturday!", evaled);
        }
Пример #4
0
        public void TestEmptyArratAndObject()
        {
            var lgFile = LGParser.ParseFile(GetExampleFilePath("EmptyArrayAndObject.lg"));

            var evaled = lgFile.EvaluateTemplate("template", new { list = new List <string> {
                                                                   }, obj = new { } });

            Assert.AreEqual("list and obj are both empty", evaled);

            evaled = lgFile.EvaluateTemplate("template", new { list = new List <string> {
                                                               }, obj = new Dictionary <string, object>() });
            Assert.AreEqual("list and obj are both empty", evaled);

            evaled = lgFile.EvaluateTemplate("template", new { list = new List <string> {
                                                                   "hi"
                                                               }, obj = new { } });
            Assert.AreEqual("obj is empty", evaled);

            evaled = lgFile.EvaluateTemplate("template", new { list = new List <string> {
                                                               }, obj = new { a = "a" } });
            Assert.AreEqual("list is empty", evaled);

            evaled = lgFile.EvaluateTemplate("template", new { list = new List <string> {
                                                               }, obj = new Dictionary <string, object> {
                                                                   { "a", "b" }
                                                               } });
            Assert.AreEqual("list is empty", evaled);

            evaled = lgFile.EvaluateTemplate("template", new { list = new JArray()
                                                               {
                                                                   new JObject()
                                                               }, obj = new JObject {
                                                                   ["a"] = "b"
                                                               } });
            Assert.AreEqual("list and obj are both not empty.", evaled);
        }
        private IList <Diagnostic> GetDiagnostics(string fileName)
        {
            var filePath = GetExceptionExampleFilePath(fileName);

            return(LGParser.ParseFile(filePath).Diagnostics);
        }
        private LGFile GetLGFile(string fileName)
        {
            var filePath = GetExceptionExampleFilePath(fileName);

            return(LGParser.ParseFile(filePath));
        }
Пример #7
0
        private LGFile GetLGFile()
        {
            var path = Path.Combine(AppContext.BaseDirectory, "lg", "NormalStructuredLG.lg");

            return(LGParser.ParseFile(path));
        }
Пример #8
0
 public TestBotLG(TestBotAccessors accessors)
 {
     lgFile = LGParser.ParseFile(GetLGResourceFile("8.LG"));
 }
Пример #9
0
        public void TestStructuredTemplate()
        {
            var lgFile = LGParser.ParseFile(GetExampleFilePath("StructuredTemplate.lg"));

            var evaled = lgFile.EvaluateTemplate("AskForAge.prompt");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"how old are you?\",\"speak\":\"how old are you?\"}"), evaled as JObject) ||
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"what's your age?\",\"speak\":\"what's your age?\"}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("AskForAge.prompt2");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"how old are you?\",\"suggestedactions\":[\"10\",\"20\",\"30\"]}"), evaled as JObject) ||
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"what's your age?\",\"suggestedactions\":[\"10\",\"20\",\"30\"]}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("AskForAge.prompt3");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"${GetAge()}\",\"suggestions\":[\"10 | cards\",\"20 | cards\"]}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("T1");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"text\":\"This is awesome\",\"speak\":\"foo bar I can also speak!\"}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("ST1");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"MyStruct\",\"text\":\"foo\",\"speak\":\"bar\"}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("AskForColor");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Activity\",\"suggestedactions\":[{\"lgType\":\"MyStruct\",\"speak\":\"bar\",\"text\":\"zoo\"},{\"lgType\":\"Activity\",\"speak\":\"I can also speak!\"}]}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("MultiExpression");
            var options = new string[]
            {
                "{\r\n  \"lgType\": \"Activity\",\r\n  \"speak\": \"I can also speak!\"\r\n} {\r\n  \"lgType\": \"MyStruct\",\r\n  \"text\": \"hi\"\r\n}",
                "{\n  \"lgType\": \"Activity\",\n  \"speak\": \"I can also speak!\"\n} {\n  \"lgType\": \"MyStruct\",\n  \"text\": \"hi\"\n}"
            };

            Assert.IsTrue(options.Contains(evaled.ToString()));

            evaled = lgFile.EvaluateTemplate("StructuredTemplateRef");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"MyStruct\",\"text\":\"hi\"}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("MultiStructuredRef");

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"MyStruct\",\"list\":[{\"lgType\":\"SubStruct\",\"text\":\"hello\"},{\"lgType\":\"SubStruct\",\"text\":\"world\"}]}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("templateWithSquareBrackets", new { manufacturer = new { Name = "Acme Co" } });

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\":\"Struct\",\"text\":\"Acme Co\"}"), evaled as JObject));

            evaled = lgFile.EvaluateTemplate("ValueWithEqualsMark", new { name = "Jack" });

            Assert.IsTrue(
                JToken.DeepEquals(JObject.Parse("{\"lgType\": \"Activity\",\"text\": \"Hello! welcome back. I have your name = Jack\"}"), evaled as JObject));
        }