Skip to content

Commit

Permalink
Merge pull request #537 from dpaoliello/usingstar
Browse files Browse the repository at this point in the history
Enable matching `*` for `--with-using`
  • Loading branch information
tannergooding committed Apr 25, 2024
2 parents b51851a + 807fe45 commit 76c95c4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
Expand Up @@ -7001,7 +7001,7 @@ private void WithUsings(NamedDecl namedDecl)
{
Debug.Assert(_outputBuilder is not null);

if (TryGetRemappedValue(namedDecl, _config.WithUsings, out var usings))
if (TryGetRemappedValue(namedDecl, _config.WithUsings, out var usings, matchStar: true))
{
foreach (var @using in usings)
{
Expand Down
57 changes: 57 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs
@@ -0,0 +1,57 @@
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;

namespace ClangSharp.UnitTests;

public sealed class OptionsTest : PInvokeGeneratorTest
{
[Test]
public Task WithUsings()
{
var inputContents = @"struct StructA {};
namespace NS
{
struct StructB {};
struct StructC {};
}
struct StructD {};
";
var expectedOutputContents = @"using ForStar;
using ForStructA1;
using ForStructA2;
using ForStructBWithDoubleColon;
using ForStructCWithDot;
namespace ClangSharp.Test
{
public partial struct StructA
{
}
public partial struct StructB
{
}
public partial struct StructC
{
}
public partial struct StructD
{
}
}
";
var withUsings = new Dictionary<string, IReadOnlyList<string>> {
["StructA"] = ["ForStructA1", "ForStructA2"],
["*"] = ["ForStar"],
["NS::StructB"] = ["ForStructBWithDoubleColon"],
["NS.StructC"] = ["ForStructCWithDot"],
["DoesNotExist"] = ["ErrorShouldNotBeInOutput"],
};

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

0 comments on commit 76c95c4

Please sign in to comment.