mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-12 10:00:38 +01:00
CodeTools, Test: Add test for FindIdentifierReferences.
This commit is contained in:
parent
8801ff314b
commit
998b38112f
35
components/codetools/tests/laztests/tfind_ref_nestclass.pas
Normal file
35
components/codetools/tests/laztests/tfind_ref_nestclass.pas
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
program Project1{ TODO findrefs:C,...};
|
||||||
|
uses Classes;
|
||||||
|
type
|
||||||
|
TFoo{findrefs:C,3,4;17,17;11,18;6,19;15,20;17,23;3,30;12,31;26,32;17,33} = class // TODO: misses 15,3
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TBar }
|
||||||
|
|
||||||
|
TBar{findrefs:5,9;22,17;22,23;8,30;17,31;31,32;22,33} = class
|
||||||
|
class procedure abc{findrefs:23,10;27,17;13,30;22,31};
|
||||||
|
class procedure def{findrefs:C,23,11;21,18;27,23;36,32;27,33};
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TFoo.TBar }
|
||||||
|
|
||||||
|
class procedure TFoo.TBar.abc;
|
||||||
|
begin // TFoo.TBar.def
|
||||||
|
// TFoo.TBar.abc
|
||||||
|
// Project1.TFoo.TBar.abc
|
||||||
|
end;
|
||||||
|
|
||||||
|
class procedure TFoo.TBar.def;
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
a: TMethod;
|
||||||
|
begin
|
||||||
|
TFoo.TBar.abc;
|
||||||
|
Project1.TFoo.TBar.abc;
|
||||||
|
a := TMethod(@Project1.TFoo.TBar.def);
|
||||||
|
a := TMethod(@TFoo.TBar.def);
|
||||||
|
end.
|
||||||
|
|
||||||
@ -48,6 +48,13 @@
|
|||||||
{guesstype:
|
{guesstype:
|
||||||
Tests: CodeToolBoss.GuessTypeOfIdentifier
|
Tests: CodeToolBoss.GuessTypeOfIdentifier
|
||||||
|
|
||||||
|
{findrefs:XYLIST
|
||||||
|
XYLIST=x,y;x,y;...
|
||||||
|
Tests: CodeToolBoss.FindReferences
|
||||||
|
|
||||||
|
An exact list of all the location that codetool will find.
|
||||||
|
if XYLIST starts with "C," then comments are searched too.
|
||||||
|
|
||||||
*)
|
*)
|
||||||
unit TestFindDeclaration;
|
unit TestFindDeclaration;
|
||||||
|
|
||||||
@ -61,7 +68,7 @@ uses
|
|||||||
Classes, SysUtils, contnrs, fpcunit, testregistry, FileProcs, LazFileUtils,
|
Classes, SysUtils, contnrs, fpcunit, testregistry, FileProcs, LazFileUtils,
|
||||||
LazLogger, CodeToolManager, ExprEval, CodeCache, BasicCodeTools,
|
LazLogger, CodeToolManager, ExprEval, CodeCache, BasicCodeTools,
|
||||||
CustomCodeTool, CodeTree, FindDeclarationTool, KeywordFuncLists,
|
CustomCodeTool, CodeTree, FindDeclarationTool, KeywordFuncLists,
|
||||||
IdentCompletionTool, DefineTemplates, DirectoryCacher, StrUtils,
|
IdentCompletionTool, DefineTemplates, DirectoryCacher, CTUnitGraph, StrUtils,
|
||||||
TestPascalParser;
|
TestPascalParser;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -290,12 +297,15 @@ var
|
|||||||
NameStartPos, i, l, IdentifierStartPos, IdentifierEndPos,
|
NameStartPos, i, l, IdentifierStartPos, IdentifierEndPos,
|
||||||
BlockTopLine, BlockBottomLine, CommentEnd, StartOffs, TestLoop: Integer;
|
BlockTopLine, BlockBottomLine, CommentEnd, StartOffs, TestLoop: Integer;
|
||||||
Marker, ExpectedType, NewType, ExpexctedCompletion, ExpexctedTerm,
|
Marker, ExpectedType, NewType, ExpexctedCompletion, ExpexctedTerm,
|
||||||
ExpexctedCompletionPart, ExpexctedTermPart: String;
|
ExpexctedCompletionPart, ExpexctedTermPart, s: String;
|
||||||
IdentItem: TIdentifierListItem;
|
IdentItem: TIdentifierListItem;
|
||||||
ItsAKeyword, IsSubIdentifier, ExpInvert: boolean;
|
ItsAKeyword, IsSubIdentifier, ExpInvert, ExpComment: boolean;
|
||||||
ExistingDefinition: TFindContext;
|
ExistingDefinition: TFindContext;
|
||||||
ListOfPFindContext: TFPList;
|
ListOfPFindContext: TFPList;
|
||||||
NewExprType: TExpressionType;
|
NewExprType: TExpressionType;
|
||||||
|
ListOfPCodeXYPosition: TFPList;
|
||||||
|
Cache: TFindIdentifierReferenceCache;
|
||||||
|
CodePos: PCodeXYPosition;
|
||||||
begin
|
begin
|
||||||
FMainCode:=aCode;
|
FMainCode:=aCode;
|
||||||
DoParseModule(MainCode,FMainTool);
|
DoParseModule(MainCode,FMainTool);
|
||||||
@ -505,6 +515,31 @@ begin
|
|||||||
FreeListOfPFindContext(ListOfPFindContext);
|
FreeListOfPFindContext(ListOfPFindContext);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
end else if Marker='findrefs' then begin
|
||||||
|
ExpectedPath:=copy(Src,PathPos,CommentP-1-PathPos);
|
||||||
|
ExpComment := copy(ExpectedPath,1,2) = 'C,';
|
||||||
|
if ExpComment then delete(ExpectedPath, 1, 2);
|
||||||
|
ListOfPCodeXYPosition:=nil;
|
||||||
|
Cache:=nil;
|
||||||
|
MainTool.CleanPosToCaret(IdentifierStartPos,CursorPos);
|
||||||
|
|
||||||
|
if not CodeToolBoss.FindReferences(
|
||||||
|
aCode,CursorPos.X,CursorPos.Y,
|
||||||
|
aCode {TODO: iterate multiple files}, not ExpComment,
|
||||||
|
ListOfPCodeXYPosition, Cache)
|
||||||
|
then
|
||||||
|
AssertTrue('FindReferences failed at '+MainTool.CleanPosToStr(IdentifierStartPos,true), False);
|
||||||
|
|
||||||
|
s := '';
|
||||||
|
for i:=0 to ListOfPCodeXYPosition.Count-1 do begin
|
||||||
|
if s <> '' then
|
||||||
|
s := s + ';';
|
||||||
|
s := s + IntToStr(PCodeXYPosition(ListOfPCodeXYPosition[i])^.X) + ',' + IntToStr(PCodeXYPosition(ListOfPCodeXYPosition[i])^.Y);
|
||||||
|
end;
|
||||||
|
CodeToolBoss.FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
|
||||||
|
Cache.Free;
|
||||||
|
|
||||||
|
AssertEquals('FindReferences failed at '+MainTool.CleanPosToStr(IdentifierStartPos,true), ExpectedPath, s);
|
||||||
end else begin
|
end else begin
|
||||||
WriteSource(IdentifierStartPos,MainTool);
|
WriteSource(IdentifierStartPos,MainTool);
|
||||||
AssertEquals('Unknown marker at '+MainTool.CleanPosToStr(IdentifierStartPos,true),'declaration',Marker);
|
AssertEquals('Unknown marker at '+MainTool.CleanPosToStr(IdentifierStartPos,true),'declaration',Marker);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user