diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs index a507a91b50..92f9e55582 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Evaluator.cs @@ -431,7 +431,7 @@ private object EvalExpression(string exp, ParserRuleContext expressionContext = CheckExpressionResult(exp, error, result, templateName, lineContent, errorPrefix); } - else if (result == null && lgOptions.StrictMode != false) + else if (result == null && lgOptions.StrictMode != true) { result = "null"; } diff --git a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs index a359daec5d..d0819a7c63 100644 --- a/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs +++ b/libraries/Microsoft.Bot.Builder.LanguageGeneration/Expander.cs @@ -430,7 +430,7 @@ private List EvalExpression(string exp, ParserRuleContext context = null Evaluator.CheckExpressionResult(exp, error, result, templateName, lineContent, errorPrefix); } - else if (result == null && lgOptions.StrictMode == false) + else if (result == null && lgOptions.StrictMode != true) { result = "null"; } diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeFalse.lg b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeFalse.lg new file mode 100644 index 0000000000..573a44317a --- /dev/null +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeFalse.lg @@ -0,0 +1,4 @@ +> !# @strict = false + +# StrictFalse +- ${variable_not_defined} \ No newline at end of file diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeTrue.lg b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeTrue.lg new file mode 100644 index 0000000000..92e5c90011 --- /dev/null +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Examples/EvaluationOptions/StrictModeTrue.lg @@ -0,0 +1,4 @@ +> !# @strict = true + +# StrictTrue +- ${variable_not_defined} \ No newline at end of file diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Microsoft.Bot.Builder.LanguageGeneration.Tests.csproj b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Microsoft.Bot.Builder.LanguageGeneration.Tests.csproj index 2fc8f523b3..834a86f439 100644 --- a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Microsoft.Bot.Builder.LanguageGeneration.Tests.csproj +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/Microsoft.Bot.Builder.LanguageGeneration.Tests.csproj @@ -24,6 +24,7 @@ + @@ -46,6 +47,7 @@ + @@ -161,6 +163,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -170,6 +175,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs index 8c7e8db81f..9a85848999 100644 --- a/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs +++ b/tests/Microsoft.Bot.Builder.LanguageGeneration.Tests/TemplatesTest.cs @@ -710,6 +710,20 @@ public void TestExpandTemplateWithEmptyListInStructuredLG() Assert.AreEqual(JObject.Parse(evaled[0].ToString())["inputhint"].ToString(), "ignoringInput"); } + [TestMethod] + public void TestExpandTemplateWithStrictMode() + { + var templates = Templates.ParseFile(GetExampleFilePath("EvaluationOptions/StrictModeFalse.lg")); + + var evaled = templates.ExpandTemplate("StrictFalse"); + Assert.AreEqual("null", evaled[0].ToString()); + + templates = Templates.ParseFile(GetExampleFilePath("EvaluationOptions/StrictModeTrue.lg")); + + var exception = Assert.ThrowsException(() => templates.ExpandTemplate("StrictTrue")); + Assert.IsTrue(exception.Message.Contains("'variable_not_defined' evaluated to null. [StrictTrue] Error occurred when evaluating '-${variable_not_defined}'")); + } + [TestMethod] public void TestEvalExpression() {