From 6559d64c51db7f2e877f5dca26967d5eee233508 Mon Sep 17 00:00:00 2001 From: Anderson Silva Date: Mon, 19 Aug 2024 17:31:23 -0500 Subject: [PATCH] Adjusting "Option to anonymize unknown public functions" (#2600) Avoids breaking change at https://github.com/microsoft/Power-Fx/pull/2597. --- .../Microsoft.PowerFx.Core/Public/CheckResult.cs | 9 +++++++-- .../Syntax/Visitors/ListFunctionVisitor.cs | 8 ++++---- .../ListFunctionVisitorTests.cs | 10 +++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/libraries/Microsoft.PowerFx.Core/Public/CheckResult.cs b/src/libraries/Microsoft.PowerFx.Core/Public/CheckResult.cs index 0005693f4..918eb2373 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Public/CheckResult.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Public/CheckResult.cs @@ -715,9 +715,14 @@ namespace Microsoft.PowerFx return summary; } - public IEnumerable GetFunctionNames(bool annonymizeUnknownPublicFunctions = false) + public IEnumerable GetFunctionNames() { - return ListFunctionVisitor.Run(ApplyParse(), annonymizeUnknownPublicFunctions); + return GetFunctionNames(false); + } + + public IEnumerable GetFunctionNames(bool anonymizeUnknownPublicFunctions) + { + return ListFunctionVisitor.Run(ApplyParse(), anonymizeUnknownPublicFunctions); } } diff --git a/src/libraries/Microsoft.PowerFx.Core/Syntax/Visitors/ListFunctionVisitor.cs b/src/libraries/Microsoft.PowerFx.Core/Syntax/Visitors/ListFunctionVisitor.cs index 219c2ad63..f4da00267 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Syntax/Visitors/ListFunctionVisitor.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Syntax/Visitors/ListFunctionVisitor.cs @@ -14,16 +14,16 @@ namespace Microsoft.PowerFx.Syntax private readonly Dictionary _unknownFunctionNames = new Dictionary(); private readonly bool _anonymizedUnknownPublicFunctions; - public static IEnumerable Run(ParseResult parse, bool annonymizeUnknownPublicFunctions = false) + public static IEnumerable Run(ParseResult parse, bool anonymizeUnknownPublicFunctions = false) { - var visitor = new ListFunctionVisitor(annonymizeUnknownPublicFunctions); + var visitor = new ListFunctionVisitor(anonymizeUnknownPublicFunctions); parse.Root.Accept(visitor); return visitor._functionNames; } - private ListFunctionVisitor(bool annonymizeUnknownPublicFunctions) + private ListFunctionVisitor(bool anonymizeUnknownPublicFunctions) { - _anonymizedUnknownPublicFunctions = annonymizeUnknownPublicFunctions; + _anonymizedUnknownPublicFunctions = anonymizeUnknownPublicFunctions; } public override bool PreVisit(CallNode node) diff --git a/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ListFunctionVisitorTests.cs b/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ListFunctionVisitorTests.cs index 67ca53aa7..367e62ad5 100644 --- a/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ListFunctionVisitorTests.cs +++ b/src/tests/Microsoft.PowerFx.Core.Tests.Shared/ListFunctionVisitorTests.cs @@ -18,7 +18,7 @@ namespace Microsoft.PowerFx.Core.Tests [InlineData("Foo() + Abs(1) + Foo()", "$#CustomFunction1#$,Abs", true)] [InlineData("true And true", "")] [InlineData("If(true, Blank(),Error())", "If,Blank,Error")] - public void ListFunctionNamesTest(string expression, string expectedNames, bool annonymizeUnknownPublicFunctions = false) + public void ListFunctionNamesTest(string expression, string expectedNames, bool anonymizeUnknownPublicFunctions = false) { foreach (var textFirst in new bool[] { false, true }) { @@ -27,7 +27,7 @@ namespace Microsoft.PowerFx.Core.Tests expression = $"={expression}"; } - CheckFunctionNames(textFirst, expression, expectedNames, annonymizeUnknownPublicFunctions); + CheckFunctionNames(textFirst, expression, expectedNames, anonymizeUnknownPublicFunctions); } } @@ -46,15 +46,15 @@ namespace Microsoft.PowerFx.Core.Tests Assert.Throws(() => checkResult.GetFunctionNames()); } - private static void CheckFunctionNames(bool textFirst, string expression, string expectedNames, bool annonymizeUnknownPublicFunctions) + private static void CheckFunctionNames(bool textFirst, string expression, string expectedNames, bool anonymizeUnknownPublicFunctions) { var options = new ParserOptions() { TextFirst = textFirst }; var engine = new Engine(); var check = engine.Check(expression, options); var checkResult = new CheckResult(engine).SetText(expression, options); - var functionsNames1 = check.GetFunctionNames(annonymizeUnknownPublicFunctions); - var functionsNames2 = checkResult.GetFunctionNames(annonymizeUnknownPublicFunctions); + var functionsNames1 = check.GetFunctionNames(anonymizeUnknownPublicFunctions); + var functionsNames2 = checkResult.GetFunctionNames(anonymizeUnknownPublicFunctions); var actualNames1 = string.Join(",", functionsNames1); var actualNames2 = string.Join(",", functionsNames2);