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 wildcard support for --with-attributes option. #567

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6765,7 +6765,7 @@ private void WithAttributes(NamedDecl namedDecl, bool onlySupportedOSPlatform =
var outputBuilder = isTestOutput ? _testOutputBuilder : _outputBuilder;
Debug.Assert(outputBuilder is not null);

if (TryGetRemappedValue(namedDecl, _config.WithAttributes, out var attributes))
if (TryGetRemappedValue(namedDecl, _config.WithAttributes, out var attributes, matchStar: true))
{
foreach (var attribute in attributes.Where((a) => !onlySupportedOSPlatform || a.StartsWith("SupportedOSPlatform(", StringComparison.Ordinal)))
{
Expand Down
37 changes: 37 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,41 @@ public partial struct StructD

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withUsings);
}

[Test]
public Task WithAttributes()
{
var inputContents = @"struct StructA {}; struct StructB {}; struct StructC {}; struct StructD {};";
var expectedOutputContents =
@"namespace ClangSharp.Test
{
[A]
public partial struct StructA
{
}

[B]
public partial struct StructB
{
}

[Star]
public partial struct StructC
{
}

[Star]
public partial struct StructD
{
}
}
";
var withAttributes = new Dictionary<string, IReadOnlyList<string>> {
["StructA"] = [@"A"],
["StructB"] = [@"B"],
["*"] = [@"Star"],
};

return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withAttributes: withAttributes);
}
}