-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As I could test, TypeScript folow the same C# sequence numbering when enum value is missing in declaring type.
- Loading branch information
Rodrigo Cesar
committed
May 27, 2024
1 parent
82fcc81
commit 96f4f91
Showing
3 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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,43 @@ | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using NUnit.Framework; | ||
|
||
namespace CSharpModelsToJson.Tests | ||
{ | ||
[TestFixture] | ||
public class EnumCollectorTest | ||
{ | ||
[Test] | ||
public void ReturnEnumWithMissingValues() | ||
{ | ||
var tree = CSharpSyntaxTree.ParseText(@" | ||
public enum SampleEnum | ||
{ | ||
A, | ||
B = 7, | ||
C, | ||
D = 4, | ||
E | ||
}" | ||
); | ||
|
||
var root = (CompilationUnitSyntax)tree.GetRoot(); | ||
|
||
var enumCollector = new EnumCollector(); | ||
enumCollector.VisitEnumDeclaration(root.DescendantNodes().OfType<EnumDeclarationSyntax>().First()); | ||
|
||
var model = enumCollector.Enums.First(); | ||
|
||
Assert.That(model, Is.Not.Null); | ||
Assert.That(model.Values, Is.Not.Null); | ||
|
||
var values = model.Values.ToArray(); | ||
Assert.That(values[0].Value, Is.Null); | ||
Assert.That(values[1].Value, Is.EqualTo("7")); | ||
Assert.That(values[2].Value, Is.Null); | ||
Assert.That(values[3].Value, Is.EqualTo("4")); | ||
Assert.That(values[4].Value, Is.Null); | ||
} | ||
} | ||
} |