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
19 changes: 19 additions & 0 deletions crates/bindings-csharp/BSATN.Codegen/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public static TypeUse Parse(ISymbol member, ITypeSymbol typeSymbol, DiagReporter
typeInfo,
Parse(member, named.TypeArguments[0], diag)
),
"System.Nullable<T>" => new NullableUse(type, typeInfo),
_ => named.IsValueType
? (
named.TypeKind == Microsoft.CodeAnalysis.TypeKind.Enum
Expand Down Expand Up @@ -182,6 +183,24 @@ public override string GetHashCodeStatement(string inVar, string outVar, int lev
$"var {outVar} = {inVar}.GetHashCode();";
}

/// <summary>
/// A use of a nullable value type (e.g. <c>int?</c>, <c>MyStruct?</c>).
/// </summary>
/// <param name="Type"></param>
/// <param name="TypeInfo"></param>
public record NullableUse(string Type, string TypeInfo) : TypeUse(Type, TypeInfo)
{
public override string EqualsStatement(
string inVar1,
string inVar2,
string outVar,
int level = 0
) => $"var {outVar} = System.Nullable.Equals({inVar1}, {inVar2});";

public override string GetHashCodeStatement(string inVar, string outVar, int level = 0) =>
$"var {outVar} = {inVar}.GetHashCode();";
}

/// <summary>
/// A use of a reference type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ public bool Equals(PublicTable that)
}
}
}
var ___eqNullableValueField = this.NullableValueField.Equals(that.NullableValueField);
var ___eqNullableValueField = System.Nullable.Equals(
this.NullableValueField,
that.NullableValueField
);
var ___eqNullableReferenceField =
this.NullableReferenceField == null
? that.NullableReferenceField == null
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ public bool Equals(PublicTable that)
}
}
}
var ___eqNullableValueField = this.NullableValueField.Equals(that.NullableValueField);
var ___eqNullableValueField = System.Nullable.Equals(
this.NullableValueField,
that.NullableValueField
);
var ___eqNullableReferenceField =
this.NullableReferenceField == null
? that.NullableReferenceField == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public bool Equals(CustomClass? that)
this.StringField == null
? that.StringField == null
: this.StringField.Equals(that.StringField);
var ___eqNullableIntField = this.NullableIntField.Equals(that.NullableIntField);
var ___eqNullableIntField = System.Nullable.Equals(
this.NullableIntField,
that.NullableIntField
);
var ___eqNullableStringField =
this.NullableStringField == null
? that.NullableStringField == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ public bool Equals(CustomNestedClass? that)
? that.NestedNullableClass == null
: this.NestedNullableClass.Equals(that.NestedNullableClass);
var ___eqNestedEnum = this.NestedEnum == that.NestedEnum;
var ___eqNestedNullableEnum = this.NestedNullableEnum.Equals(that.NestedNullableEnum);
var ___eqNestedNullableEnum = System.Nullable.Equals(
this.NestedNullableEnum,
that.NestedNullableEnum
);
var ___eqNestedTaggedEnum =
this.NestedTaggedEnum == null
? that.NestedTaggedEnum == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public bool Equals(CustomRecord? that)
this.StringField == null
? that.StringField == null
: this.StringField.Equals(that.StringField);
var ___eqNullableIntField = this.NullableIntField.Equals(that.NullableIntField);
var ___eqNullableIntField = System.Nullable.Equals(
this.NullableIntField,
that.NullableIntField
);
var ___eqNullableStringField =
this.NullableStringField == null
? that.NullableStringField == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ public bool Equals(CustomStruct that)
this.StringField == null
? that.StringField == null
: this.StringField.Equals(that.StringField);
var ___eqNullableIntField = this.NullableIntField.Equals(that.NullableIntField);
var ___eqNullableIntField = System.Nullable.Equals(
this.NullableIntField,
that.NullableIntField
);
var ___eqNullableStringField =
this.NullableStringField == null
? that.NullableStringField == null
Expand Down
66 changes: 65 additions & 1 deletion sdks/csharp/examples~/regression-tests/client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Regression tests run with a live server.
/// Regression tests run with a live server.
/// To run these, run a local SpacetimeDB via `spacetime start`,
/// then in a separate terminal run `tools~/run-regression-tests.sh PATH_TO_SPACETIMEDB_REPO_CHECKOUT`.
/// This is done on CI in .github/workflows/test.yml.
Expand Down Expand Up @@ -65,6 +65,7 @@ void OnConnected(DbConnection conn, Identity identity, string authToken)
"SELECT * FROM players_at_level_one",
"SELECT * FROM my_table",
"SELECT * FROM Admins",
"SELECT * FROM nullable_vec_view",
]);

// If testing against Rust, the indexed parameter will need to be changed to: ulong indexed
Expand All @@ -87,6 +88,21 @@ void OnConnected(DbConnection conn, Identity identity, string authToken)
Log.Info($"Got OnUnhandledReducerError: {exception}");
waiting--;
ValidateBTreeIndexes(ctx);
ValidateNullableVecView(ctx);
};

conn.Reducers.OnSetNullableVec += (ReducerEventContext ctx, uint id, bool hasPos, int x, int y) =>
{
Log.Info("Got SetNullableVec callback");
waiting--;
if (id == 1)
{
ValidateNullableVecView(ctx, hasPos, x, y);
}
else
{
ValidateNullableVecView(ctx);
}
};
}

Expand All @@ -113,6 +129,44 @@ void ValidateBTreeIndexes(IRemoteDbContext conn)
Log.Debug(" Indexes are good.");
}

void ValidateNullableVecView(
IRemoteDbContext conn,
bool? expectedHasPos = null,
int expectedX = 0,
int expectedY = 0
)
{
Log.Debug("Checking nullable vec view...");
Debug.Assert(conn.Db.NullableVecView != null, "conn.Db.NullableVecView != null");
Debug.Assert(
conn.Db.NullableVecView.Count >= 2,
$"conn.Db.NullableVecView.Count = {conn.Db.NullableVecView.Count}"
);

var rows = conn.Db.NullableVecView.Iter().ToList();
Debug.Assert(rows.Any(r => r.Id == 1));
Debug.Assert(rows.Any(r => r.Id == 2));

var remoteRows = conn.Db.NullableVecView.RemoteQuery("WHERE Id = 1").Result;
Debug.Assert(remoteRows != null && remoteRows.Length == 1);
Debug.Assert(remoteRows[0].Id == 1);

if (expectedHasPos is bool hasPos)
{
var row1 = rows.First(r => r.Id == 1);
if (!hasPos)
{
Debug.Assert(row1.Pos == null, "Expected NullableVecView row 1 Pos == null");
}
else
{
Debug.Assert(row1.Pos != null, "Expected NullableVecView row 1 Pos != null");
Debug.Assert(row1.Pos.X == expectedX, $"Expected row1.Pos.X == {expectedX}, got {row1.Pos.X}");
Debug.Assert(row1.Pos.Y == expectedY, $"Expected row1.Pos.Y == {expectedY}, got {row1.Pos.Y}");
}
}
}

void OnSubscriptionApplied(SubscriptionEventContext context)
{
applied = true;
Expand Down Expand Up @@ -160,6 +214,8 @@ void OnSubscriptionApplied(SubscriptionEventContext context)
Debug.Assert(context.Db.Admins != null, "context.Db.Admins != null");
Debug.Assert(context.Db.Admins.Count > 0, $"context.Db.Admins.Count = {context.Db.Admins.Count}");

ValidateNullableVecView(context, expectedHasPos: true, expectedX: 1, expectedY: 2);

Log.Debug("Calling Iter on View");
var viewIterRows = context.Db.MyPlayer.Iter();
var expectedPlayer = new Player
Expand Down Expand Up @@ -230,6 +286,14 @@ void OnSubscriptionApplied(SubscriptionEventContext context)
Debug.Assert(anonViewRemoteQueryRows != null && anonViewRemoteQueryRows.Result.Length > 0);
Debug.Assert(anonViewRemoteQueryRows.Result.First().Equals(expectedPlayerAndLevel));

Log.Debug("Calling SetNullableVec (null)");
waiting++;
context.Reducers.SetNullableVec(1, false, 0, 0);

Log.Debug("Calling SetNullableVec (some)");
waiting++;
context.Reducers.SetNullableVec(1, true, 7, 8);

// Procedures tests
Log.Debug("Calling InsertWithTxRollback");
waiting++;
Expand Down

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

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

Loading
Loading