mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-15 02:19:36 +01:00
codetools: test CheckLFM child component
This commit is contained in:
parent
029f775a85
commit
09c3e47a45
@ -23,6 +23,10 @@ type
|
|||||||
protected
|
protected
|
||||||
procedure SetUp; override;
|
procedure SetUp; override;
|
||||||
procedure TearDown; override;
|
procedure TearDown; override;
|
||||||
|
function AddControls(const aFilename: string = 'controls.pas'): TCodeBuffer;
|
||||||
|
function AddFormUnit(const Fields: array of string;
|
||||||
|
const aFormClass: string = 'TForm';
|
||||||
|
const aFilename: string = 'unit1.pas'): TCodeBuffer;
|
||||||
function AddSource(aFilename, aSource: string): TCodeBuffer;
|
function AddSource(aFilename, aSource: string): TCodeBuffer;
|
||||||
public
|
public
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
@ -42,6 +46,7 @@ type
|
|||||||
TTestLFMTrees = class(TCustomTestLFMTrees)
|
TTestLFMTrees = class(TCustomTestLFMTrees)
|
||||||
published
|
published
|
||||||
procedure LFMEmptyForm;
|
procedure LFMEmptyForm;
|
||||||
|
procedure LFMButton1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -61,35 +66,6 @@ end;
|
|||||||
procedure TCustomTestLFMTrees.SetUp;
|
procedure TCustomTestLFMTrees.SetUp;
|
||||||
begin
|
begin
|
||||||
inherited SetUp;
|
inherited SetUp;
|
||||||
|
|
||||||
FControlsCode:=AddSource('controls.pas',LinesToStr([
|
|
||||||
'unit Controls;',
|
|
||||||
'{$mode objfpc}{$H+}',
|
|
||||||
'interface',
|
|
||||||
'uses Classes;',
|
|
||||||
'type',
|
|
||||||
' TCaption = type string;',
|
|
||||||
' TAction = class(TComponent)',
|
|
||||||
' published',
|
|
||||||
' property OnExecute: TNotifyEvent;',
|
|
||||||
' end;',
|
|
||||||
'',
|
|
||||||
' TControl = class(TComponent)',
|
|
||||||
' published',
|
|
||||||
' property Caption: TCaption;',
|
|
||||||
' property Left: integer;',
|
|
||||||
' property Top: integer;',
|
|
||||||
' property OnClick: TNotifyEvent;',
|
|
||||||
' end;',
|
|
||||||
' TFormStyle = (fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop, fsSplash, fsSystemStayOnTop);',
|
|
||||||
' TForm = class(TControl)',
|
|
||||||
' published',
|
|
||||||
' property FormStyle: TFormStyle;',
|
|
||||||
' end;',
|
|
||||||
'end.',
|
|
||||||
'implementation',
|
|
||||||
'end.'
|
|
||||||
]));
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomTestLFMTrees.TearDown;
|
procedure TCustomTestLFMTrees.TearDown;
|
||||||
@ -108,9 +84,75 @@ begin
|
|||||||
inherited TearDown;
|
inherited TearDown;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomTestLFMTrees.AddControls(const aFilename: string): TCodeBuffer;
|
||||||
|
begin
|
||||||
|
FControlsCode:=AddSource(aFilename,LinesToStr([
|
||||||
|
'unit Controls;',
|
||||||
|
'{$mode objfpc}{$H+}',
|
||||||
|
'interface',
|
||||||
|
'uses Classes;',
|
||||||
|
'type',
|
||||||
|
' TCaption = type string;',
|
||||||
|
' TAction = class(TComponent)',
|
||||||
|
' published',
|
||||||
|
' property OnExecute: TNotifyEvent;',
|
||||||
|
' end;',
|
||||||
|
'',
|
||||||
|
' TControl = class(TComponent)',
|
||||||
|
' published',
|
||||||
|
' property Caption: TCaption;',
|
||||||
|
' property Left: integer;',
|
||||||
|
' property Top: integer;',
|
||||||
|
//' property Width: integer;',
|
||||||
|
//' property Height: integer;',
|
||||||
|
' property OnClick: TNotifyEvent;',
|
||||||
|
' end;',
|
||||||
|
'',
|
||||||
|
' TButton = class(TControl)',
|
||||||
|
' published',
|
||||||
|
' property Default: Boolean;',
|
||||||
|
' end;',
|
||||||
|
'',
|
||||||
|
' TFormStyle = (fsNormal, fsMDIChild, fsMDIForm, fsStayOnTop, fsSplash, fsSystemStayOnTop);',
|
||||||
|
' TForm = class(TControl)',
|
||||||
|
' published',
|
||||||
|
' property FormStyle: TFormStyle;',
|
||||||
|
' end;',
|
||||||
|
'end.',
|
||||||
|
'implementation',
|
||||||
|
'end.'
|
||||||
|
]));
|
||||||
|
Result:=FControlsCode;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCustomTestLFMTrees.AddFormUnit(const Fields: array of string;
|
||||||
|
const aFormClass: string; const aFilename: string): TCodeBuffer;
|
||||||
|
var
|
||||||
|
Src: String;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
Src:='';
|
||||||
|
for i:=low(Fields) to high(Fields) do begin
|
||||||
|
Src:=Src+' '+Fields[i]+';'+sLineBreak;
|
||||||
|
end;
|
||||||
|
FUnitCode:=AddSource(aFilename,LinesToStr([
|
||||||
|
'unit Unit1;',
|
||||||
|
'{$mode objfpc}{$H+}',
|
||||||
|
'interface',
|
||||||
|
'uses Controls;',
|
||||||
|
'type',
|
||||||
|
' '+aFormClass+'1 = class('+aFormClass+')',
|
||||||
|
Src+' end;',
|
||||||
|
'implementation',
|
||||||
|
'end.'
|
||||||
|
]));
|
||||||
|
Result:=FUnitCode;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomTestLFMTrees.AddSource(aFilename, aSource: string): TCodeBuffer;
|
function TCustomTestLFMTrees.AddSource(aFilename, aSource: string): TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
Result:=CodeToolBoss.CreateFile(aFilename);
|
Result:=CodeToolBoss.CreateFile(aFilename);
|
||||||
|
FSources.Add(Result);
|
||||||
Result.Source:=aSource;
|
Result.Source:=aSource;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -129,12 +171,20 @@ end;
|
|||||||
procedure TCustomTestLFMTrees.CheckLFM;
|
procedure TCustomTestLFMTrees.CheckLFM;
|
||||||
var
|
var
|
||||||
LFMTree: TLFMTree;
|
LFMTree: TLFMTree;
|
||||||
|
LFMErr: TLFMError;
|
||||||
begin
|
begin
|
||||||
LFMTree:=nil;
|
LFMTree:=nil;
|
||||||
try
|
try
|
||||||
if CodeToolBoss.CheckLFM(UnitCode,LFMCode,LFMTree,true,true,true) then
|
if CodeToolBoss.CheckLFM(UnitCode,LFMCode,LFMTree,true,true,true) then
|
||||||
exit;
|
exit;
|
||||||
WriteSource(CodeXYPosition(CodeToolBoss.ErrorColumn,CodeToolBoss.ErrorLine,CodeToolBoss.ErrorCode));
|
WriteSource(CodeXYPosition(CodeToolBoss.ErrorColumn,CodeToolBoss.ErrorLine,CodeToolBoss.ErrorCode));
|
||||||
|
if LFMTree<>nil then begin
|
||||||
|
LFMErr:=LFMTree.FirstError;
|
||||||
|
while LFMErr<>nil do begin
|
||||||
|
writeln('LFM Error: (',LFMErr.Caret.Y,',',LFMErr.Caret.X,') ',LFMErr.ErrorMessage);
|
||||||
|
LFMErr:=LFMErr.NextError;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
Fail('CheckLFM error "'+CodeToolBoss.ErrorMessage+'"');
|
Fail('CheckLFM error "'+CodeToolBoss.ErrorMessage+'"');
|
||||||
finally
|
finally
|
||||||
LFMTree.Free;
|
LFMTree.Free;
|
||||||
@ -189,18 +239,20 @@ procedure TCustomTestLFMTrees.WriteSource(const CursorPos: TCodeXYPosition);
|
|||||||
end else begin
|
end else begin
|
||||||
if (CurCode=CursorPos.Code) then continue;
|
if (CurCode=CursorPos.Code) then continue;
|
||||||
end;
|
end;
|
||||||
|
writeln('WriteSources ',i,'/',SourceCount,' ',CurCode.Filename);
|
||||||
for LineNo:=1 to CurCode.LineCount do begin
|
for LineNo:=1 to CurCode.LineCount do begin
|
||||||
Line:=CurCode.GetLine(i-1,false);
|
Line:=CurCode.GetLine(LineNo-1,false);
|
||||||
if (CurCode=CursorPos.Code) and (i=CursorPos.Y) then begin
|
if (CurCode=CursorPos.Code) and (LineNo=CursorPos.Y) then begin
|
||||||
write('*');
|
write('*');
|
||||||
Line:=LeftStr(Line,CursorPos.X-1)+'|'+copy(Line,CursorPos.X,length(Line));
|
Line:=LeftStr(Line,CursorPos.X-1)+'|'+copy(Line,CursorPos.X,length(Line));
|
||||||
end;
|
end;
|
||||||
writeln(Format('%:4d: ',[i]),Line);
|
writeln(Format('%:4d: ',[LineNo]),Line);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
writeln('TCustomTestLFMTrees.WriteSource CursorPos=',dbgs(CursorPos));
|
||||||
// write good sources
|
// write good sources
|
||||||
MyWriteSources(false);
|
MyWriteSources(false);
|
||||||
// write error source
|
// write error source
|
||||||
@ -211,17 +263,8 @@ end;
|
|||||||
|
|
||||||
procedure TTestLFMTrees.LFMEmptyForm;
|
procedure TTestLFMTrees.LFMEmptyForm;
|
||||||
begin
|
begin
|
||||||
FUnitCode:=AddSource('unit1.pas',LinesToStr([
|
AddControls;
|
||||||
'unit Unit1;',
|
AddFormUnit([]);
|
||||||
'{$mode objfpc}{$H+}',
|
|
||||||
'interface',
|
|
||||||
'uses Controls;',
|
|
||||||
'type',
|
|
||||||
' TForm1 = class(TForm)',
|
|
||||||
' end;',
|
|
||||||
'implementation',
|
|
||||||
'end.'
|
|
||||||
]));
|
|
||||||
FLFMCode:=AddSource('unit1.lfm',LinesToStr([
|
FLFMCode:=AddSource('unit1.lfm',LinesToStr([
|
||||||
'object Form1: TForm1',
|
'object Form1: TForm1',
|
||||||
'end'
|
'end'
|
||||||
@ -229,6 +272,22 @@ begin
|
|||||||
CheckLFM;
|
CheckLFM;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestLFMTrees.LFMButton1;
|
||||||
|
begin
|
||||||
|
AddControls;
|
||||||
|
AddFormUnit(['Button1: TButton']);
|
||||||
|
FLFMCode:=AddSource('unit1.lfm',LinesToStr([
|
||||||
|
'object Form1: TForm1',
|
||||||
|
' Left = 300',
|
||||||
|
' object Button1: TButton',
|
||||||
|
' Caption = ''ClickMe''',
|
||||||
|
' Default = True',
|
||||||
|
' end',
|
||||||
|
'end'
|
||||||
|
]));
|
||||||
|
CheckLFM;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterTest(TTestLFMTrees);
|
RegisterTest(TTestLFMTrees);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user