Types added to Tuples

This commit is contained in:
Michael Schimmel
2025-08-27 16:05:13 +02:00
parent 284fb95985
commit dc4066097c
5 changed files with 290 additions and 190 deletions
+6 -10
View File
@@ -172,7 +172,7 @@ begin
floatValue := TDataType.Float.CreateValue(45.67);
// --- 2. Test Value Creation and basic properties ---
tuple1 := TDataType.Tuple.CreateValue([intValue, floatValue]);
tuple1 := TDataType.TupleOf([intValue, floatValue]);
Assert.IsNotNull(IDataTupleValue(tuple1), 'Tuple value should be created');
Assert.AreEqual(2, tuple1.ItemCount, 'ItemCount should be on the value');
@@ -181,8 +181,8 @@ begin
// --- 3. Test Singleton Type Behavior ---
// Create more tuples with different structures
tuple2 := TDataType.Tuple.CreateValue([TDataType.Ordinal.CreateValue(99), TDataType.Float.CreateValue(1.1)]);
tuple3 := TDataType.Tuple.CreateValue([intValue]);
tuple2 := TDataType.TupleOf([TDataType.Ordinal.CreateValue(99), TDataType.Float.CreateValue(1.1)]);
tuple3 := TDataType.TupleOf([intValue]);
// Access the DataType via the underlying interface
type1 := tuple1.DataType;
@@ -190,11 +190,7 @@ begin
type3 := tuple3.DataType;
Assert.IsNotNull(type1, 'DataType interface should be accessible');
Assert.AreEqual('Tuple', type1.Name, 'The type name for all tuples should be Tuple');
// The core test: All tuples, regardless of their content, must share the exact same singleton type object.
Assert.AreSame(type1, type2, 'All tuple types should be the same singleton instance');
Assert.AreSame(type1, type3, 'All tuple types should be the same singleton instance');
Assert.AreEqual('Tuple<Integer, Float>', type1.Name, 'The type name for all tuples should be Tuple');
end;
procedure TMyTestObject.TestTuples_Generic;
@@ -204,7 +200,7 @@ var
begin
// Test the generic implementation for tuples with > 5 elements.
tupleValue :=
TDataType.Tuple.CreateValue(
TDataType.TupleOf(
[
TDataType.Ordinal.CreateValue(1),
TDataType.Ordinal.CreateValue(2),
@@ -542,7 +538,7 @@ begin
Assert.AreEqual('<ID: 1, Name: Bob>', IDataValue(recordValue).AsString, 'Record AsString incorrect');
// Tuple
tupleValue := TDataType.Tuple.CreateValue([TDataType.Ordinal.CreateValue(10), TDataType.Text.CreateValue('Tuple')]);
tupleValue := TDataType.TupleOf([TDataType.Ordinal.CreateValue(10), TDataType.Text.CreateValue('Tuple')]);
Assert.AreEqual('(10, Tuple)', IDataValue(tupleValue).AsString, 'Tuple AsString incorrect');
end;