3
./runtests --format=plain --suite=TTestCTStdCodetools
4
./runtests --format=plain --suite=TestCTStdFindBlockStart
13
Classes, SysUtils, LCLProc, testglobals, fpcunit,
14
CodeToolManager, StdCodeTools, CodeCache, LinkScanner;
18
{ TTestCTStdCodetools }
20
TTestCTStdCodetools = class(TTestCase)
22
procedure TestCTStdFindBlockStart;
27
{ TTestCTStdCodetools }
29
procedure TTestCTStdCodetools.TestCTStdFindBlockStart;
33
function GetSource: string;
36
'program TestStdCodeTools;'+LineEnding
38
+' if true then {begin1}begin'+LineEnding
39
+' {try1}try'+LineEnding
40
+' writeln;'+LineEnding
41
+' {try1finally}finally'+LineEnding
42
+' writeln;'+LineEnding
43
+' {try1end}end;'+LineEnding
44
+' writeln;'+LineEnding
45
+' {begin1end}end;'+LineEnding
49
function GetMarker(Comment: string): TPoint;
54
if Comment[1]<>'{' then
55
Comment:='{'+Comment+'}';
56
p:=System.Pos(Comment,Code.Source);
58
AssertEquals('searching marker: '+Comment,true,p>=1);
59
Code.AbsoluteToLineCol(p+length(Comment),Result.Y,Result.X);
61
AssertEquals('Code.AbsoluteToLineCol: '+Comment,true,Result.Y>=1);
64
function GetInfo(XY: TPoint): string;
68
Line:=Code.GetLine(XY.Y-1);
69
Result:=dbgs(XY)+': '+copy(Line,1,XY.X-1)+'|'+copy(Line,XY.X,length(Line));
72
procedure Test(aTitle, StartMarker,EndMarker: string);
81
BlockStart:=GetMarker(StartMarker);
82
BlockEnd:=GetMarker(EndMarker);
83
//debugln(['TTestCTStdCodetools.TestCTStdFindBlockStart BlockStart=',GetInfo(BlockStart),' BlockEnd=',GetInfo(BlockEnd)]);
84
if not CodeToolBoss.FindBlockStart(Code,BlockEnd.X,BlockEnd.Y,NewCode,NewX,NewY,NewTopline)
86
AssertEquals(aTitle+': '+CodeToolBoss.ErrorMessage,true,false)
88
AssertEquals(aTitle,GetInfo(BlockStart),GetInfo(Point(NewX,NewY)))
92
Code:=CodeToolBoss.CreateFile('TestStdCodeTools.pas');
95
Code.Source:=GetSource();
97
Test('begin,try,finally,end|end','begin1','begin1end');
98
Test('begin,try,finally,|end,end','try1finally','try1end');
99
Test('begin,try,finally,|end,end','try1','try1finally');
103
AddToCodetoolsTestSuite(TTestCTStdCodetools);