TestCaseAttribute to support sets
Closed this issue · 1 comments
joerg-github commented
I like to request the feature that TestCaseAttribute works with sets.
TTestEnum = (teOne, teTwo, teThree);
TTestEnums = set of TTestEnum;
[TestCaseAttribute('Test case 1', '[teOne, teThree]'), '|']
procedure TestCase(Value: TTestEnums);
The following converter needs to be added:
function ConvStr2Set(const ASource: TValue; ATarget: PTypeInfo; out AResult: TValue): Boolean;
var
pInt: PInteger;
begin
AResult := TValue.From(0, ATarget);
pInt := AResult.GetReferenceToRawData;
pInt^ := StringToSet(ATarget, Asource.AsString);
Result := True;
end;
The conversion array needs to get this change.
// tkUString
(
// tkUnknown, tkInteger, tkChar, tkEnumeration, tkFloat, tkString,
ConvFail, ConvStr2Int, ConvFail, ConvStr2Enum, ConvStr2Float, ConvFail,
// tkSet, tkClass, tkMethod, tkWChar, tkLString, tkWString
ConvStr2Set, ConvFail, ConvFail, ConvFail, ConvFail, ConvFail,
// tkVariant, tkArray, tkRecord, tkInterface, tkInt64, tkDynArray
ConvFail, ConvFail, ConvFail, ConvFail, ConvStr2Ord, {$IFDEF DELPHI_XE3_UP}ConvStr2DynArray{$ELSE}ConvFail{$ENDIF},
// tkUString, tkClassRef, tkPointer, tkProcedure, tkMRecord
ConvFail, ConvFail, ConvFail, ConvFail {$IFDEF DELPHI_XE103_UP}, ConvFail{$ENDIF}
),
vincentparrett commented
Happy to accept a PR for this - be sure to add a unit test that shows the usage of this.