Skip to content

Commit

Permalink
Change all public types in namespace Cysharp.Text to internal (#372)
Browse files Browse the repository at this point in the history
* Change all public types in namespace Cysharp.Text to internal

* Regression caused by #368
* Stop namespace collision with Cysharp.Text nuget package
* Affects: class, struct, interface, delegate, enum
* using https://github.com/zzzprojects/findandreplace on command line, so we can automate this step:
"fnr.exe" --cl --dir "SmartFormat.ZString\repo\src\ZString" --fileMask "*.cs,*.tt" --includeSubDirectories --caseSensitive --useRegEx --find "public (?=.*(class |struct |enum |interface |delegate ))" --replace "internal "

* Add a unit test to get an alert when Cysharp.Text objects are public

* Bump version to v3.3.2
  • Loading branch information
axunonb committed Jan 29, 2024
1 parent d217ceb commit 245d3b0
Show file tree
Hide file tree
Showing 43 changed files with 176 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/SonarCloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
# (PRs from forks can't access secrets other than secrets.GITHUB_TOKEN for security reasons)
if: ${{ !github.event.pull_request.head.repo.fork }}
env:
version: '3.3.1'
versionFile: '3.3.1'
version: '3.3.2'
versionFile: '3.3.2'
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for:
- ps: dotnet restore SmartFormat.sln --verbosity quiet
- ps: dotnet add .\SmartFormat.Tests\SmartFormat.Tests.csproj package AltCover
- ps: |
$version = "3.3.1"
$version = "3.3.2"
$versionFile = $version + "." + ${env:APPVEYOR_BUILD_NUMBER}
if ($env:APPVEYOR_PULL_REQUEST_NUMBER) {
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<Copyright>Copyright 2011-$(CurrentYear) SmartFormat Project</Copyright>
<RepositoryUrl>https://github.com/axuno/SmartFormat.git</RepositoryUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Version>3.3.1</Version>
<FileVersion>3.3.1</FileVersion>
<Version>3.3.2</Version>
<FileVersion>3.3.2</FileVersion>
<AssemblyVersion>3.0.0</AssemblyVersion> <!--only update AssemblyVersion with major releases -->
<LangVersion>latest</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
34 changes: 34 additions & 0 deletions src/SmartFormat.ZString.Tests/CysharpText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright SmartFormat Project maintainers and contributors.
// Licensed under the MIT license.
//

using NUnit.Framework;

namespace SmartFormat.ZString.Tests;

[TestFixture]
public class CysharpText
{
/// <summary>
/// To stop namespace collision with Cysharp.Text nuget package,
/// change all public types in namespace Cysharp.Text to internal.
/// This can easily happen when Cysharp.Text is updated in the SmartFormat.ZString project.
/// Using https://github.com/zzzprojects/findandreplace on command line, so we can automate this step:
/// "fnr.exe" --cl --dir "SmartFormat.ZString\repo\src\ZString" --fileMask "*.cs,*.tt" --includeSubDirectories --caseSensitive --useRegEx --find "public (?=.*(class |struct |enum |interface |delegate ))" --replace "internal "
/// </summary>
[Test]
public void Classes_Of_Cysharp_Text_Namespace_Should_Be_Internal()
{
// If this tests fails, you need to run the above command line
// to change all public types in namespace Cysharp.Text to internal
Assert.Multiple(() =>
{
Assert.That(typeof(Cysharp.Text.Utf16ValueStringBuilder).IsPublic, Is.False);
Assert.That(typeof(Cysharp.Text.Utf8ValueStringBuilder).IsPublic, Is.False);
Assert.That(typeof(Cysharp.Text.ZString).IsPublic, Is.False);
Assert.That(typeof(Cysharp.Text.FormatParser).IsPublic, Is.False);
Assert.That(typeof(System.HexConverter).IsPublic, Is.False);
});
}
}
47 changes: 47 additions & 0 deletions src/SmartFormat.ZString.Tests/SmartFormat.ZString.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Unit tests for SmartFormat.ZString</Description>
<AssemblyTitle>SmartFormat.ZString.Tests</AssemblyTitle>
<Authors>axuno gGmbH, Scott Rippey, Bernhard Millauer and other contributors.</Authors>
<TargetFrameworks>net462;net6.0</TargetFrameworks>
<DefineConstants>TRACE;DEBUG;RELEASE</DefineConstants>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<AssemblyName>SmartFormat.ZString.Tests</AssemblyName>
<AssemblyOriginatorKeyFile>../SmartFormat/SmartFormat.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<SignAssembly>true</SignAssembly>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>$(NoWarn);CA1861</NoWarn>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>$(NoWarn);CA1861</NoWarn>
<WarningLevel>4</WarningLevel>
<DefineConstants>RELEASE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\SmartFormat.ZString\SmartFormat.ZString.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/SmartFormat.ZString/SmartFormat.ZString.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>SmartFormat.ZString.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100a1cdb8ba81e1a00f0f9509a8f0c896e0de0da6875652fffd44fb867e6b78fd78c31c6fdb07544b2ae53ed4b56daa90333d32ac14387f7f68d39165da8f99b8c294c1cee1bcc4bbcbe2dd73879824b53708837f425e2bf5c7d2cf868de9548c44871888bf9db5cb425064dda4b17134f8e3b52e1f686315a1832043c7b58fb0ac</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/SmartFormat.ZString/ZStringWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public sealed class ZStringWriter : TextWriter
{
private Utf16ValueStringBuilder sb;
private bool isOpen;
private UnicodeEncoding encoding;
private UnicodeEncoding encoding = null!;

/// <summary>
/// Creates a new instance using <see cref="CultureInfo.CurrentCulture"/> as format provider.
/// </summary>
public ZStringWriter() : this(CultureInfo.CurrentCulture)
{
sb = Cysharp.Text.ZString.CreateStringBuilder();
isOpen = true;
}

/// <summary>
/// Creates a new instance with given format provider.
/// </summary>
public ZStringWriter(IFormatProvider formatProvider) : base(formatProvider)
{
sb = Cysharp.Text.ZString.CreateStringBuilder();
isOpen = true;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SmartFormat.ZString/repo/src/ZString/FormatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class FormatParser
{
// {index[,alignment][:formatString]}

public readonly ref struct ParseResult
internal readonly ref struct ParseResult
{
public readonly int Index;
public readonly ReadOnlySpan<char> FormatString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Cysharp.Text
{
public interface IResettableBufferWriter<T> : IBufferWriter<T>
internal interface IResettableBufferWriter<T> : IBufferWriter<T>
{
void Reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace System.Numerics
/// The methods use hardware intrinsics when available on the underlying platform,
/// otherwise they use optimized software fallbacks.
/// </summary>
public static class BitOperations
internal static class BitOperations
{
// C# no-alloc optimization that directly wraps the data section of the dll (similar to string constants)
// https://github.com/dotnet/roslyn/pull/24621
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System
{
internal static class HexConverter
{
public enum Casing : uint
internal enum Casing : uint
{
// Output [ '0' .. '9' ] and [ 'A' .. 'F' ].
Upper = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static unsafe int SingleToInt32Bits(float value)
return *((int*)&value);
}

public readonly struct FloatingPointInfo
internal readonly struct FloatingPointInfo
{
public static readonly FloatingPointInfo Double = new FloatingPointInfo(
denormalMantissaBits: 52,
Expand Down
Loading

0 comments on commit 245d3b0

Please sign in to comment.