mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 06:39:12 +02:00
codetools: added tests for type helpers
git-svn-id: trunk@50102 -
This commit is contained in:
parent
0075408ba2
commit
0ca8f14eff
@ -8254,6 +8254,9 @@ var
|
||||
debugln([' FindExpressionTypeOfTerm ResolveChildren']);
|
||||
{$ENDIF}
|
||||
ResolveBaseTypeOfIdentifier;
|
||||
{$IFDEF ShowExprEval}
|
||||
debugln([' FindExpressionTypeOfTerm ResolveChildren ExprType=',ExprTypeToString(ExprType)]);
|
||||
{$ENDIF}
|
||||
if (ExprType.Context.Node=nil) then exit;
|
||||
if (ExprType.Context.Node.Desc in AllUsableSourceTypes) then begin
|
||||
if ExprType.Context.Tool=Self then begin
|
||||
|
@ -1,3 +1,6 @@
|
||||
{
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_TypeHelper
|
||||
}
|
||||
unit fdt_typehelper;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
@ -10,31 +13,86 @@ uses
|
||||
|
||||
type
|
||||
|
||||
{ TStringTypeHelper }
|
||||
{ TShortStringTypeHelper }
|
||||
|
||||
TStringTypeHelper = type helper for ShortString
|
||||
TShortStringTypeHelper = type helper for ShortString
|
||||
public
|
||||
function MyVar: integer;
|
||||
end;
|
||||
|
||||
{ TStringTypeHelper }
|
||||
|
||||
TStringTypeHelper = type helper for String
|
||||
public
|
||||
function Get45: integer;
|
||||
end;
|
||||
|
||||
{ TLongIntTypeHelper }
|
||||
|
||||
TLongIntTypeHelper = type helper for LongInt
|
||||
public
|
||||
function GetStr: string;
|
||||
end;
|
||||
|
||||
{ TEnumTypeHelper }
|
||||
|
||||
TEnumTypeHelper = type helper for TShiftStateEnum
|
||||
public
|
||||
function Get78: integer;
|
||||
end;
|
||||
|
||||
procedure DoIt;
|
||||
|
||||
implementation
|
||||
|
||||
procedure DoIt;
|
||||
var
|
||||
s: ShortString;
|
||||
ShortS: ShortString;
|
||||
AnsiS: string;
|
||||
i: integer;
|
||||
e: TShiftStateEnum;
|
||||
begin
|
||||
s:='ABC';
|
||||
writeln('DoIt ',s.MyVar{declaration:fdt_typehelper.TStringTypeHelper.MyVar});
|
||||
ShortS:='ABC';
|
||||
writeln('DoIt ',ShortS.MyVar{declaration:fdt_typehelper.TShortStringTypeHelper.MyVar});
|
||||
|
||||
i:='Hello'.Get45{declaration:fdt_typehelper.TStringTypeHelper.Get45};
|
||||
if i<>45 then ;
|
||||
|
||||
AnsiS:=i.GetStr{declaration:fdt_typehelper.TLongIntTypeHelper.GetStr};
|
||||
if AnsiS<>'' then ;
|
||||
|
||||
e:=ssDouble;
|
||||
i:=e.Get78{ Not yet supported: declaration:fdt_typehelper.TEnumTypeHelper.Get78};
|
||||
if i<>78 then ;
|
||||
end;
|
||||
|
||||
{ TStringTypeHelper }
|
||||
{ TEnumTypeHelper }
|
||||
|
||||
function TStringTypeHelper.MyVar: integer;
|
||||
function TEnumTypeHelper.Get78: integer;
|
||||
begin
|
||||
Result:=78;
|
||||
end;
|
||||
|
||||
{ TLongIntTypeHelper }
|
||||
|
||||
function TLongIntTypeHelper.GetStr: string;
|
||||
begin
|
||||
Result:=IntToStr(Self)
|
||||
end;
|
||||
|
||||
{ TShortStringTypeHelper }
|
||||
|
||||
function TShortStringTypeHelper.MyVar: integer;
|
||||
begin
|
||||
Result:=123;
|
||||
end;
|
||||
|
||||
{ TStringTypeHelper }
|
||||
|
||||
function TStringTypeHelper.Get45: integer;
|
||||
begin
|
||||
Result:=45;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user