Adjusting "Option to anonymize unknown public functions" (#2600)

Avoids breaking change at
https://github.com/microsoft/Power-Fx/pull/2597.
This commit is contained in:
Anderson Silva 2024-08-19 17:31:23 -05:00 коммит произвёл GitHub
Родитель fd52aff3df
Коммит 6559d64c51
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 16 добавлений и 11 удалений

Просмотреть файл

@ -715,9 +715,14 @@ namespace Microsoft.PowerFx
return summary;
}
public IEnumerable<string> GetFunctionNames(bool annonymizeUnknownPublicFunctions = false)
public IEnumerable<string> GetFunctionNames()
{
return ListFunctionVisitor.Run(ApplyParse(), annonymizeUnknownPublicFunctions);
return GetFunctionNames(false);
}
public IEnumerable<string> GetFunctionNames(bool anonymizeUnknownPublicFunctions)
{
return ListFunctionVisitor.Run(ApplyParse(), anonymizeUnknownPublicFunctions);
}
}

Просмотреть файл

@ -14,16 +14,16 @@ namespace Microsoft.PowerFx.Syntax
private readonly Dictionary<string, string> _unknownFunctionNames = new Dictionary<string, string>();
private readonly bool _anonymizedUnknownPublicFunctions;
public static IEnumerable<string> Run(ParseResult parse, bool annonymizeUnknownPublicFunctions = false)
public static IEnumerable<string> 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)

Просмотреть файл

@ -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<InvalidOperationException>(() => 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);