Skip to content

Commit

Permalink
Merge pull request #15 from tpwalke2/dotnet-8
Browse files Browse the repository at this point in the history
.NET 8
  • Loading branch information
tpwalke2 authored Dec 18, 2023
2 parents 82b2053 + 349508d commit 013a329
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 38 deletions.
13 changes: 7 additions & 6 deletions CodePointEnumGenerator.Tests/CodePointEnumGenerator.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<LangVersion>12</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
16 changes: 9 additions & 7 deletions CodePointEnumGenerator.Tests/CodePointEnumGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ public void ShouldBuildEnumForCodePoints()
{
var result = GeneratorTestFactory.RunGenerator(
"",
("TestEnum.codepoints", @"9mp e979
abc eb94
ac_unit eb3b
access_alarm e190
access_alarms e191
access_time e192
access_time_filled efd6"));
("TestEnum.codepoints", """
9mp e979
abc eb94
ac_unit eb3b
access_alarm e190
access_alarms e191
access_time e192
access_time_filled efd6
"""));
Assert.NotNull(
result.RunResult?.GeneratedTrees.FirstOrDefault(t => t.FilePath.Contains("TestEnum")));
}
Expand Down
5 changes: 1 addition & 4 deletions CodePointEnumGenerator.Tests/GeneratorTestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ namespace CodePointEnumGenerator.Tests;

public static class GeneratorTestFactory
{
private static readonly HashSet<string> IgnoredPreDiagnosticErrors = new()
{
"CS0012", "CS0616", "CS0246", "CS0103"
};
private static readonly HashSet<string> IgnoredPreDiagnosticErrors = ["CS0012", "CS0616", "CS0246", "CS0103"];

public static (Compilation? Compilation,
(ImmutableArray<Diagnostic> Before, ImmutableArray<Diagnostic> After) Diagnostics,
Expand Down
30 changes: 20 additions & 10 deletions CodePointEnumGenerator.Tests/Helpers/GetEnumValuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class GetEnumValuesTests
[Fact]
public void MultipleUniqueValues()
{
const string content = @"add e001
delete e002";
const string content = """
add e001
delete e002
""";
var result = content.GetEnumValues().ToArray();

Assert.Equal(2, result.Length);
Expand All @@ -23,8 +25,10 @@ public void MultipleUniqueValues()
[Fact]
public void RemoveUnderscores()
{
const string content = @"add_comment e001
delete_comment_by_user e002";
const string content = """
add_comment e001
delete_comment_by_user e002
""";
var result = content.GetEnumValues().ToArray();

Assert.Equal(2, result.Length);
Expand All @@ -37,8 +41,10 @@ public void RemoveUnderscores()
[Fact]
public void DuplicateValues()
{
const string content = @"add e001
add e002";
const string content = """
add e001
add e002
""";
var result = content.GetEnumValues().ToArray();

Assert.Equal(2, result.Length);
Expand All @@ -51,8 +57,10 @@ public void DuplicateValues()
[Fact]
public void MissingValue()
{
const string content = @"add
delete e002";
const string content = """
add
delete e002
""";
var result = content.GetEnumValues().ToArray();

Assert.Single(result);
Expand All @@ -63,8 +71,10 @@ public void MissingValue()
[Fact]
public void NumericPrefix()
{
const string content = @"1add e001
2delete e002";
const string content = """
1add e001
2delete e002
""";
var result = content.GetEnumValues().ToArray();

Assert.Equal(2, result.Length);
Expand Down
4 changes: 2 additions & 2 deletions CodePointEnumGenerator.Tests/Helpers/ToNamespaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ToNamespaceTests
[InlineData(@"C:\Source\SongBook\Fonts\", "Source.SongBook.Fonts")]
[InlineData(@"C:\Source\SongBook\Fonts", "Source.SongBook")]
[InlineData(@"C:\", "")]
[InlineData(@"C:", "")]
[InlineData(@"", "")]
[InlineData("C:", "")]
[InlineData("", "")]
public void ToNamespace(string input, string expectedOutput)
{
Assert.Equal(expectedOutput, input.ToNamespace());
Expand Down
4 changes: 2 additions & 2 deletions CodePointEnumGenerator/CodePointEnumGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<IsRoslynComponent>true</IsRoslynComponent>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
</ItemGroup>

Expand Down
18 changes: 11 additions & 7 deletions CodePointEnumGenerator/Helpers/CodeGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ public static string BuildEnumFileContents(
string enumName,
IEnumerable<(string, string)> values,
string @namespace) => new StringBuilder()
.Append($@"
namespace {@namespace};
.Append($$"""
public enum {enumName} {{
")
namespace {{@namespace}};
public enum {{enumName}} {
""")
.Append(string.Join(
",\n",
values.Select(tuple => $@" {tuple.Item1} = 0x{tuple.Item2}")))
.Append(@"
}")
values.Select(tuple => $" {tuple.Item1} = 0x{tuple.Item2}")))
.Append("""
}
""")
.ToString();
}

0 comments on commit 013a329

Please sign in to comment.