Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scope info for AddColumns / Search functions #2166

Merged
merged 14 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public AddColumnsFunction()
{
// AddColumns(source, name, valueFunc, name, valueFunc, ..., name, valueFunc, ...)
SignatureConstraint = new SignatureConstraint(omitStartIndex: 5, repeatSpan: 2, endNonRepeatCount: 0, repeatTopLength: 9);
ScopeInfo = new FunctionScopeInfo(this, canBeCreatedByRecord: true);
ScopeInfo = new FunctionScopeInfo(this, canBeCreatedByRecord: true, appliesToArgument: (argIndex) => (argIndex % 2) == 1);
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public RenameColumnsFunction()
{
// RenameColumns(source, oldName, newName, oldName, newName, ..., oldName, newName, ...)
SignatureConstraint = new SignatureConstraint(omitStartIndex: 5, repeatSpan: 2, endNonRepeatCount: 0, repeatTopLength: 9);
ScopeInfo = new FunctionScopeInfo(this, canBeCreatedByRecord: true);
ScopeInfo = new FunctionScopeInfo(this, canBeCreatedByRecord: true, appliesToArgument: (argIndex) => argIndex % 2 == 1);
}

public override IEnumerable<TexlStrings.StringGetter[]> GetSignatures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal sealed class SearchFunction : FunctionWithTableInput
public SearchFunction()
: base("Search", TexlStrings.AboutSearch, FunctionCategories.Table, DType.EmptyTable, 0, 3, int.MaxValue, DType.EmptyTable, DType.String, DType.String)
{
ScopeInfo = new FunctionScopeInfo(this);
ScopeInfo = new FunctionScopeInfo(this, appliesToArgument: (argIndex) => argIndex > 1);
}

public override ParamIdentifierStatus GetIdentifierParamStatus(Features features, int index)
Expand Down
14 changes: 14 additions & 0 deletions src/tests/Microsoft.PowerFx.Core.Tests/FunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ public void TextFunctionSet_Remove2()
Assert.Empty(tfs.WithNamespace(DPath.Root));
}

[Fact]
public void TestScopeArguments()
{
for (int i = 0; i < 10; i++)
{
Assert.Equal(i % 2 == 1, BuiltinFunctionsCore.AddColumns.ScopeInfo.AppliesToArgument(i));
Assert.Equal(i % 2 == 1, BuiltinFunctionsCore.RenameColumns.ScopeInfo.AppliesToArgument(i));
Assert.Equal(i > 0, BuiltinFunctionsCore.ShowColumns.ScopeInfo.AppliesToArgument(i));
Assert.Equal(i > 0, BuiltinFunctionsCore.DropColumns.ScopeInfo.AppliesToArgument(i));
Assert.Equal(i > 1, BuiltinFunctionsCore.Search.ScopeInfo.AppliesToArgument(i));
Assert.Equal(i % 2 == 1, BuiltinFunctionsCore.SortByColumns.ScopeInfo.AppliesToArgument(i));
}
}

private class TestTexlFunction : TexlFunction
{
private readonly int _requiredEnums = 0;
Expand Down
Loading