-
Notifications
You must be signed in to change notification settings - Fork 0
Add opt-in EmitShapeTag support
#49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sator-imaging
merged 12 commits into
main
from
codex/add-emitshapetag-to-zeroserializerattribute
Aug 12, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ed755e8
Add opt-in ShapeTag emission
sator-imaging bb64554
Apply suggestion from @sator-imaging
sator-imaging edf0209
Apply suggestion from @sator-imaging
sator-imaging 211d692
Apply suggestion from @sator-imaging
sator-imaging 0675a6b
Apply suggestion from @sator-imaging
sator-imaging 754bc9f
Apply suggestion from @sator-imaging
sator-imaging a265976
Apply suggestions from code review
sator-imaging 05ded50
Apply suggestion from @sator-imaging
sator-imaging e63ae66
Apply suggestion from @sator-imaging
sator-imaging d640c54
Apply suggestion from @sator-imaging
sator-imaging 5a2352c
Apply suggestion from @sator-imaging
sator-imaging 172c682
Apply suggestion from @sator-imaging
sator-imaging File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Licensed under the Apache-2.0 License | ||
| // https://github.com/sator-imaging/ZeroSerializer | ||
|
|
||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
| using System; | ||
| using System.Linq; | ||
| using Xunit; | ||
| using ZeroSerializer.Generator; | ||
|
|
||
| #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
|
||
| namespace ZeroSerializer.Tests; | ||
|
|
||
| public class ShapeTagEmissionTests | ||
| { | ||
| [Fact] | ||
| public void ShapeTagIsCommentedOutByDefault() | ||
| { | ||
| string generatedView = GenerateView("[ZeroSerializer.ZeroSerializer] public class Record { public int Value { get; set; } }"); | ||
|
|
||
| Assert.DoesNotContain("/// <remarks>", generatedView); | ||
| Assert.DoesNotContain(" public const string ShapeTag", generatedView); | ||
| Assert.Contains("// To emit this, `set EmitShapeTag = true` on ZeroSerializerAttribute.", generatedView); | ||
| Assert.Contains("// public const string ShapeTag = \"v1/{int}\";", generatedView); | ||
| Assert.Contains("public const uint ShapeHash = ", generatedView); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ShapeTagAndRemarksAreEmittedWhenRequested() | ||
| { | ||
| string generatedView = GenerateView("[ZeroSerializer.ZeroSerializer(EmitShapeTag = true)] public class Record { public int Value { get; set; } }"); | ||
|
|
||
| Assert.DoesNotContain("// public const string ShapeTag", generatedView); | ||
| Assert.Contains("/// <remarks>", generatedView); | ||
| Assert.Contains("/// ShapeTag: v1/{int}", generatedView); | ||
| Assert.Contains("public const string ShapeTag = \"v1/{int}\";", generatedView); | ||
| Assert.Contains("public const uint ShapeHash = ", generatedView); | ||
|
sator-imaging marked this conversation as resolved.
|
||
| } | ||
|
sator-imaging marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public void InjectedAttributeExposesObsoleteEmitShapeTagField() | ||
| { | ||
| GeneratorDriverRunResult result = RunGenerator("public class Record { }"); | ||
| string generatedAttribute = result.Results[0].GeneratedSources | ||
| .Single(source => source.HintName == "- ZeroSerializerAttribute.g.cs") | ||
| .SourceText | ||
| .ToString(); | ||
|
|
||
| Assert.Contains("public bool EmitShapeTag;", generatedAttribute); | ||
| Assert.Contains("[Obsolete(\"Emitting string representation of the type will expose internal details", generatedAttribute); | ||
| Assert.Contains("public ZeroSerializerAttribute() { }", generatedAttribute); | ||
| } | ||
|
|
||
| private static string GenerateView(string source) | ||
| { | ||
| GeneratorDriverRunResult result = RunGenerator(source); | ||
| return result.Results[0].GeneratedSources | ||
| .Single(generatedSource => generatedSource.HintName == "Record.ZeroSerializer.g.cs") | ||
| .SourceText | ||
| .ToString(); | ||
| } | ||
|
|
||
| private static GeneratorDriverRunResult RunGenerator(string source) | ||
| { | ||
| SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source); | ||
| CSharpCompilation compilation = CSharpCompilation.Create( | ||
| "ShapeTagEmissionTests", | ||
| new[] { syntaxTree }, | ||
| new[] { MetadataReference.CreateFromFile(typeof(Attribute).Assembly.Location) }); | ||
| GeneratorDriver driver = CSharpGeneratorDriver.Create(new ZeroSerializerGenerator()); | ||
| return driver.RunGenerators(compilation).GetRunResult(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.