codetools: tests: started test for RemoveWithBlock

git-svn-id: trunk@50260 -
This commit is contained in:
mattias 2015-11-08 18:15:07 +00:00
parent cd32c38a07
commit f8980e1003
6 changed files with 138 additions and 19 deletions

2
.gitattributes vendored
View File

@ -1031,6 +1031,8 @@ components/codetools/tests/parsertest.lpi svneol=native#text/plain
components/codetools/tests/parsertest.lpr svneol=native#text/plain components/codetools/tests/parsertest.lpr svneol=native#text/plain
components/codetools/tests/pt_thlp1.pas svneol=native#text/plain components/codetools/tests/pt_thlp1.pas svneol=native#text/plain
components/codetools/tests/pt_thlp2.pas svneol=native#text/plain components/codetools/tests/pt_thlp2.pas svneol=native#text/plain
components/codetools/tests/refactoringtests.pas svneol=native#text/plain
components/codetools/tests/rt_explodewith.pas svneol=native#text/plain
components/codetools/tests/testcodetools.lpi svneol=native#text/plain components/codetools/tests/testcodetools.lpi svneol=native#text/plain
components/codetools/tests/testcodetools.lpr svneol=native#text/plain components/codetools/tests/testcodetools.lpr svneol=native#text/plain
components/codetools/unitdictionary.pas svneol=native#text/plain components/codetools/unitdictionary.pas svneol=native#text/plain

View File

@ -18,7 +18,7 @@
./testcodetools --format=plain --suite=TestFindDeclaration_LazTests --filemask=t*.pp ./testcodetools --format=plain --suite=TestFindDeclaration_LazTests --filemask=t*.pp
./testcodetools --format=plain --suite=TestFindDeclaration_LazTests --filemask=tdefaultproperty1.pp ./testcodetools --format=plain --suite=TestFindDeclaration_LazTests --filemask=tdefaultproperty1.pp
} }
unit finddeclarationtests; unit FindDeclarationTests;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
@ -56,21 +56,8 @@ var
BugsTestSuite: TTestSuite; BugsTestSuite: TTestSuite;
FindDeclarationTestSuite: TTestSuite; FindDeclarationTestSuite: TTestSuite;
procedure AddToBugsTestSuite(ATest: TTest);
procedure AddToFindDeclarationTestSuite(ATestClass: TClass);
implementation implementation
procedure AddToBugsTestSuite(ATest: TTest);
begin
BugsTestSuite.AddTest(ATest);
end;
procedure AddToFindDeclarationTestSuite(ATestClass: TClass);
begin
FindDeclarationTestSuite.AddTestSuiteFromClass(ATestClass);
end;
{ TTestFindDeclaration } { TTestFindDeclaration }
procedure TTestFindDeclaration.FindDeclarations(Filename: string); procedure TTestFindDeclaration.FindDeclarations(Filename: string);
@ -313,9 +300,9 @@ initialization
GetTestRegistry.TestName := 'All tests'; GetTestRegistry.TestName := 'All tests';
BugsTestSuite := TTestSuite.Create('Bugs'); BugsTestSuite := TTestSuite.Create('Bugs');
GetTestRegistry.AddTest(BugsTestSuite); GetTestRegistry.AddTest(BugsTestSuite);
FindDeclarationTestSuite := TTestSuite.Create('Parser'); FindDeclarationTestSuite := TTestSuite.Create('FindDeclaration');
GetTestRegistry.AddTest(FindDeclarationTestSuite); GetTestRegistry.AddTest(FindDeclarationTestSuite);
AddToFindDeclarationTestSuite(TTestFindDeclaration); FindDeclarationTestSuite.AddTestSuiteFromClass(TTestFindDeclaration);
end. end.

View File

@ -0,0 +1,86 @@
{
Test with:
./testcodetools --format=plain --suite=TTestRefactoring
./testcodetools --format=plain --suite=TestExplodeWith
}
unit RefactoringTests;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, CodeToolManager, CodeCache, CodeTree, LazLogger,
LazFileUtils, fpcunit, testregistry, FindDeclarationTests;
type
{ TTestRefactoring }
TTestRefactoring = class(TTestCase)
private
published
procedure TestExplodeWith;
end;
var
RefactoringTestSuite: TTestSuite;
implementation
{ TTestRefactoring }
procedure TTestRefactoring.TestExplodeWith;
var
Code: TCodeBuffer;
Tool: TCodeTool;
Node: TCodeTreeNode;
CodeXYPos: TCodeXYPosition;
ListOfPCodeXYPosition: TFPList;
i: Integer;
Filename, OldSource: String;
begin
Filename:=ExpandFileNameUTF8('rt_explodewith.pas');
Code:=CodeToolBoss.LoadFile(Filename,true,false);
AssertEquals('Load file error: '+Filename,true,Code<>nil);
if not CodeToolBoss.Explore(Code,Tool,true) then
AssertEquals('Parse error: ','',CodeToolBoss.ErrorMessage);
ListOfPCodeXYPosition:=nil;
try
// collect all With-Blocks
Node:=Tool.Tree.Root;
while Node<>nil do begin
if Node.Desc=ctnWithVariable then begin
Tool.CleanPosToCaret(Node.StartPos,CodeXYPos);
AddCodePosition(ListOfPCodeXYPosition,CodeXYPos);
end;
Node:=Node.Next;
end;
for i:=0 to ListOfPCodeXYPosition.Count-1 do begin
CodeXYPos:=PCodeXYPosition(ListOfPCodeXYPosition[i])^;
debugln(['TTestRefactoring.TestExplodeWith ',dbgs(CodeXYPos)]);
OldSource:=Code.Source;
try
if CodeToolBoss.RemoveWithBlock(Code,CodeXYPos.X,CodeXYPos.Y) then begin
// check changes
end else begin
AssertEquals('CodeToolBoss.RemoveWithBlock failed at '+dbgs(CodeXYPos),'',CodeToolBoss.ErrorMessage);
end;
finally
Code.Source:=OldSource;
end;
end;
finally
FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
end;
end;
initialization
RefactoringTestSuite := TTestSuite.Create('Refactoring');
GetTestRegistry.AddTest(RefactoringTestSuite);
RefactoringTestSuite.AddTestSuiteFromClass(TTestRefactoring);
end.

View File

@ -0,0 +1,33 @@
unit rt_explodewith;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
{ TMyClass }
TMyClass = class
public
procedure DoSomething;
end;
implementation
{ TMyClass }
procedure TMyClass.DoSomething;
var
R: TRect;
begin
R:=Rect(1,2,3,4);
with R do
{explodewith:R}Left:=4;
end;
end.

View File

@ -40,7 +40,7 @@
<PackageName Value="fpcunitconsolerunner"/> <PackageName Value="fpcunitconsolerunner"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="9"> <Units Count="11">
<Unit0> <Unit0>
<Filename Value="testcodetools.lpr"/> <Filename Value="testcodetools.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -48,6 +48,7 @@
<Unit1> <Unit1>
<Filename Value="finddeclarationtests.pas"/> <Filename Value="finddeclarationtests.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="FindDeclarationTests"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="fdt_typehelper.pas"/> <Filename Value="fdt_typehelper.pas"/>
@ -77,6 +78,15 @@
<Filename Value="fdt_with.pas"/> <Filename Value="fdt_with.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
</Unit8> </Unit8>
<Unit9>
<Filename Value="refactoringtests.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="RefactoringTests"/>
</Unit9>
<Unit10>
<Filename Value="rt_explodewith.pas"/>
<IsPartOfProject Value="True"/>
</Unit10>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -21,7 +21,8 @@ program testcodetools;
uses uses
Classes, sysutils, consoletestrunner, dom, fpcunit, CodeToolManager, Classes, sysutils, consoletestrunner, dom, fpcunit, CodeToolManager,
CodeToolsConfig, LazLogger, finddeclarationtests, fdt_classhelper, CodeToolsConfig, LazLogger, finddeclarationtests, RefactoringTests,
fdt_classhelper,
{$IF FPC_FULLVERSION >= 30101} {$IF FPC_FULLVERSION >= 30101}
fdt_typehelper, fdt_typehelper,
{$ENDIF} {$ENDIF}
@ -29,7 +30,7 @@ uses
{$IFDEF Darwin} {$IFDEF Darwin}
fdt_objccategory, fdt_objcclass, fdt_objccategory, fdt_objcclass,
{$ENDIF} {$ENDIF}
fdt_basic, fdt_with; fdt_basic, fdt_with, rt_explodewith;
const const
ConfigFilename = 'codetools.config'; ConfigFilename = 'codetools.config';