Skip to content

Commit 2b40d5f

Browse files
committed
csharpier
1 parent 22c8b68 commit 2b40d5f

2 files changed

Lines changed: 32 additions & 22 deletions

File tree

crates/bindings-csharp/BSATN.Codegen/Type.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ public static TypeUse Parse(ISymbol member, ITypeSymbol typeSymbol, DiagReporter
7373
Parse(member, named.TypeArguments[0], diag)
7474
),
7575
_ => named.IsValueType
76-
? (named.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum ? new EnumUse(type, typeInfo) : new ValueUse(type, typeInfo))
76+
? (
77+
named.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum
78+
? new EnumUse(type, typeInfo)
79+
: new ValueUse(type, typeInfo)
80+
)
7781
: new ReferenceUse(type, typeInfo),
7882
},
7983
_ => throw new InvalidOperationException($"Unsupported type {type}"),

crates/bindings-csharp/BSATN.Runtime.Tests/Tests.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ public partial record BasicEnum
444444
BasicDataClass U,
445445
BasicDataStruct V,
446446
BasicDataRecord W
447-
)>
448-
{ }
447+
)> { }
449448

450449
static readonly Gen<BasicEnum> GenBasicEnum = Gen.SelectMany<int, BasicEnum>(
451450
Gen.Int[0, 7],
@@ -670,7 +669,6 @@ enum Banana
670669
PisangRaja,
671670
}
672671

673-
674672
[Fact]
675673
public static void EnumSerializationWorks()
676674
{
@@ -830,29 +828,37 @@ partial struct ContainsEnum
830828
public int BananaCount;
831829
}
832830

833-
static readonly Gen<(Banana, int)> GenContainsEnum = Gen.Select(Gen.Enum<Banana>(), Gen.Int[0, 3]);
834-
static readonly Gen<((Banana, int), (Banana, int))> GenTwoContainsEnum = Gen.Select(GenContainsEnum, GenContainsEnum);
831+
static readonly Gen<(Banana, int)> GenContainsEnum = Gen.Select(
832+
Gen.Enum<Banana>(),
833+
Gen.Int[0, 3]
834+
);
835+
static readonly Gen<((Banana, int), (Banana, int))> GenTwoContainsEnum = Gen.Select(
836+
GenContainsEnum,
837+
GenContainsEnum
838+
);
835839

836840
[Fact]
837841
public static void GeneratedEnumEqualsWorks()
838842
{
839-
GenTwoContainsEnum.Sample(example =>
840-
{
841-
var ((b1, c1), (b2, c2)) = example;
842-
var struct1 = new ContainsEnum { TheBanana = b1, BananaCount = c1 };
843-
var struct2 = new ContainsEnum { TheBanana = b2, BananaCount = c2 };
844-
845-
if ((b1, c1) == (b2, c2))
846-
{
847-
Assert.True(struct1.Equals(struct2));
848-
Assert.Equal(struct1, struct2);
849-
}
850-
else
843+
GenTwoContainsEnum.Sample(
844+
example =>
851845
{
852-
Assert.False(struct1.Equals(struct2));
853-
Assert.NotEqual(struct1, struct2);
854-
}
846+
var ((b1, c1), (b2, c2)) = example;
847+
var struct1 = new ContainsEnum { TheBanana = b1, BananaCount = c1 };
848+
var struct2 = new ContainsEnum { TheBanana = b2, BananaCount = c2 };
855849

856-
}, iter: 10_000);
850+
if ((b1, c1) == (b2, c2))
851+
{
852+
Assert.True(struct1.Equals(struct2));
853+
Assert.Equal(struct1, struct2);
854+
}
855+
else
856+
{
857+
Assert.False(struct1.Equals(struct2));
858+
Assert.NotEqual(struct1, struct2);
859+
}
860+
},
861+
iter: 10_000
862+
);
857863
}
858864
}

0 commit comments

Comments
 (0)