Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/bindings-csharp/Codegen.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ public static async Task TypeAndModuleGeneratorsOnServer()
AssertNoCs0436Diagnostics(compilationWithUserCode);
}

[Fact]
public static async Task SettingsAndExplicitNames()
{
var fixture = await Fixture.Compile("explicitnames");

var compilationAfterGen = await fixture.RunAndCheckGenerators(
new SpacetimeDB.Codegen.Type(),
new SpacetimeDB.Codegen.Module()
);

Assert.Empty(GetCompilationErrors(compilationAfterGen));

AssertPublicBoundIsAvailableInRuntime(compilationAfterGen);
AssertRuntimeDoesNotDefineLocal(compilationAfterGen);
AssertGeneratedCodeDoesNotUseInternalBound(compilationAfterGen);
}

[Fact]
public static async Task TestDiagnostics()
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions crates/bindings-csharp/Codegen.Tests/fixtures/explicitnames/Lib.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using SpacetimeDB;

#pragma warning disable CA1050 // Declare types in namespaces - this is a test fixture, no need for a namespace.

public static partial class Module
{
[SpacetimeDB.Settings]
public const SpacetimeDB.Internal.CaseConversionPolicy CASE_CONVERSION_POLICY = SpacetimeDB
.Internal
.CaseConversionPolicy
.SnakeCase;
}

[SpacetimeDB.Type]
public partial struct DemoType
{
public int A;
}

[SpacetimeDB.Table(Accessor = "DemoTable", Name = "canonical_table", Public = true)]
public partial struct DemoTable
{
[SpacetimeDB.PrimaryKey]
[SpacetimeDB.Index.BTree(Accessor = "ById", Name = "canonical_index")]
public int Id;

public int Value;
}

public static partial class Reducers
{
[SpacetimeDB.Reducer(Name = "canonical_reducer")]
public static void DemoReducer(ReducerContext ctx, int value)
{
ctx.Db.DemoTable.Insert(new DemoTable { Id = value, Value = value });
}

[SpacetimeDB.Procedure(Name = "canonical_procedure")]
public static void DemoProcedure(ProcedureContext ctx) { }

[SpacetimeDB.View(Accessor = "demo_view", Name = "canonical_view", Public = true)]
public static List<DemoTable> DemoView(ViewContext ctx)
{
return new List<DemoTable>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../../BSATN.Runtime/BSATN.Runtime.csproj" />
<ProjectReference Include="../../../Runtime/Runtime.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//HintName: DemoTable.cs
// <auto-generated />
#nullable enable

partial struct DemoTable : System.IEquatable<DemoTable>, SpacetimeDB.BSATN.IStructuralReadWrite
{
public void ReadFields(System.IO.BinaryReader reader)
{
Id = BSATN.IdRW.Read(reader);
Value = BSATN.ValueRW.Read(reader);
}

public void WriteFields(System.IO.BinaryWriter writer)
{
BSATN.IdRW.Write(writer, Id);
BSATN.ValueRW.Write(writer, Value);
}

object SpacetimeDB.BSATN.IStructuralReadWrite.GetSerializer()
{
return new BSATN();
}

public override string ToString() =>
$"DemoTable {{ Id = {SpacetimeDB.BSATN.StringUtil.GenericToString(Id)}, Value = {SpacetimeDB.BSATN.StringUtil.GenericToString(Value)} }}";

public readonly partial struct BSATN : SpacetimeDB.BSATN.IReadWrite<DemoTable>
{
internal static readonly SpacetimeDB.BSATN.I32 IdRW = new();
internal static readonly SpacetimeDB.BSATN.I32 ValueRW = new();

public DemoTable Read(System.IO.BinaryReader reader)
{
var ___result = new DemoTable();
___result.ReadFields(reader);
return ___result;
}

public void Write(System.IO.BinaryWriter writer, DemoTable value)
{
value.WriteFields(writer);
}

public SpacetimeDB.BSATN.AlgebraicType.Ref GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) =>
registrar.RegisterType<DemoTable>(_ => new SpacetimeDB.BSATN.AlgebraicType.Product(
new SpacetimeDB.BSATN.AggregateElement[]
{
new("Id", IdRW.GetAlgebraicType(registrar)),
new("Value", ValueRW.GetAlgebraicType(registrar))
}
));

SpacetimeDB.BSATN.AlgebraicType SpacetimeDB.BSATN.IReadWrite<DemoTable>.GetAlgebraicType(
SpacetimeDB.BSATN.ITypeRegistrar registrar
) => GetAlgebraicType(registrar);
}

public override int GetHashCode()
{
var ___hashId = Id.GetHashCode();
var ___hashValue = Value.GetHashCode();
return ___hashId ^ ___hashValue;
}

#nullable enable
public bool Equals(DemoTable that)
{
var ___eqId = this.Id.Equals(that.Id);
var ___eqValue = this.Value.Equals(that.Value);
return ___eqId && ___eqValue;
}

public override bool Equals(object? that)
{
if (that == null)
{
return false;
}
var that_ = that as DemoTable?;
if (((object?)that_) == null)
{
return false;
}
return Equals(that_);
}

public static bool operator ==(DemoTable this_, DemoTable that)
{
if (((object?)this_) == null || ((object?)that) == null)
{
return object.Equals(this_, that);
}
return this_.Equals(that);
}

public static bool operator !=(DemoTable this_, DemoTable that)
{
if (((object?)this_) == null || ((object?)that) == null)
{
return !object.Equals(this_, that);
}
return !this_.Equals(that);
}
#nullable restore
} // DemoTable
Loading
Loading