mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-08 04:37:23 +01:00
codetools: added test for scanner at end, tool at impl uses end, then buildtree
git-svn-id: trunk@39865 -
This commit is contained in:
parent
5a5af581e2
commit
6438ccc4ba
@ -10,6 +10,7 @@
|
|||||||
./runtests --format=plain --suite=TestCTScanRangeImplementationToEnd
|
./runtests --format=plain --suite=TestCTScanRangeImplementationToEnd
|
||||||
./runtests --format=plain --suite=TestCTScanRangeInitializationModified
|
./runtests --format=plain --suite=TestCTScanRangeInitializationModified
|
||||||
./runtests --format=plain --suite=TestCTScanRangeLibraryInitializationModified
|
./runtests --format=plain --suite=TestCTScanRangeLibraryInitializationModified
|
||||||
|
./runtests --format=plain --suite=TestCTScanRangeScannerAtEnd
|
||||||
}
|
}
|
||||||
unit TestCTRangeScan;
|
unit TestCTRangeScan;
|
||||||
|
|
||||||
@ -21,8 +22,11 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpcunit, testglobals, FileProcs, CodeToolManager,
|
Classes, SysUtils, fpcunit, testglobals, FileProcs, CodeToolManager,
|
||||||
CodeCache, CustomCodeTool, LinkScanner, CodeTree, EventCodeTool;
|
CodeCache, CustomCodeTool, LinkScanner, CodeTree, EventCodeTool,
|
||||||
|
PascalParserTool;
|
||||||
|
|
||||||
|
const
|
||||||
|
ctrsCommentOfProc1 = 'comment of Proc1';
|
||||||
type
|
type
|
||||||
TCTRgSrcFlag = (
|
TCTRgSrcFlag = (
|
||||||
crsfWithProc1,
|
crsfWithProc1,
|
||||||
@ -42,6 +46,7 @@ type
|
|||||||
protected
|
protected
|
||||||
function GetSource(Flags: TCTRgSrcFlags): string;
|
function GetSource(Flags: TCTRgSrcFlags): string;
|
||||||
procedure CheckTree(Tool: TCodeTool);
|
procedure CheckTree(Tool: TCodeTool);
|
||||||
|
function FindPos(Code: TCodeBuffer; SearchText: string; out Line,Col: integer; ErrorOnNotFound: boolean = true): boolean;
|
||||||
published
|
published
|
||||||
procedure TestCTScanRange;
|
procedure TestCTScanRange;
|
||||||
procedure TestCTScanRangeAscending;
|
procedure TestCTScanRangeAscending;
|
||||||
@ -50,6 +55,7 @@ type
|
|||||||
procedure TestCTScanRangeImplementationToEnd;
|
procedure TestCTScanRangeImplementationToEnd;
|
||||||
procedure TestCTScanRangeInitializationModified;
|
procedure TestCTScanRangeInitializationModified;
|
||||||
procedure TestCTScanRangeLibraryInitializationModified;
|
procedure TestCTScanRangeLibraryInitializationModified;
|
||||||
|
procedure TestCTScanRangeScannerAtEnd;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -85,7 +91,7 @@ begin
|
|||||||
if crsfWithProc1Modified in Flags then
|
if crsfWithProc1Modified in Flags then
|
||||||
Result+='procedure Proc1;'+LineEnding
|
Result+='procedure Proc1;'+LineEnding
|
||||||
+'begin'+LineEnding
|
+'begin'+LineEnding
|
||||||
+' // comment'+LineEnding
|
+' // '+ctrsCommentOfProc1+LineEnding
|
||||||
+'end;'+LineEnding;
|
+'end;'+LineEnding;
|
||||||
if crsfWithInitialization in Flags then begin
|
if crsfWithInitialization in Flags then begin
|
||||||
Result+='initialization'+LineEnding;
|
Result+='initialization'+LineEnding;
|
||||||
@ -121,6 +127,23 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TTestCodetoolsRangeScan.FindPos(Code: TCodeBuffer; SearchText: string;
|
||||||
|
out Line, Col: integer; ErrorOnNotFound: boolean): boolean;
|
||||||
|
var
|
||||||
|
p: SizeInt;
|
||||||
|
begin
|
||||||
|
Line:=0;
|
||||||
|
Col:=0;
|
||||||
|
p:=Pos(SearchText,Code.Source);
|
||||||
|
if p<1 then begin
|
||||||
|
if ErrorOnNotFound then
|
||||||
|
raise Exception.Create('TTestCodetoolsRangeScan.FindPos SearchText "'+SearchText+'" not found in "'+Code.Filename+'"');
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
Code.AbsoluteToLineCol(p,Line,Col);
|
||||||
|
Result:=Line>=0;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestCodetoolsRangeScan.TestCTScanRange;
|
procedure TTestCodetoolsRangeScan.TestCTScanRange;
|
||||||
var
|
var
|
||||||
Code: TCodeBuffer;
|
Code: TCodeBuffer;
|
||||||
@ -340,6 +363,34 @@ begin
|
|||||||
//Tool.WriteDebugTreeReport;
|
//Tool.WriteDebugTreeReport;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestCodetoolsRangeScan.TestCTScanRangeScannerAtEnd;
|
||||||
|
var
|
||||||
|
Code: TCodeBuffer;
|
||||||
|
Tool: TCodeTool;
|
||||||
|
CursorPos: TCodeXYPosition;
|
||||||
|
CleanCursorPos: integer;
|
||||||
|
begin
|
||||||
|
Code:=CodeToolBoss.CreateFile('TestRangeScan.pas');
|
||||||
|
Tool:=CodeToolBoss.GetCodeToolForSource(Code,false,true) as TCodeTool;
|
||||||
|
|
||||||
|
// scan source til implementation uses end
|
||||||
|
Code.Source:=GetSource([crsfWithProc1Modified]);
|
||||||
|
Tool.BuildTree(lsrImplementationUsesSectionEnd);
|
||||||
|
|
||||||
|
// let LinkScanner scan til end
|
||||||
|
Tool.Scanner.Scan(lsrEnd,false);
|
||||||
|
|
||||||
|
AssertEquals('scanner at end, tool at impl uses end',true,Tool.ScannedRange=lsrImplementationUsesSectionEnd);
|
||||||
|
AssertEquals('scanner at end, tool at impl uses end',true,Tool.Scanner.ScannedRange=lsrEnd);
|
||||||
|
// test BuildTreeAndGetCleanPos in implementation section
|
||||||
|
CursorPos.Code:=Code;
|
||||||
|
FindPos(Code,ctrsCommentOfProc1,CursorPos.Y,CursorPos.X);
|
||||||
|
Tool.BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos,
|
||||||
|
[btSetIgnoreErrorPos]);
|
||||||
|
AssertEquals('scanner and tool at end',true,Tool.ScannedRange=lsrEnd);
|
||||||
|
AssertEquals('scanner and tool at end',true,Tool.Scanner.ScannedRange=lsrEnd);
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
AddToCodetoolsTestSuite(TTestCodetoolsRangeScan);
|
AddToCodetoolsTestSuite(TTestCodetoolsRangeScan);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user