mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 16:59:15 +02:00
codetools: added test FindCodeContext for proc type
git-svn-id: trunk@56511 -
This commit is contained in:
parent
60dce6d601
commit
fa28ac6748
@ -38,15 +38,34 @@ type
|
|||||||
{ TTestIdentCompletion }
|
{ TTestIdentCompletion }
|
||||||
|
|
||||||
TTestIdentCompletion = class(TCustomTestFindDeclaration)
|
TTestIdentCompletion = class(TCustomTestFindDeclaration)
|
||||||
|
private
|
||||||
|
procedure CheckCodeContext(Context: TCodeContextInfoItem; MarkerName: string
|
||||||
|
);
|
||||||
published
|
published
|
||||||
procedure Test_GetValuesOfCaseVariable_Enum;
|
procedure Test_GetValuesOfCaseVariable_Enum;
|
||||||
procedure Test_FindCodeContext_ProcParams;
|
procedure Test_FindCodeContext_ProcParams;
|
||||||
|
procedure Test_FindCodeContext_ProcTypeParams;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TTestIdentCompletion }
|
{ TTestIdentCompletion }
|
||||||
|
|
||||||
|
procedure TTestIdentCompletion.CheckCodeContext(Context: TCodeContextInfoItem; MarkerName: string);
|
||||||
|
var
|
||||||
|
Marker: TFDMarker;
|
||||||
|
begin
|
||||||
|
AssertNotNull('CheckCodeContext: missing context for #'+MarkerName,Context);
|
||||||
|
AssertEquals('CheckCodeContext: Context.Expr.Desc for #'+MarkerName,
|
||||||
|
ExpressionTypeDescNames[xtContext],ExpressionTypeDescNames[Context.Expr.Desc]);
|
||||||
|
if MainTool<>Context.Expr.Context.Tool then
|
||||||
|
Fail('CheckCodeContext: Context.Expr.Context.Tool for #'+MarkerName+' expected "'+MainTool.MainFilename+'", but found "'+Context.Expr.Context.Tool.MainFilename+'"');
|
||||||
|
Marker:=FindMarker(MarkerName,'#');
|
||||||
|
AssertNotNull('CheckCodeContext: missing marker #'+MarkerName,Marker);
|
||||||
|
AssertEquals('CheckCodeContext: Context.Expr.Context.Node.StartPos for #'+MarkerName,
|
||||||
|
Marker.CleanPos,Context.Expr.Context.Node.StartPos);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTestIdentCompletion.Test_GetValuesOfCaseVariable_Enum;
|
procedure TTestIdentCompletion.Test_GetValuesOfCaseVariable_Enum;
|
||||||
var
|
var
|
||||||
List: TStrings;
|
List: TStrings;
|
||||||
@ -73,22 +92,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTestIdentCompletion.Test_FindCodeContext_ProcParams;
|
procedure TTestIdentCompletion.Test_FindCodeContext_ProcParams;
|
||||||
|
|
||||||
procedure CheckCodeContext(Context: TCodeContextInfoItem; MarkerName: string);
|
|
||||||
var
|
|
||||||
Marker: TFDMarker;
|
|
||||||
begin
|
|
||||||
AssertNotNull('CheckCodeContext: missing context for #'+MarkerName,Context);
|
|
||||||
AssertEquals('CheckCodeContext: Context.Expr.Desc for #'+MarkerName,
|
|
||||||
ExpressionTypeDescNames[xtContext],ExpressionTypeDescNames[Context.Expr.Desc]);
|
|
||||||
if MainTool<>Context.Expr.Context.Tool then
|
|
||||||
Fail('CheckCodeContext: Context.Expr.Context.Tool for #'+MarkerName+' expected "'+MainTool.MainFilename+'", but found "'+Context.Expr.Context.Tool.MainFilename+'"');
|
|
||||||
Marker:=FindMarker(MarkerName,'#');
|
|
||||||
AssertNotNull('CheckCodeContext: missing marker #'+MarkerName,Marker);
|
|
||||||
AssertEquals('CheckCodeContext: Context.Expr.Context.Node.StartPos for #'+MarkerName,
|
|
||||||
Marker.CleanPos,Context.Expr.Context.Node.StartPos);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
SrcMark: TFDMarker;
|
SrcMark: TFDMarker;
|
||||||
CursorPos: TCodeXYPosition;
|
CursorPos: TCodeXYPosition;
|
||||||
@ -126,6 +129,41 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTestIdentCompletion.Test_FindCodeContext_ProcTypeParams;
|
||||||
|
var
|
||||||
|
SrcMark: TFDMarker;
|
||||||
|
CursorPos: TCodeXYPosition;
|
||||||
|
CodeContexts: TCodeContextInfo;
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
StartProgram;
|
||||||
|
Add([
|
||||||
|
'type',
|
||||||
|
' TProc = procedure(i,j: longint);',
|
||||||
|
'var {#p}p: TProc;',
|
||||||
|
'begin',
|
||||||
|
' p(3,{#c}4);',
|
||||||
|
'end.']);
|
||||||
|
ParseSimpleMarkers(Code);
|
||||||
|
SrcMark:=FindMarker('c','#');
|
||||||
|
AssertNotNull('missing src marker #c',SrcMark);
|
||||||
|
MainTool.CleanPosToCaret(SrcMark.CleanPos,CursorPos);
|
||||||
|
CodeContexts:=nil;
|
||||||
|
try
|
||||||
|
if not CodeToolBoss.FindCodeContext(Code,CursorPos.X,CursorPos.Y,CodeContexts)
|
||||||
|
then begin
|
||||||
|
WriteSource(CursorPos);
|
||||||
|
Fail('CodeToolBoss.FindCodeContext');
|
||||||
|
end;
|
||||||
|
AssertEquals('CodeContexts.Count',1,CodeContexts.Count);
|
||||||
|
for i:=0 to CodeContexts.Count-1 do
|
||||||
|
debugln(['TTestIdentCompletion.Test_FindCodeContext_ProcParams ',i,' ',CodeContexts[i].AsDebugString(true)]);
|
||||||
|
CheckCodeContext(CodeContexts[0],'p');
|
||||||
|
finally
|
||||||
|
CodeContexts.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisterTests([TTestIdentCompletion]);
|
RegisterTests([TTestIdentCompletion]);
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user