Skip to content

Commit 76c95c4

Browse files
Merge pull request #537 from dpaoliello/usingstar
Enable matching `*` for `--with-using`
2 parents b51851a + 807fe45 commit 76c95c4

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7001,7 +7001,7 @@ private void WithUsings(NamedDecl namedDecl)
70017001
{
70027002
Debug.Assert(_outputBuilder is not null);
70037003

7004-
if (TryGetRemappedValue(namedDecl, _config.WithUsings, out var usings))
7004+
if (TryGetRemappedValue(namedDecl, _config.WithUsings, out var usings, matchStar: true))
70057005
{
70067006
foreach (var @using in usings)
70077007
{
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// 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.
2+
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using NUnit.Framework;
6+
7+
namespace ClangSharp.UnitTests;
8+
9+
public sealed class OptionsTest : PInvokeGeneratorTest
10+
{
11+
[Test]
12+
public Task WithUsings()
13+
{
14+
var inputContents = @"struct StructA {};
15+
namespace NS
16+
{
17+
struct StructB {};
18+
struct StructC {};
19+
}
20+
struct StructD {};
21+
";
22+
var expectedOutputContents = @"using ForStar;
23+
using ForStructA1;
24+
using ForStructA2;
25+
using ForStructBWithDoubleColon;
26+
using ForStructCWithDot;
27+
28+
namespace ClangSharp.Test
29+
{
30+
public partial struct StructA
31+
{
32+
}
33+
34+
public partial struct StructB
35+
{
36+
}
37+
38+
public partial struct StructC
39+
{
40+
}
41+
42+
public partial struct StructD
43+
{
44+
}
45+
}
46+
";
47+
var withUsings = new Dictionary<string, IReadOnlyList<string>> {
48+
["StructA"] = ["ForStructA1", "ForStructA2"],
49+
["*"] = ["ForStar"],
50+
["NS::StructB"] = ["ForStructBWithDoubleColon"],
51+
["NS.StructC"] = ["ForStructCWithDot"],
52+
["DoesNotExist"] = ["ErrorShouldNotBeInOutput"],
53+
};
54+
55+
return ValidateGeneratedCSharpLatestWindowsBindingsAsync(inputContents, expectedOutputContents, withUsings: withUsings);
56+
}
57+
}

0 commit comments

Comments
 (0)