Skip to content

Commit

Permalink
Merge pull request #68 from jeromelaban/dev/jela/invariant
Browse files Browse the repository at this point in the history
fix: Use invariant ToLower
  • Loading branch information
dansiegel authored Dec 12, 2024
2 parents 4956c75 + 1e76368 commit e23ba6f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build -c Release

- name: Upload Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: NuGet
path: Artifacts/
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenHelpers/ClassBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ internal override void Write(in CodeWriter writer)
IsSealed ? "sealed" : null,
IsAbstract ? "abstract" : null,
_isPartial ? "partial" : null,
Kind.ToString().ToLower(),
Kind.ToString().ToLowerInvariant(),
$"{Name}{_generics}",
extra
};
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenHelpers/CodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private CodeWriter BuildInternal()
writer.NewLine();

if(_nullable != NullableState.Default)
writer.AppendLine($"#nullable {_nullable}".ToLower());
writer.AppendLine($"#nullable {_nullable}".ToLowerInvariant());

WriteAssemblyAttributes(_assemblyAttributes, ref writer);
if(_topLevel)
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenHelpers/ConstructorBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ internal override void Write(in CodeWriter writer)

var modifier = AccessModifier switch
{
null => Class.AccessModifier.ToString().ToLower(),
null => Class.AccessModifier.ToString().ToLowerInvariant(),
_ => AccessModifier.Code()
};
var parameters = _parameters.Any() ? string.Join(", ", _parameters.Select(x => x.ToString())) : string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/CodeGenHelpers/Internals/AccessibilityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class AccessibilityExtensions
Accessibility.ProtectedAndInternal => "private protected",
Accessibility.ProtectedOrInternal => "protected internal",
Accessibility.NotApplicable => null,
_ => accessModifier.ToString().ToLower()
_ => accessModifier.ToString().ToLowerInvariant()
};

public static string? Code(this Accessibility? accessModifier) =>
Expand Down
15 changes: 15 additions & 0 deletions tests/CodeGenHelpers.Tests/SampleCode/InternalClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace CodeGenHelpers.SampleCode
{
internal partial class InternalClass
{
}
}
34 changes: 33 additions & 1 deletion tests/CodeGenHelpers.Tests/Tests/ClassTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.CodeAnalysis;
using System.Globalization;
using System.Threading;
using Microsoft.CodeAnalysis;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -41,6 +43,36 @@ public void GenerateGenericClassWithConstraint()
MakeAssertion(builder);
}

[Fact]
public void GenerateInternalClass()
{
var builder = CodeBuilder.Create(Namespace)
.AddClass("InternalClass")
.WithAccessModifier(Accessibility.Internal);

MakeAssertion(builder);
}

[Fact]
public void GenerateInternalClassTurkish()
{
var currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");

try
{
var builder = CodeBuilder.Create(Namespace)
.AddClass("InternalClass")
.WithAccessModifier(Accessibility.Internal);

MakeAssertion(builder);
}
finally
{
Thread.CurrentThread.CurrentCulture = currentCulture;
}
}

[Fact]
public void GenerateGenericClassWithComplexConstraint()
{
Expand Down

0 comments on commit e23ba6f

Please sign in to comment.