MacroScript: started tests

git-svn-id: trunk@39168 -
This commit is contained in:
martin 2012-10-26 00:00:41 +00:00
parent 48e6d4d808
commit f5a27a1725
5 changed files with 223 additions and 2 deletions

3
.gitattributes vendored
View File

@ -2163,6 +2163,9 @@ components/macroscript/editormacroscript.pas svneol=native#text/pascal
components/macroscript/emscriptclasses.pas svneol=native#text/pascal
components/macroscript/emscriptmacro.pas svneol=native#text/pascal
components/macroscript/registerems.pas svneol=native#text/pascal
components/macroscript/test/TestMacroScript.lpi svneol=native#text/plain
components/macroscript/test/TestMacroScript.lpr svneol=native#text/plain
components/macroscript/test/testscriptprocs.pas svneol=native#text/pascal
components/memds/Makefile svneol=native#text/plain
components/memds/Makefile.compiled svneol=native#text/plain
components/memds/Makefile.fpc svneol=native#text/plain

View File

@ -227,7 +227,7 @@ begin
RegisterMethod('procedure PasteFromClipboard;');
RegisterProperty('CanPaste', 'Boolean', iptR);
// Logigal / Physical
// Logical / Physical
RegisterMethod('function LogicalToPhysicalPos(const p: TPoint): TPoint;');
RegisterMethod('function LogicalToPhysicalCol(const Line: String; Index, LogicalPos : integer): integer;');
RegisterMethod('function PhysicalToLogicalPos(const p: TPoint): TPoint;');
@ -281,7 +281,7 @@ begin
RegisterMethod(@TSynEdit.PasteFromClipboard, 'PASTEFROMCLIPBOARD');
RegisterPropertyHelper(@TSynEdit_CanPaste_R, nil, 'CANPASTE');
// Logigal / Physical
// Logical / Physical
RegisterMethod(@TSynEdit.LogicalToPhysicalPos, 'LOGICALTOPHYSICALPOS');
RegisterMethod(@TSynEdit.LogicalToPhysicalCol, 'LOGICALTOPHYSICALCOL');
RegisterMethod(@TSynEdit.PhysicalToLogicalPos, 'PHYSICALTOLOGICALPOS');

View File

@ -0,0 +1,89 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<Version Value="9"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="TestMacroScript"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<i18n>
<EnableI18N LFM="False"/>
</i18n>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="5">
<Item1>
<PackageName Value="SynEdit"/>
</Item1>
<Item2>
<PackageName Value="EditorMacroScript"/>
</Item2>
<Item3>
<PackageName Value="FPCUnitTestRunner"/>
</Item3>
<Item4>
<PackageName Value="LCL"/>
</Item4>
<Item5>
<PackageName Value="FCL"/>
</Item5>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="TestMacroScript.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestMacroScript"/>
</Unit0>
<Unit1>
<Filename Value="testscriptprocs.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TestScriptProcs"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
</SearchPaths>
<Other>
<CompilerMessages>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,15 @@
program TestMacroScript;
{$mode objfpc}{$H+}
uses
Interfaces, Forms, GuiTestRunner, TestScriptProcs;
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TGuiTestRunner, TestRunner);
Application.Run;
end.

View File

@ -0,0 +1,114 @@
unit TestScriptProcs;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, SynEdit, EMScriptMacro, fpcunit, testutils, testregistry;
type
{ TTestCase1 }
TTestCase1 = class(TTestCase)
published
procedure TestProcs;
end;
implementation
procedure TTestCase1.TestProcs;
var
TestSyn: TSynEdit;
TestMacro: TEMSEditorMacro;
function t(lines: array of string): String;
var
i: Integer;
begin
Result := '';
for i := low(lines) to high (lines) do Result := Result + lines[i] + LineEnding;
end;
procedure DoTestSimple(AName, AStartText, AMacroText, AExpect: String;
Ax: Integer = 1; Ay: Integer = 1; ExpX: Integer = -1; ExpY: Integer = -1;
AExpIsPart: Boolean = True);
begin
if pos ('end.', AMacroText) < 1 then
AMacroText := 'begin' + LineEnding + AMacroText + LineEnding + 'end.';
TestSyn.Text := AStartText;
TestSyn.CaretXY := Point(aX, AY);
TestMacro.SetFromSource(AMacroText);
AssertTrue(AName+' Macro is valid: ' +TestMacro.ErrorMsg, not TestMacro.IsInvalid);
TestMacro.PlaybackMacro(TestSyn);
if AExpIsPart
then AssertTrue(AName+' contains: ' + AExpect + ' IN ' + TestSyn.Text, pos(AExpect, TestSyn.Text) > 0)
else AssertEquals(AName+' equals: ' + AExpect + ' IN ' + TestSyn.Text, AExpect, TestSyn.Text);
if ExpX > 0 then begin
AssertEquals(AName+ ' Carety: ', Expy, TestSyn.CaretXY.y);
AssertEquals(AName+ ' CaretX: ', ExpX, TestSyn.CaretXY.x);
end;
end;
begin
TestSyn := TSynEdit.Create(nil);
TestMacro := TEMSEditorMacro.Create(nil);
try
DoTestSimple('ecChar', '', 'ecChar(''C'');', 'C');
DoTestSimple('InsertTextAtCaret', '',
'Caller.InsertTextAtCaret(''Foo'', scamEnd);',
'Foo');
DoTestSimple('InsertTextAtCaret 2', 'SomeBar',
'Caller.InsertTextAtCaret(''Foo'', scamEnd);',
'SomeFooBar', 5,1, 8,1);
DoTestSimple('InsertTextAtCaret 2', 'SomeBar',
'Caller.InsertTextAtCaret(''Foo'', scamBegin);',
'SomeFooBar', 5,1, 5,1);
DoTestSimple('TextBetweenPoints', 'SomeBar',
'Caller.TextBetweenPoints[Point(3,1), point(5,1)] := ''ng'';',
'SongBar');
DoTestSimple('TextBetweenPoints 2', t(['Bar', 'aXY']),
'var s: string; begin'+LineEnding+
' s := Caller.TextBetweenPoints[Point(2,2), point(4,2)];'+LineEnding+
' Caller.TextBetweenPoints[Point(5,1), point(5,1)] := s;'+LineEnding+
'end.',
'Bar XY');
DoTestSimple('SetTextBetweenPoints', 'SomeBar',
'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [], scamEnd, smaKeep, smNormal);',
'SongBar', 1,1, 5,1);
DoTestSimple('SetTextBetweenPoints scamBegin', 'SomeBar',
'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [], scamBegin, smaKeep, smNormal);',
'SongBar', 1,1, 3,1);
DoTestSimple('SetTextBetweenPoints setSelect', 'SomeBar',
'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [setSelect], scamEnd, smaKeep, smNormal);',
'SongBar');
AssertEquals('SetTextBetweenPoints setSelect', 'ng', TestSyn.SelText);
DoTestSimple('LineAtCaret', t(['1', 'Bar', 'abc 123']),
'Caller.TextBetweenPoints[Point(1,2), point(1,2)] := Caller.LineAtCaret',
'abc 123Bar', 2,3);
DoTestSimple('Lines[2]', t(['1', 'Bar', 'abc 123']),
'Caller.TextBetweenPoints[Point(1,1), point(1,1)] := Caller.Lines[2]',
'abc 1231');
DoTestSimple('Lines[1]', t(['1', 'Bar', 'abc 123']),
'Caller.TextBetweenPoints[Point(1,1), point(1,1)] := Caller.Lines[1]',
'Bar1');
finally
TestMacro.Free;
TestSyn.Free;
end;
end;
initialization
RegisterTest(TTestCase1);
end.