mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 02:40:03 +02:00
codetools: added test for find declaration nested class
git-svn-id: trunk@40199 -
This commit is contained in:
parent
248c598499
commit
a70b6fb7e5
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -851,6 +851,7 @@ components/codetools/sourcechanger.pas svneol=native#text/pascal
|
||||
components/codetools/sourcelog.pas svneol=native#text/pascal
|
||||
components/codetools/stdcodetools.pas svneol=native#text/pascal
|
||||
components/codetools/tests/fdt_classhelper.pas svneol=native#text/plain
|
||||
components/codetools/tests/fdt_nestedclasses.pas svneol=native#text/plain
|
||||
components/codetools/tests/fdtbase.pas svneol=native#text/plain
|
||||
components/codetools/tests/finddeclarationtest.lpi svneol=native#text/plain
|
||||
components/codetools/tests/finddeclarationtest.lpr svneol=native#text/plain
|
||||
|
44
components/codetools/tests/fdt_nestedclasses.pas
Normal file
44
components/codetools/tests/fdt_nestedclasses.pas
Normal file
@ -0,0 +1,44 @@
|
||||
unit fdt_nestedclasses;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
type
|
||||
TBaseClass = class
|
||||
public type
|
||||
TBaseSubClass = class
|
||||
procedure DoSomething; virtual;
|
||||
end;
|
||||
end;
|
||||
|
||||
TCustomClass = class(TBaseClass)
|
||||
public type
|
||||
TCustomSubClass = class(TBaseSubClass{declaration:fdt_nestedclasses.TBaseClass.TBaseSubClass})
|
||||
procedure DoSomething; override;
|
||||
end;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TCustomClass.TCustomSubClass }
|
||||
|
||||
procedure TCustomClass.TCustomSubClass.DoSomething;
|
||||
begin
|
||||
//put the cursor here and hit Ctrl+Space
|
||||
|
||||
end;
|
||||
|
||||
{ TBaseClass.TBaseSubClass }
|
||||
|
||||
procedure TBaseClass.TBaseSubClass.DoSomething;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -1,8 +1,9 @@
|
||||
{
|
||||
Test with:
|
||||
./finddeclarationtest --format=plain --suite=TTestFindDeclarationClassHelper
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_base
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_classhelper
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_Base
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_NestedClasses
|
||||
./finddeclarationtest --format=plain --suite=TestFindDeclaration_ClassHelper
|
||||
}
|
||||
unit fdtbase;
|
||||
|
||||
@ -17,14 +18,15 @@ uses
|
||||
|
||||
type
|
||||
|
||||
{ TTestFindDeclarationClassHelper }
|
||||
{ TTestFindDeclaration }
|
||||
|
||||
TTestFindDeclarationClassHelper = class(TTestCase)
|
||||
TTestFindDeclaration = class(TTestCase)
|
||||
private
|
||||
procedure FindDeclarations(Filename, Marker: string);
|
||||
published
|
||||
procedure TestFindDeclaration_base;
|
||||
procedure TestFindDeclaration_classhelper;
|
||||
procedure TestFindDeclaration_Base;
|
||||
procedure TestFindDeclaration_NestedClasses;
|
||||
procedure TestFindDeclaration_ClassHelper;
|
||||
end;
|
||||
|
||||
var
|
||||
@ -46,9 +48,9 @@ begin
|
||||
FindDeclarationTestSuite.AddTestSuiteFromClass(ATestClass);
|
||||
end;
|
||||
|
||||
{ TTestFindDeclarationClassHelper }
|
||||
{ TTestFindDeclaration }
|
||||
|
||||
procedure TTestFindDeclarationClassHelper.FindDeclarations(Filename,
|
||||
procedure TTestFindDeclaration.FindDeclarations(Filename,
|
||||
Marker: string);
|
||||
|
||||
procedure PrependPath(Prefix: string; var Path: string);
|
||||
@ -64,12 +66,12 @@ var
|
||||
StartPos: Integer;
|
||||
ExpectedPath: String;
|
||||
PathPos: Integer;
|
||||
CursorPos, TargetCursorPos: TCodeXYPosition;
|
||||
TargetTopLine: integer;
|
||||
TargetTool: TFindDeclarationTool;
|
||||
TargetCleanPos: Integer;
|
||||
TargetNode: TCodeTreeNode;
|
||||
TargetPath: String;
|
||||
CursorPos, FoundCursorPos: TCodeXYPosition;
|
||||
FoundTopLine: integer;
|
||||
FoundTool: TFindDeclarationTool;
|
||||
FoundCleanPos: Integer;
|
||||
FoundNode: TCodeTreeNode;
|
||||
FoundPath: String;
|
||||
begin
|
||||
Filename:=TrimAndExpandFilename(Filename);
|
||||
Code:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||
@ -87,41 +89,48 @@ begin
|
||||
p:=FindCommentEnd(Tool.Src,p,Tool.Scanner.NestedComments);
|
||||
if Tool.Src[StartPos]<>'{' then continue;
|
||||
PathPos:=StartPos+1;
|
||||
//debugln(['TTestFindDeclaration.FindDeclarations Comment: ',dbgstr(Tool.Src,StartPos,p-StartPos)]);
|
||||
if copy(Tool.Src,PathPos,length(Marker))<>Marker then continue;
|
||||
PathPos+=length(Marker);
|
||||
ExpectedPath:=copy(Tool.Src,PathPos,p-1-PathPos);
|
||||
//debugln(['TTestFindDeclarationClassHelper.FindDeclarations ',ExpectedPath]);
|
||||
//debugln(['TTestFindDeclaration.FindDeclarations ExpectedPath=',ExpectedPath]);
|
||||
Tool.CleanPosToCaret(StartPos-1,CursorPos);
|
||||
if not CodeToolBoss.FindDeclaration(CursorPos.Code,CursorPos.X,CursorPos.Y,
|
||||
TargetCursorPos.Code,TargetCursorPos.X,TargetCursorPos.Y,TargetTopLine)
|
||||
FoundCursorPos.Code,FoundCursorPos.X,FoundCursorPos.Y,FoundTopLine)
|
||||
then begin
|
||||
AssertEquals('find declaration failed at '+Tool.CleanPosToStr(StartPos-1)+': '+CodeToolBoss.ErrorMessage,false,true);
|
||||
continue;
|
||||
end else begin
|
||||
TargetTool:=CodeToolBoss.GetCodeToolForSource(TargetCursorPos.Code,true,true) as TFindDeclarationTool;
|
||||
TargetTool.CaretToCleanPos(TargetCursorPos,TargetCleanPos);
|
||||
TargetNode:=TargetTool.FindDeepestNodeAtPos(TargetCleanPos,true);
|
||||
TargetPath:='';
|
||||
while TargetNode<>nil do begin
|
||||
case TargetNode.Desc of
|
||||
FoundTool:=CodeToolBoss.GetCodeToolForSource(FoundCursorPos.Code,true,true) as TFindDeclarationTool;
|
||||
FoundTool.CaretToCleanPos(FoundCursorPos,FoundCleanPos);
|
||||
FoundNode:=FoundTool.FindDeepestNodeAtPos(FoundCleanPos,true);
|
||||
FoundPath:='';
|
||||
while FoundNode<>nil do begin
|
||||
case FoundNode.Desc of
|
||||
ctnTypeDefinition,ctnVarDefinition,ctnConstDefinition:
|
||||
PrependPath(GetIdentifier(@TargetTool.Src[TargetNode.StartPos]),TargetPath);
|
||||
PrependPath(GetIdentifier(@FoundTool.Src[FoundNode.StartPos]),FoundPath);
|
||||
ctnInterface,ctnUnit:
|
||||
PrependPath(TargetTool.GetSourceName(false),TargetPath);
|
||||
PrependPath(FoundTool.GetSourceName(false),FoundPath);
|
||||
end;
|
||||
TargetNode:=TargetNode.Parent;
|
||||
FoundNode:=FoundNode.Parent;
|
||||
end;
|
||||
AssertEquals('find declaration wrong at '+Tool.CleanPosToStr(StartPos-1),LowerCase(ExpectedPath),LowerCase(TargetPath));
|
||||
//debugln(['TTestFindDeclaration.FindDeclarations FoundPath=',FoundPath]);
|
||||
AssertEquals('find declaration wrong at '+Tool.CleanPosToStr(StartPos-1),LowerCase(ExpectedPath),LowerCase(FoundPath));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclarationClassHelper.TestFindDeclaration_base;
|
||||
procedure TTestFindDeclaration.TestFindDeclaration_Base;
|
||||
begin
|
||||
FindDeclarations('fdt_classhelper.pas','declaration:');
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclarationClassHelper.TestFindDeclaration_classhelper;
|
||||
procedure TTestFindDeclaration.TestFindDeclaration_NestedClasses;
|
||||
begin
|
||||
FindDeclarations('fdt_nestedclasses.pas','declaration:');
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclaration.TestFindDeclaration_ClassHelper;
|
||||
begin
|
||||
FindDeclarations('fdt_classhelper.pas','declaration-classhelper:');
|
||||
end;
|
||||
@ -133,6 +142,6 @@ initialization
|
||||
FindDeclarationTestSuite := TTestSuite.Create('Parser');
|
||||
GetTestRegistry.AddTest(FindDeclarationTestSuite);
|
||||
|
||||
AddToFindDeclarationTestSuite(TTestFindDeclarationClassHelper);
|
||||
AddToFindDeclarationTestSuite(TTestFindDeclaration);
|
||||
end.
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
||||
<PackageName Value="fpcunitconsolerunner"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="finddeclarationtest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
@ -57,6 +57,11 @@
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="fdt_classhelper"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="fdt_nestedclasses.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="fdt_nestedclasses"/>
|
||||
</Unit3>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
@ -20,8 +20,8 @@ program finddeclarationtest;
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, sysutils, consoletestrunner, dom, fpcunit,
|
||||
CodeToolManager, CodeToolsConfig, fdtbase, fdt_classhelper;
|
||||
Classes, sysutils, consoletestrunner, dom, fpcunit, CodeToolManager,
|
||||
CodeToolsConfig, LazLogger, fdtbase, fdt_classhelper, fdt_nestedclasses;
|
||||
|
||||
const
|
||||
ConfigFilename = 'codetools.config';
|
||||
@ -64,6 +64,7 @@ begin
|
||||
// To not parse the FPC sources every time, the options are saved to a file.
|
||||
Options.LoadFromFile(ConfigFilename);
|
||||
end;
|
||||
DebugLn(['EnvironmentVariables: PP, FPCDIR, LAZARUSDIR, FPCTARGET, FPCTARGETCPU']);
|
||||
Options.InitWithEnvironmentVariables;
|
||||
|
||||
if HasOption('submitter') then
|
||||
|
Loading…
Reference in New Issue
Block a user