Skip to content

Commit 5c98078

Browse files
committed
Add test cases to cover ID3D12Device shared prefix identification behavior
1 parent d3c4cf2 commit 5c98078

3 files changed

Lines changed: 69 additions & 1 deletion
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[NameAffix("Prefix", "SharedPrefix", "D3D12")]
2+
public struct D3D12_BUFFER_BARRIER;
3+
[NameAffix("Prefix", "SharedPrefix", "D3D12")]
4+
[NameAffix("Prefix", "Interface", "I")]
5+
public struct ID3D12Device;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[NameAffix("Prefix", "SharedPrefix", "D3D12")]
2+
[NameAffix("Prefix", "Interface", "I")]
3+
public struct ID3D12Device;

tests/SilkTouch/SilkTouch/Naming/IdentifySharedPrefixesTests.cs

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,73 @@ public enum OcclusionQueryParameterNameNV
185185

186186
await identifySharedPrefixes.ExecuteAsync(context);
187187

188-
// The declaration of the 2 NV member suffixes should make PrettifyNames trim less of the member name
188+
// The declaration of the 2 NV member suffixes should make IdentifySharedPrefixes identify less of the member name as the shared prefix
189189
// IdentifySharedPrefixes should only use the unaffixed name for prefix identification
190190
// The shared prefix should be "GL_PIXEL"
191191
var result = await context.SourceProject.Documents.First().GetSyntaxRootAsync();
192192
await Verify(result!.NormalizeWhitespace().ToString());
193193
}
194194

195+
[Test]
196+
public async Task IdentifiesSharedPrefix_WhenPrefixesDeclared()
197+
{
198+
var project = TestUtils
199+
.CreateTestProject()
200+
.AddDocument(
201+
"D3D12.gen.cs",
202+
"""
203+
public struct D3D12_BUFFER_BARRIER;
204+
205+
[NameAffix("Prefix", "Interface", "I")]
206+
public struct ID3D12Device;
207+
"""
208+
)
209+
.Project;
210+
211+
var context = new DummyModContext() { SourceProject = project };
212+
213+
var identifySharedPrefixes = new IdentifySharedPrefixes(
214+
new DummyOptions<IdentifySharedPrefixes.Configuration>(
215+
new IdentifySharedPrefixes.Configuration()
216+
)
217+
);
218+
219+
await identifySharedPrefixes.ExecuteAsync(context);
220+
221+
// The declaration of the I- prefix should lead to "D3D12" being identified as the shared prefix
222+
var result = await context.SourceProject.Documents.First().GetSyntaxRootAsync();
223+
await Verify(result!.NormalizeWhitespace().ToString());
224+
}
225+
226+
[Test]
227+
public async Task IdentifiesSharedPrefix_WhenPrefixesDeclared_WithHint()
228+
{
229+
var project = TestUtils
230+
.CreateTestProject()
231+
.AddDocument(
232+
"D3D12.gen.cs",
233+
"""
234+
[NameAffix("Prefix", "Interface", "I")]
235+
public struct ID3D12Device;
236+
"""
237+
)
238+
.Project;
239+
240+
var context = new DummyModContext() { SourceProject = project };
241+
242+
var identifySharedPrefixes = new IdentifySharedPrefixes(
243+
new DummyOptions<IdentifySharedPrefixes.Configuration>(
244+
new IdentifySharedPrefixes.Configuration() { GlobalPrefixHints = ["D3D12"] }
245+
)
246+
);
247+
248+
await identifySharedPrefixes.ExecuteAsync(context);
249+
250+
// The declaration of the I- prefix should lead to "D3D12" being identified as the shared prefix
251+
var result = await context.SourceProject.Documents.First().GetSyntaxRootAsync();
252+
await Verify(result!.NormalizeWhitespace().ToString());
253+
}
254+
195255
[Test]
196256
public async Task HintShouldNotAffectSharedPrefixIdentification()
197257
{

0 commit comments

Comments
 (0)