Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# dotenv files
.env
*.lscache

# User-specific files
*.rsuser
Expand Down
4 changes: 4 additions & 0 deletions src/CarpaNet.SourceGen/CarpaNet.SourceGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="CarpaNet.UnitTests, PublicKey=00240000048000009400000006020000002400005253413100040000010001005311bd88d09f39da8d0a7814421594e8769c2c6af9b162a58a5c531868178ee6f8c3a108ffef4035eebe195bc06615043564b1c319b5b83be9ee8fae7f99a5b0b52cab19f8aabb66acbe9384dfda7a5d359e6b34ac3f7907db45f2c0c33c2bb4290ca55adc414a1823888a92d9b9f61c32f48d391be17000f3032e0b5146b48b" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="System.Text.Json" PrivateAssets="all" GeneratePathProperty="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/CarpaNet.SourceGen/Generation/JsonContextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ private static void GenerateListTypeFactory(
dispatchLines.Add($"if (type == typeof({globalList})) return Create_BuiltIn_{safeName}_TypeInfo(options);");
}

private static string ToBuiltInSuffix(string typeName)
internal static string ToBuiltInSuffix(string typeName)
{
return typeName switch
{
Expand All @@ -809,7 +809,7 @@ private static string ToBuiltInSuffix(string typeName)
"int" => "Int32",
"byte[]" => "ByteArray",
"object" => "Object",
_ => typeName.Replace(".", "_").Replace("@", "")
_ => typeName.Replace(".", "_").Replace("@", "").Replace("<", "_").Replace(">", "_")
};
}
}
33 changes: 33 additions & 0 deletions tests/CarpaNet.UnitTests/Generation/JsonContextGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using CarpaNet.Generation;

using Xunit;

namespace CarpaNet.UnitTests.Generation;

public class JsonContextGeneratorTests
{
[Theory]
[InlineData("string", "String")]
[InlineData("long", "Int64")]
[InlineData("bool", "Boolean")]
[InlineData("int", "Int32")]
[InlineData("byte[]", "ByteArray")]
[InlineData("object", "Object")]
[InlineData("System.DateTimeOffset", "System_DateTimeOffset")]
[InlineData("System.Collections.Generic.List<string>", "System_Collections_Generic_List_string_")]
public void ToBuiltInSuffix_ProducesValidIdentifier(string typeName, string expected)
{
var result = JsonContextGenerator.ToBuiltInSuffix(typeName);
Assert.Equal(expected, result);
}

[Fact]
public void ToBuiltInSuffix_NestedGenericType_SanitizesAngleBrackets()
{
var result = JsonContextGenerator.ToBuiltInSuffix("System.Collections.Generic.List<string>");

Assert.DoesNotContain("<", result);
Assert.DoesNotContain(">", result);
Assert.Equal("System_Collections_Generic_List_string_", result);
}
}
Loading