Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Dec 6, 2023
1 parent 70faced commit 014e279
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
BUILD_PATH: '${{github.workspace}}/artifacts'
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

on:
push:
Expand Down Expand Up @@ -42,6 +43,13 @@ jobs:
- name: Run Test
run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings

- name: Report Coverage
if: success()
uses: coverallsapp/github-action@v2
with:
file: "${{github.workspace}}/test/*/TestResults/*/coverage.info"
format: lcov

- name: Create Packages
if: success() && github.event_name != 'pull_request'
run: dotnet pack --configuration Release --include-symbols --include-source --no-build --no-restore --output "${{env.BUILD_PATH}}"
Expand Down
5 changes: 3 additions & 2 deletions src/AssemblyMetadata.Generators/AssemblyMetadataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Versioning;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace AssemblyMetadata.Generators;
Expand Down Expand Up @@ -83,7 +84,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex
name = name.Substring(0, name.Length - 9);

var argument = attribute.ConstructorArguments.FirstOrDefault();
var value = argument.Value?.ToString() ?? string.Empty;
var value = argument.ToCSharpString() ?? string.Empty;

if (string.IsNullOrWhiteSpace(value))
continue;
Expand All @@ -97,7 +98,7 @@ private static GeneratorContext SemanticTransform(GeneratorAttributeSyntaxContex
var key = nameArgument.Value?.ToString() ?? string.Empty;

var valueArgument = attribute.ConstructorArguments[1];
var value = valueArgument.Value?.ToString() ?? string.Empty;
var value = valueArgument.ToCSharpString() ?? string.Empty;

if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
continue;
Expand Down
15 changes: 3 additions & 12 deletions src/AssemblyMetadata.Generators/AssemblyMetadataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ public static string Generate(EquatableArray<AssemblyConstant> constants)
foreach (var constant in constants)
{
var name = SafeName(constant.Name);
var value = SafeValue(constant.Value);

codeBuilder
.Append("public const string ")
.Append(name)
.Append(" = \"")
.Append(value)
.AppendLine("\";")
.Append(" = ")
.Append(constant.Value)
.AppendLine(";")
.AppendLine();
}

Expand All @@ -67,14 +66,6 @@ public static string SafeName(string name)
return ToPropertyName(name.AsSpan());
}

public static string SafeValue(string value)
{
return value
.Replace("\\", "\\\\")
.Replace("\"", "\\\"")
.Replace(Environment.NewLine, "\\r\\n");
}

public static string ToPropertyName(ReadOnlySpan<char> span)
{
if (span.IsEmpty)
Expand Down
9 changes: 0 additions & 9 deletions test/AssemblyMetadata.Generators.Tests/PropertyNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,4 @@ public void PropertyName(string input, string expected)
var actual = AssemblyMetadataWriter.ToPropertyName(input);
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("Name\\Test", "Name\\\\Test")]
[InlineData("Name\"Test\"", "Name\\\"Test\\\"")]
public void SafeValue(string input, string expected)
{
var actual = AssemblyMetadataWriter.SafeValue(input);
Assert.Equal(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal static partial class ThisAssembly

public const string HardKey = "HardValue";

public const string VerifyTargetFrameworks = "";

public const string VerifyProjectDirectory = "D:\\Projects\\GitHub\\AssemblyMetadata.Generators\\test\\AssemblyMetadata.Generators.Tests\\";

public const string VerifySolutionDirectory = "D:\\Projects\\GitHub\\AssemblyMetadata.Generators\\";
Expand Down

0 comments on commit 014e279

Please sign in to comment.