Skip to content

Commit

Permalink
Merge pull request #567 from ronaldvanmanen/fix/with-attributes-wildc…
Browse files Browse the repository at this point in the history
…ard-support

Fix wildcard support for --with-attributes option.
  • Loading branch information
tannergooding authored Sep 27, 2024
2 parents cde319b + 7a147c5 commit 7e211d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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);
}
}

0 comments on commit 7e211d6

Please sign in to comment.