codetools: test GetValuesOfCaseVariable on enum

git-svn-id: trunk@56167 -
This commit is contained in:
mattias 2017-10-23 11:22:14 +00:00
parent c210d57d51
commit f424cce57e
3 changed files with 53 additions and 16 deletions

View File

@ -37,7 +37,7 @@
<PackageName Value="fpcunitconsolerunner"/> <PackageName Value="fpcunitconsolerunner"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="13"> <Units Count="14">
<Unit0> <Unit0>
<Filename Value="runtestscodetools.lpr"/> <Filename Value="runtestscodetools.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -99,6 +99,11 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="TestCompReaderWriterPas"/> <UnitName Value="TestCompReaderWriterPas"/>
</Unit12> </Unit12>
<Unit13>
<Filename Value="testidentcompletion.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestIdentCompletion"/>
</Unit13>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -37,8 +37,9 @@ uses
fdt_objccategory, fdt_objcclass, fdt_objccategory, fdt_objcclass,
{$ENDIF} {$ENDIF}
TestBasicCodetools, TestCTRangeScan, TestPascalParser, TestMethodJumpTool, TestBasicCodetools, TestCTRangeScan, TestPascalParser, TestMethodJumpTool,
TestStdCodetools, TestFindDeclaration, TestCompleteBlock, TestRefactoring, TestStdCodetools, TestFindDeclaration, TestIdentCompletion, TestCompleteBlock,
fdt_arrays, testcodecompletion, TestCompReaderWriterPas; TestRefactoring, TestCodeCompletion, TestCompReaderWriterPas,
fdt_arrays;
const const
ConfigFilename = 'codetools.config'; ConfigFilename = 'codetools.config';

View File

@ -1,25 +1,30 @@
{ {
Test with: Test with:
./runtests --format=plain --suite=TTestCompReaderWriterPas ./runtests --format=plain --suite=TTestCompReaderWriterPas
./runtests --format=plain --suite=TTestCompReaderWriterPas.TestWriteProperties ./runtests --format=plain --suite=TTestCompReaderWriterPas.TestBaseTypesMaxValues
Working:
- integer
- strings
- enum, custom enum range
- set of enum, set of custom enum range
ToDo: ToDo:
- base types - enum: add unit, avoid nameclash with-do
- UTF-8 string - set of boolean
- unicodestring - set of char
- enum - custom integer TColor, add unit, avoid nameclash with-do
- set - method, avoid nameclash with-do
- variant - variant
- datetime - datetime
- TComponent.Left/Right - TComponent.Left/Right
- custom range TColor
- subcomponents - subcomponents
- cycle in subcomponents - cycle in subcomponents
- ancestor - ancestor
- childpos - childpos
- inline component - inline component
- collection - collection
- DefineProperty - DefineProperties
} }
unit TestCompReaderWriterPas; unit TestCompReaderWriterPas;
@ -200,6 +205,7 @@ type
{ TCompBaseTypesCustomStored } { TCompBaseTypesCustomStored }
TCompBaseTypesCustomStored = class(TComponent) TCompBaseTypesCustomStored = class(TComponent)
procedure OnClick(Sender: TObject);
private private
FABoolean: Boolean; FABoolean: Boolean;
FAByte: Byte; FAByte: Byte;
@ -225,6 +231,7 @@ type
FAWordBool: WordBool; FAWordBool: WordBool;
FEnum: TEnum; FEnum: TEnum;
FEnumRg: TEnumRg; FEnumRg: TEnumRg;
FEvent: TNotifyEvent;
FSetOfEnum: TSetOfEnum; FSetOfEnum: TSetOfEnum;
FSetOfEnumRg: TSetOfEnumRg; FSetOfEnumRg: TSetOfEnumRg;
function ABooleanIsStored: Boolean; function ABooleanIsStored: Boolean;
@ -251,6 +258,7 @@ type
function AWordIsStored: Boolean; function AWordIsStored: Boolean;
function EnumIsStored: Boolean; function EnumIsStored: Boolean;
function EnumRgIsStored: Boolean; function EnumRgIsStored: Boolean;
function EventIsStored: Boolean;
function SetOfEnumIsStored: Boolean; function SetOfEnumIsStored: Boolean;
function SetOfEnumRgIsStored: Boolean; function SetOfEnumRgIsStored: Boolean;
public public
@ -280,8 +288,9 @@ type
DefEnumRg: TEnumRg; DefEnumRg: TEnumRg;
DefSetOfEnum: TSetOfEnum; DefSetOfEnum: TSetOfEnum;
DefSetOfEnumRg: TSetOfEnumRg; DefSetOfEnumRg: TSetOfEnumRg;
published DefEvent: TNotifyEvent;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
published
property ABoolean: Boolean read FABoolean write FABoolean stored ABooleanIsStored; property ABoolean: Boolean read FABoolean write FABoolean stored ABooleanIsStored;
property AByteBool: ByteBool read FAByteBool write FAByteBool stored AByteBoolIsStored; property AByteBool: ByteBool read FAByteBool write FAByteBool stored AByteBoolIsStored;
property AWordBool: WordBool read FAWordBool write FAWordBool stored AWordBoolIsStored; property AWordBool: WordBool read FAWordBool write FAWordBool stored AWordBoolIsStored;
@ -308,6 +317,7 @@ type
property EnumRg: TEnumRg read FEnumRg write FEnumRg stored EnumRgIsStored; property EnumRg: TEnumRg read FEnumRg write FEnumRg stored EnumRgIsStored;
property SetOfEnum: TSetOfEnum read FSetOfEnum write FSetOfEnum stored SetOfEnumIsStored; property SetOfEnum: TSetOfEnum read FSetOfEnum write FSetOfEnum stored SetOfEnumIsStored;
property SetOfEnumRg: TSetOfEnumRg read FSetOfEnumRg write FSetOfEnumRg stored SetOfEnumRgIsStored; property SetOfEnumRg: TSetOfEnumRg read FSetOfEnumRg write FSetOfEnumRg stored SetOfEnumRgIsStored;
property Event: TNotifyEvent read FEvent write FEvent stored EventIsStored;
end; end;
{ TTestCompReaderWriterPas } { TTestCompReaderWriterPas }
@ -421,6 +431,11 @@ end;
{ TCompBaseTypesCustomStored } { TCompBaseTypesCustomStored }
procedure TCompBaseTypesCustomStored.OnClick(Sender: TObject);
begin
if Sender=nil then ;
end;
function TCompBaseTypesCustomStored.ABooleanIsStored: Boolean; function TCompBaseTypesCustomStored.ABooleanIsStored: Boolean;
begin begin
Result:=FABoolean<>DefABoolean; Result:=FABoolean<>DefABoolean;
@ -541,6 +556,11 @@ begin
Result:=FEnumRg<>DefEnumRg; Result:=FEnumRg<>DefEnumRg;
end; end;
function TCompBaseTypesCustomStored.EventIsStored: Boolean;
begin
Result:=TMethod(FEvent).Code<>TMethod(DefEvent).Code;
end;
function TCompBaseTypesCustomStored.SetOfEnumIsStored: Boolean; function TCompBaseTypesCustomStored.SetOfEnumIsStored: Boolean;
begin begin
Result:=FSetOfEnum<>DefSetOfEnum; Result:=FSetOfEnum<>DefSetOfEnum;
@ -771,6 +791,7 @@ begin
DefMethodValue.Code := nil; DefMethodValue.Code := nil;
end; end;
//system.writeln('TCompWriterPas.WriteProperty ',dbgs(MethodValue.Data),' ',dbgs(MethodValue.Code),' ',dbgs(DefMethodValue.Data),' ',dbgs(DefMethodValue.Code));
if Assigned(OnGetMethodName) then if Assigned(OnGetMethodName) then
begin begin
if (MethodValue.Code <> DefMethodValue.Code) or if (MethodValue.Code <> DefMethodValue.Code) or
@ -837,8 +858,8 @@ begin
end; end;
tkVariant: tkVariant:
begin begin
{ Ensure that a Variant manager is installed } // Ensure that a Variant manager is installed
if not assigned(VarClearProc) then if not Assigned(VarClearProc) then
raise EWriteError.Create(SErrNoVariantSupport); raise EWriteError.Create(SErrNoVariantSupport);
VarValue := tvardata(GetVariantProp(Instance, PropInfo)); VarValue := tvardata(GetVariantProp(Instance, PropInfo));
@ -853,7 +874,9 @@ begin
System.writeln('TCompWriterPas.WriteProperty Property="',PropName,'" Kind=',PropType^.Kind); System.writeln('TCompWriterPas.WriteProperty Property="',PropName,'" Kind=',PropType^.Kind);
raise EWriteError.Create('proptype not supported: '+GetEnumName(TypeInfo(PropType^.Kind),ord(PropType^.Kind))); raise EWriteError.Create('proptype not supported: '+GetEnumName(TypeInfo(PropType^.Kind),ord(PropType^.Kind)));
{$ENDIF} {$ENDIF}
{ can't use variant() typecast, pulls in variants unit } // can't use variant() typecast, pulls in variants unit
//case VarValue.vtype ofall
//ToDo WriteVariant(pvariant(@VarValue)^); //ToDo WriteVariant(pvariant(@VarValue)^);
end; end;
end; end;
@ -1308,6 +1331,8 @@ begin
DefSetOfEnum:=[red]; DefSetOfEnum:=[red];
SetOfEnumRg:=[]; SetOfEnumRg:=[];
DefSetOfEnumRg:=[red]; DefSetOfEnumRg:=[red];
Event:=nil;
DefEvent:=@OnClick;
end; end;
TestWriteDescendant('TestBaseTypesZeroes',AComponent,nil,[ TestWriteDescendant('TestBaseTypesZeroes',AComponent,nil,[
'AByte:=0;', 'AByte:=0;',
@ -1325,6 +1350,7 @@ begin
'EnumRg:=TEnumRg(0);', 'EnumRg:=TEnumRg(0);',
'SetOfEnum:=[];', 'SetOfEnum:=[];',
'SetOfEnumRg:=[];', 'SetOfEnumRg:=[];',
//'Event:=nil;', must not be written
'']); '']);
finally finally
AComponent.Free; AComponent.Free;
@ -1382,6 +1408,8 @@ begin
DefSetOfEnum:=[red]; DefSetOfEnum:=[red];
SetOfEnumRg:=[]; SetOfEnumRg:=[];
DefSetOfEnumRg:=[red]; DefSetOfEnumRg:=[red];
Event:=@OnClick;
DefEvent:=nil;
end; end;
TestWriteDescendant('TestBaseTypesMinValues',AComponent,nil,[ TestWriteDescendant('TestBaseTypesMinValues',AComponent,nil,[
'ABoolean:=False;', 'ABoolean:=False;',
@ -1404,6 +1432,7 @@ begin
'EnumRg:=green;', 'EnumRg:=green;',
'SetOfEnum:=[];', 'SetOfEnum:=[];',
'SetOfEnumRg:=[];', 'SetOfEnumRg:=[];',
'Event:=@OnClick;',
'']); '']);
finally finally
AComponent.Free; AComponent.Free;
@ -1499,9 +1528,11 @@ begin
with AComponent do begin with AComponent do begin
Name:=AComponent.ClassName+'1'; Name:=AComponent.ClassName+'1';
AString:=#9'A'#13#10; AString:=#9'A'#13#10;
AShortString:=#9'A'#13#10;
end; end;
TestWriteDescendant('TestStringASCII',AComponent,nil,[ TestWriteDescendant('TestStringASCII',AComponent,nil,[
'AString:=#9''A''#13#10;']); 'AString:=#9''A''#13#10;',
'AShortString:=#9''A''#13#10;']);
finally finally
AComponent.Free; AComponent.Free;
end; end;