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

Enable matching * for --with-using #537

Merged
merged 2 commits into from
Apr 25, 2024
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 @@ -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))
dpaoliello marked this conversation as resolved.
Show resolved Hide resolved
{
foreach (var @using in usings)
{
Expand Down
57 changes: 57 additions & 0 deletions tests/ClangSharp.PInvokeGenerator.UnitTests/OptionsTest.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading