Skip to content

Commit

Permalink
Merge pull request #44 from jeffijoe/net8
Browse files Browse the repository at this point in the history
Upgrade to .NET 8, update packages, fix unit tests to be culture-invariant
  • Loading branch information
jeffijoe authored Sep 28, 2024
2 parents 14e9a9d + 08b468f commit 13ce061
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 100

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Install dependencies
working-directory: ./src
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
<AssemblyOriginatorKeyFile>../Jeffijoe.MessageFormat/MessageFormat.snk</AssemblyOriginatorKeyFile>
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="data/plurals.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.0.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
</ItemGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void DateFormatter_Custom()
{
var formatter = new CustomValueFormatters
{
Date = (CultureInfo _, object? value, string? _, out string? formatted) =>
Date = (CultureInfo culture, object? value, string? _, out string? formatted) =>
{
// This is just a test, you probably shouldn't be doing this in real workloads.
formatted = $"{value:MMMM d 'in the year' yyyy}";
formatted = ((FormattableString)$"{value:MMMM d 'in the year' yyyy}").ToString(culture);
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void NumberFormatter_Decimal_CustomFormat(decimal number, string expected
{
var formatters = new CustomValueFormatters
{
Number = (CultureInfo _, object? value, string? style, out string? formatted) =>
Number = (CultureInfo culture, object? value, string? style, out string? formatted) =>
{
formatted = string.Format($"{{0:{style}}}", value);
formatted = string.Format(culture, $"{{0:{style}}}", value);
return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.assert" Version="2.5.0" />
<PackageReference Include="xunit.core" Version="2.5.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit.assert" Version="2.9.2" />
<PackageReference Include="xunit.core" Version="2.9.2" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task FormatMessage_with_multiple_tasks()
var t1 = Task.Run(() => MessageFormatter.Format(pattern, new { fileCount = 1 }));
var t2 = Task.Run(() => MessageFormatter.Format(pattern, new { fileCount = 1 }));
var t3 = Task.Run(() => MessageFormatter.Format(pattern, new { fileCount = 5 }));
await Task.WhenAll(t1, t2);
await Task.WhenAll(t1, t2, t3);

Assert.Equal("Copying one file.", t1.Result);
Assert.Equal("Copying one file.", t2.Result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Author: Jeff Hansen <jeff@jeffijoe.com>
// Copyright (C) Jeff Hansen 2015. All rights reserved.

using System;
using System.Linq;
using System.Text;

Expand Down Expand Up @@ -135,6 +136,11 @@ public void ParseLiterals_unclosed_escape_sequence(
")]
public void ParseLiterals_position_and_inner_text(string source, int[] position, string expectedInnerText)
{
// It seems that depending on platform this is compiled on, the actual representation of new lines in the
// string literals can differ, which can make this test fail due to differences.
// This will normalize those changes.
expectedInnerText = expectedInnerText.Replace("\r\n", "\n");

var sb = new StringBuilder(source);
var subject = new LiteralParser();
var actual = subject.ParseLiterals(sb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void ReadLiteralSection_throws_with_invalid_characters(
[InlineData("SupDawg,yeah ", "yeah", 8)]
[InlineData("SupDawg, ", null, 8)]
[InlineData("SupDawg,", null, 8)]
public void ReadLiteralSection_with_offset(string source, string expected, int offset)
public void ReadLiteralSection_with_offset(string source, string? expected, int offset)
{
var literal = new Literal(10, 10, 1, 1, source);
Assert.Equal(expected, PatternParser.ReadLiteralSection(literal, offset, true, out _));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static string FormatInteger(IFormatProvider cultureInfo, object? value)
value switch
{
decimal or float or double => string.Format(cultureInfo, "{0}", Convert.ToInt64(value)),
string s => decimal.TryParse(s, out var parsed) ? FormatInteger(cultureInfo, parsed) : s,
string s => decimal.TryParse(s, NumberStyles.Any, cultureInfo, out var parsed) ? FormatInteger(cultureInfo, parsed) : s,
_ => string.Format(cultureInfo, "{0}", value)
};
}
9 changes: 3 additions & 6 deletions src/Jeffijoe.MessageFormat/Jeffijoe.MessageFormat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
<RepositoryUrl>https://github.com/jeffijoe/messageformat.net</RepositoryUrl>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0;netstandard2.0;netstandard2.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin/$(Configuration)/$(TargetFramework)/$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="6.0.1" />
<PackageReference Include="MinVer" Version="4.3.0">
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="8.0.8" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -29,9 +29,6 @@
<ProjectReference Include="../Jeffijoe.MessageFormat.MetadataGenerator/Jeffijoe.MessageFormat.MetadataGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<PropertyGroup>
<PluralLanguagesMetadataExcludeLocales></PluralLanguagesMetadataExcludeLocales>
</PropertyGroup>
<ItemGroup>
<CompilerVisibleProperty Include="PluralLanguagesMetadataExcludeLocales" />
</ItemGroup>
Expand Down

0 comments on commit 13ce061

Please sign in to comment.