Skip to content

Commit d0e34c1

Browse files
committed
Add test: TransformPropertiesTests.Transforms_Utf8String_StaticConstProperties
1 parent c9b5dcf commit d0e34c1

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public struct Test
2+
{
3+
public static Utf8String Text => "Hello world!"u8;
4+
}

tests/SilkTouch/SilkTouch/TransformPropertiesTests.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,38 @@ static TransformPropertiesTests()
1717
}
1818

1919
[Test]
20-
public async Task MaybeBool_Transforms_FieldsAndProperties()
20+
public async Task Transforms_Utf8String_StaticConstProperties()
21+
{
22+
var project = TestUtils
23+
.CreateTestProject()
24+
.AddDocument(
25+
"Test.gen.cs",
26+
"""
27+
public struct Test
28+
{
29+
public static ReadOnlySpan<byte> Text => "Hello world!"u8;
30+
}
31+
"""
32+
)
33+
.Project;
34+
35+
var context = new DummyModContext() { SourceProject = project };
36+
37+
var transformProperties = new TransformProperties(
38+
new DummyOptions<TransformProperties.Configuration>(
39+
new TransformProperties.Configuration() { BoolTypes = { { "TestBool32", null } } }
40+
)
41+
);
42+
43+
await transformProperties.ExecuteAsync(context);
44+
45+
// Test.Text should be transformed to use the Utf8String type
46+
var result = await context.SourceProject.Documents.First().GetSyntaxRootAsync();
47+
await Verify(result!.NormalizeWhitespace().ToString());
48+
}
49+
50+
[Test]
51+
public async Task Transforms_MaybeBool_FieldsAndProperties()
2152
{
2253
var project = TestUtils
2354
.CreateTestProject()
@@ -64,7 +95,7 @@ public struct NoTransform
6495

6596
await transformProperties.ExecuteAsync(context);
6697

67-
// Only members with [NativeTypeName("TestBool32")] should be transformed
98+
// Only members with exactly [NativeTypeName("TestBool32")] should be transformed
6899
var result = await context.SourceProject.Documents.First().GetSyntaxRootAsync();
69100
await Verify(result!.NormalizeWhitespace().ToString());
70101
}

0 commit comments

Comments
 (0)