mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-06 16:12:43 +02:00
77 lines
1.7 KiB
ObjectPascal
77 lines
1.7 KiB
ObjectPascal
unit TestCodeCompletion;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, CodeToolManager, CodeCache,
|
|
LazLogger, LazFileUtils, fpcunit, testregistry,
|
|
TestFinddeclaration, TestStdCodetools;
|
|
|
|
type
|
|
|
|
{ TTestCodeCompletion }
|
|
|
|
TTestCodeCompletion = class(TCustomTestCTStdCodetools)
|
|
private
|
|
procedure Test(Title: string; Src: array of string; Line, Col: integer;
|
|
Expected: array of string);
|
|
published
|
|
procedure TestIntfProcUpdateArgName;
|
|
end;
|
|
|
|
implementation
|
|
|
|
{ TTestCodeCompletion }
|
|
|
|
procedure TTestCodeCompletion.Test(Title: string; Src: array of string; Line,
|
|
Col: integer; Expected: array of string);
|
|
var
|
|
i, NewX, NewY, NewTopLine, BlockTopLine, BlockBottomLine: Integer;
|
|
s: String;
|
|
NewCode, Code: TCodeBuffer;
|
|
begin
|
|
Code:=CodeToolBoss.CreateFile('test1.pas');
|
|
s:='';
|
|
for i:=Low(Src) to High(Src) do
|
|
s+=Src[i]+LineEnding;
|
|
Code.Source:=s;
|
|
|
|
if not CodeToolBoss.CompleteCode(Code,Col,Line,Line,NewCode,NewX,NewY,NewTopLine,
|
|
BlockTopLine,BlockBottomLine,false) then
|
|
begin
|
|
WriteSource(Code.Filename,Line,Col);
|
|
Fail(Title+'call CompleteCode failed: '+CodeToolBoss.ErrorDbgMsg);
|
|
end;
|
|
s:='';
|
|
for i:=Low(Expected) to High(Expected) do
|
|
s+=Expected[i]+LineEnding;
|
|
CheckDiff(Title,s,Code.Source);
|
|
end;
|
|
|
|
procedure TTestCodeCompletion.TestIntfProcUpdateArgName;
|
|
begin
|
|
Test('TestIntfProcUpdateArgName',
|
|
['unit test1;'
|
|
,'interface'
|
|
,'procedure DoIt(a: longint);'
|
|
,'implementation'
|
|
,'procedure DoIt(b: longint);'
|
|
,'begin end;'
|
|
,'end.'],
|
|
3,1,
|
|
['unit test1;'
|
|
,'interface'
|
|
,'procedure DoIt(a: longint);'
|
|
,'implementation'
|
|
,'procedure DoIt(a: longint);'
|
|
,'begin end;'
|
|
,'end.']);
|
|
end;
|
|
|
|
initialization
|
|
RegisterTests([TTestCodeCompletion]);
|
|
end.
|
|
|