1 unit TestScriptProcs;
2 
3 {$mode objfpc}{$H+}
4 
5 interface
6 
7 uses
8   Classes, SysUtils, SynEdit, EMScriptMacro, EMSSelfTest, Controls, Dialogs,
9   Clipbrd, fpcunit, testutils, testregistry;
10 
11 type
12 
13   { TTestCase1 }
14 
15   TTestCase1 = class(TTestCase)
16   private
17     FTestSyn: TSynEdit;
18     FTestMacro: TEMSEditorMacro;
19 
20     procedure DoTestSimple(AName, AStartText, AMacroText, AExpect: String;
21       Ax: Integer = 1; Ay: Integer = 1;  ExpX: Integer = -1; ExpY: Integer = -1;
22       AExpIsPart: Boolean = True; ABlockEndX: Integer = -1; ABlockEndY: Integer = -1);
23   published
24     procedure TestBasics;
25     procedure TestSynProcs;
26     procedure TestSelfTest;
27     procedure TestInteractiv;
28   end;
29 
30 implementation
31 
tnull32 function t(lines: array of string): String;
33 var
34   i: Integer;
35 begin
36   Result := '';
37   for i := low(lines) to high (lines) do Result := Result + lines[i] + LineEnding;
38 end;
39 
40 procedure TTestCase1.DoTestSimple(AName, AStartText, AMacroText, AExpect: String; Ax: Integer;
41   Ay: Integer; ExpX: Integer; ExpY: Integer; AExpIsPart: Boolean; ABlockEndX: Integer;
42   ABlockEndY: Integer);
43 begin
44   if pos ('end.', AMacroText) < 1 then
45     AMacroText := 'begin' + LineEnding + AMacroText + LineEnding + 'end.';
46   FTestSyn.Text := AStartText;
47   FTestSyn.CaretXY := Point(aX, AY);
48   if ABlockEndY > 0 then begin
49     FTestSyn.BlockBegin := FTestSyn.LogicalCaretXY;
50     FTestSyn.BlockEnd := Point(ABlockEndX, ABlockEndY);
51   end;
52   FTestMacro.SetFromSource(AMacroText);
53   AssertTrue(AName+' Macro is valid: ' +FTestMacro.ErrorMsg, not FTestMacro.IsInvalid);
54   FTestMacro.PlaybackMacro(FTestSyn);
55   if AExpIsPart
56   then AssertTrue(AName+' contains: ' + AExpect + ' IN ' + FTestSyn.Text, pos(AExpect, FTestSyn.Text) > 0)
57   else AssertEquals(AName+' equals: ' + AExpect + ' IN ' + FTestSyn.Text, AExpect, FTestSyn.Text);
58   if ExpX > 0 then begin
59     AssertEquals(AName+ ' Carety: ', Expy, FTestSyn.CaretXY.y);
60     AssertEquals(AName+ ' CaretX: ', ExpX, FTestSyn.CaretXY.x);
61   end;
62 end;
63 
64 procedure TTestCase1.TestBasics;
65 begin
66   FTestSyn := TSynEdit.Create(nil);
67   FTestMacro := TEMSelfTestEditorMacro.Create(nil);
68   try
69     DoTestSimple('SizeOf(TPoint)',   '',
70                  'var p: TPoint; begin if SizeOf(p) = ' +IntToStr(SizeOf(TPoint)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd); end.',
71                  'Y'
72                  );
73 
74     DoTestSimple('mrNone',   '',
75                  'if mrNone = ' +IntToStr(mrNone) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
76                  'Y'
77                  );
78 
79     DoTestSimple('mrOk',   '',
80                  'if mrOk = ' +IntToStr(mrOk) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
81                  'Y'
82                  );
83 
84 
85     DoTestSimple('mtWarning',   '',
86                  'if test_ord_mt(mtWarning) = ' +IntToStr(ord(mtWarning)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
87                  'Y'
88                  );
89     DoTestSimple('mtError',   '',
90                  'if test_ord_mt(mtError) = ' +IntToStr(ord(mtError)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
91                  'Y'
92                  );
93     DoTestSimple('mtInformation',   '',
94                  'if test_ord_mt(mtInformation) = ' +IntToStr(ord(mtInformation)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
95                  'Y'
96                  );
97     DoTestSimple('mtConfirmation',   '',
98                  'if test_ord_mt(mtConfirmation) = ' +IntToStr(ord(mtConfirmation)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
99                  'Y'
100                  );
101     DoTestSimple('mtCustom',   '',
102                  'if test_ord_mt(mtCustom) = ' +IntToStr(ord(mtCustom)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
103                  'Y'
104                  );
105 
106 
107     DoTestSimple('mbYes',   '',
108                  'if test_ord_mb(mbYes) = ' +IntToStr(ord(mbYes)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
109                  'Y'
110                  );
111     DoTestSimple('mbNo',   '',
112                  'if test_ord_mb(mbNo) = ' +IntToStr(ord(mbNo)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
113                  'Y'
114                  );
115     DoTestSimple('mbOk',   '',
116                  'if test_ord_mb(mbOk) = ' +IntToStr(ord(mbOk)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
117                  'Y'
118                  );
119     DoTestSimple('mbCancel',   '',
120                  'if test_ord_mb(mbCancel) = ' +IntToStr(ord(mbCancel)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
121                  'Y'
122                  );
123     DoTestSimple('mbAbort',   '',
124                  'if test_ord_mb(mbAbort) = ' +IntToStr(ord(mbAbort)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
125                  'Y'
126                  );
127     DoTestSimple('mbRetry',   '',
128                  'if test_ord_mb(mbRetry) = ' +IntToStr(ord(mbRetry)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
129                  'Y'
130                  );
131     DoTestSimple('mbIgnore',   '',
132                  'if test_ord_mb(mbIgnore) = ' +IntToStr(ord(mbIgnore)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
133                  'Y'
134                  );
135     DoTestSimple('mbAll',   '',
136                  'if test_ord_mb(mbAll) = ' +IntToStr(ord(mbAll)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
137                  'Y'
138                  );
139     DoTestSimple('mbNoToAll',   '',
140                  'if test_ord_mb(mbNoToAll) = ' +IntToStr(ord(mbNoToAll)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
141                  'Y'
142                  );
143     DoTestSimple('mbYesToAll',   '',
144                  'if test_ord_mb(mbYesToAll) = ' +IntToStr(ord(mbYesToAll)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
145                  'Y'
146                  );
147     DoTestSimple('mbHelp',   '',
148                  'if test_ord_mb(mbHelp) = ' +IntToStr(ord(mbHelp)) + ' then Caller.InsertTextAtCaret(''Y'', scamEnd);',
149                  'Y'
150                  );
151 
152 
153   finally
154     FTestMacro.Free;
155     FTestSyn.Free;
156   end;
157 end;
158 
159 procedure TTestCase1.TestSynProcs;
160 begin
161   FTestSyn := TSynEdit.Create(nil);
162   FTestMacro := TEMSelfTestEditorMacro.Create(nil);
163   try
164     {%region Text / point / ecXXX *}
165 
166     // ecChar
167     DoTestSimple('ecChar',              '', 'ecChar(''C'');', 'C');
168 
169     // InsertTextAtCaret
170     DoTestSimple('InsertTextAtCaret',   '',
171                  'Caller.InsertTextAtCaret(''Foo'', scamEnd);',
172                  'Foo');
173     DoTestSimple('InsertTextAtCaret 2', 'SomeBar',
174                  'Caller.InsertTextAtCaret(''Foo'', scamEnd);',
175                  'SomeFooBar',  5,1,  8,1);
176     DoTestSimple('InsertTextAtCaret 2', 'SomeBar',
177                  'Caller.InsertTextAtCaret(''Foo'', scamBegin);',
178                  'SomeFooBar',  5,1,  5,1);
179 
180     // point
181     DoTestSimple('point()', '',
182                  'var p: TPoint; begin'+LineEnding+
183                  '  p := point(4,2);'+LineEnding+
184                  '  Caller.InsertTextAtCaret(inttostr(p.x)+'',''+inttostr(p.y), scamBegin);'+LineEnding+
185                  'end.',
186                  '4,2');
187 
188     // TextBetweenPoints
189     DoTestSimple('TextBetweenPoints',   'SomeBar',
190                  'Caller.TextBetweenPoints[Point(3,1), point(5,1)] :=  ''ng'';',
191                  'SongBar');
192     DoTestSimple('TextBetweenPoints 2', t(['Bar', 'aXY']),
193                  'var s: string; begin'+LineEnding+
194                  '  s := Caller.TextBetweenPoints[Point(2,2), point(4,2)];'+LineEnding+
195                  '  Caller.TextBetweenPoints[Point(5,1), point(5,1)] :=  s;'+LineEnding+
196                  'end.',
197                  'Bar XY');
198 
199     DoTestSimple('SetTextBetweenPoints',   'SomeBar',
200                  'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [], scamEnd, smaKeep, smNormal);',
201                  'SongBar',  1,1,  5,1);
202     DoTestSimple('SetTextBetweenPoints scamBegin',   'SomeBar',
203                  'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [], scamBegin, smaKeep, smNormal);',
204                  'SongBar',  1,1,  3,1);
205     DoTestSimple('SetTextBetweenPoints setSelect',   'SomeBar',
206                  'Caller.SetTextBetweenPoints(Point(3,1), point(5,1), ''ng'', [setSelect], scamEnd, smaKeep, smNormal);',
207                  'SongBar');
208     AssertEquals('SetTextBetweenPoints setSelect', 'ng', FTestSyn.SelText);
209 
210     // LineAtCaret
211     DoTestSimple('LineAtCaret',   t(['1', 'Bar', 'abc 123']),
212                  'Caller.TextBetweenPoints[Point(1,2), point(1,2)] := Caller.LineAtCaret',
213                  'abc 123Bar',  2,3);
214 
215     // Lines[]
216     DoTestSimple('Lines[2]',   t(['1', 'Bar', 'abc 123']),
217                  'Caller.TextBetweenPoints[Point(1,1), point(1,1)] := Caller.Lines[2]',
218                  'abc 1231');
219     DoTestSimple('Lines[1]',   t(['1', 'Bar', 'abc 123']),
220                  'Caller.TextBetweenPoints[Point(1,1), point(1,1)] := Caller.Lines[1]',
221                  'Bar1');
222 
223     {%endregion Text / point / ecXXX *}
224 
225 
226     {%region Caret *}
227     // CaretXY
228     DoTestSimple('CaretXY read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
229                  'var p: TPoint; begin ' + LineEnding +
230                  'p := caller.CaretXY;' + LineEnding +
231                  'Caller.InsertTextAtCaret(IntToStr(p.x)+'',''+IntToStr(p.y), scamEnd);' + LineEnding +
232                  'end.',
233                  '3,2',
234                  3,2
235                  );
236 
237     DoTestSimple('CaretXY write',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
238                  'begin ' + LineEnding +
239                  'caller.CaretXY := Point(5,2);' + LineEnding +
240                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
241                  'end.',
242                  'XXFoo',
243                  1,1
244                  );
245 
246     // CaretX, CaretY
247     DoTestSimple('CaretX read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
248                  'begin ' + LineEnding +
249                  'Caller.InsertTextAtCaret(IntToStr(caller.CaretX)+'',''+IntToStr(caller.CaretY), scamEnd);' + LineEnding +
250                  'end.',
251                  '3,2',
252                  3,2
253                  );
254 
255     DoTestSimple('CaretX write',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
256                  'begin ' + LineEnding +
257                  'caller.CaretX := 5;' + LineEnding +
258                  'caller.CaretY := 2;' + LineEnding +
259                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
260                  'end.',
261                  'XXFoo',
262                  1,1
263                  );
264 
265     // LogicalCaretXY
266     DoTestSimple('LogicalCaretXY read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
267                  'var p: TPoint; begin ' + LineEnding +
268                  'p := caller.LogicalCaretXY;' + LineEnding +
269                  'Caller.InsertTextAtCaret(IntToStr(p.x)+'',''+IntToStr(p.y), scamEnd);' + LineEnding +
270                  'end.',
271                  '4,2',
272                  3,2
273                  );
274 
275     DoTestSimple('LogicalCaretXY write',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
276                  'begin ' + LineEnding +
277                  'caller.LogicalCaretXY := Point(6,2);' + LineEnding +
278                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
279                  'end.',
280                  'XXFoo',
281                  1,1
282                  );
283 
284     // LogicalCaretX
285     DoTestSimple('LogicalCaretX read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
286                  'begin ' + LineEnding +
287                  'Caller.InsertTextAtCaret(IntToStr(caller.LogicalCaretX)+'',''+IntToStr(caller.CaretY), scamEnd);' + LineEnding +
288                  'end.',
289                  '4,2',
290                  3,2
291                  );
292 
293     DoTestSimple('LogicalCaretX write',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
294                  'begin ' + LineEnding +
295                  'caller.CaretY := 2;' + LineEnding +
296                  'caller.LogicalCaretX := 6;' + LineEnding +
297                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
298                  'end.',
299                  'XXFoo',
300                  1,1
301                  );
302 
303     // MoveCaretIgnoreEOL
304     DoTestSimple('MoveCaretIgnoreEOL',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
305                  'begin ' + LineEnding +
306                  'Caller.MoveCaretIgnoreEOL(Point(9,2));' + LineEnding +
307                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
308                  'end.',
309                  'Foo XX',
310                  1,1
311                  );
312 
313     // MoveLogicalCaretIgnoreEOL
314     DoTestSimple('MoveLogicalCaretIgnoreEOL',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
315                  'begin ' + LineEnding +
316                  'Caller.MoveLogicalCaretIgnoreEOL(Point(10,2));' + LineEnding +
317                  'Caller.InsertTextAtCaret(''XX'', scamEnd);' + LineEnding +
318                  'end.',
319                  'Foo XX',
320                  1,1
321                  );
322 
323     {%endregion Caret*}
324 
325 
326     {%region Selection *}
327     // BlockBegin, BlockEnd
328     DoTestSimple('BlockBegin read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
329                  'var p: TPoint; begin ' + LineEnding +
330                  'p := caller.BlockBegin;' + LineEnding +
331                  'Caller.InsertTextAtCaret(IntToStr(p.x)+'',''+IntToStr(p.y), scamEnd);' + LineEnding +
332                  'end.',
333                  '6,2',
334                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
335                  );
336 
337     DoTestSimple('BlockEnd read',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
338                  'var p: TPoint; begin ' + LineEnding +
339                  'p := caller.BlockEnd;' + LineEnding +
340                  'Caller.InsertTextAtCaret(IntToStr(p.x)+'',''+IntToStr(p.y), scamEnd);' + LineEnding +
341                  'end.',
342                  '8,2',
343                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
344                  );
345 
346     DoTestSimple('BlockBegin/End write',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
347                  'begin ' + LineEnding +
348                  'caller.BlockBegin := point(2,1);' + LineEnding +
349                  'caller.BlockEnd := point(5,1);' + LineEnding +
350                  'ecChar(''X'');' + LineEnding + // Replace "est"
351                  'end.',
352                  'TX',
353                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
354                  );
355 
356     // SelAvail
357     DoTestSimple('SelAvail',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
358                  'if caller.SelAvail then begin' + LineEnding +
359                  '  Caller.CaretXY := point(2,1);' + LineEnding +
360                  '  Caller.InsertTextAtCaret(''Y'', scamEnd);' + LineEnding +
361                  'end;',
362                  'TYest',
363                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
364                  );
365     DoTestSimple('SelAvail (NO)',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
366                  'if caller.SelAvail then begin' + LineEnding +
367                  '  Caller.CaretXY := point(2,1);' + LineEnding +
368                  '  Caller.InsertTextAtCaret(''Y'', scamEnd);' + LineEnding +
369                  'end;',
370                  'Test',
371                  5, 2
372                  );
373 
374     // SelText
375     DoTestSimple('SelText (read)',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
376                  'var s: String; begin ' + LineEnding +
377                  's := caller.SelText;' + LineEnding +
378                  'Caller.CaretXY := point(2,1);' + LineEnding +
379                  'Caller.InsertTextAtCaret(s, scamEnd);' + LineEnding +
380                  'end.',
381                  'TFoest',
382                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
383                  );
384     DoTestSimple('SelText(empty)',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
385                  'var s: String; begin ' + LineEnding +
386                  's := caller.SelText;' + LineEnding +
387                  'Caller.CaretXY := point(2,1);' + LineEnding +
388                  'Caller.InsertTextAtCaret(s, scamEnd);' + LineEnding +
389                  'end.',
390                  'Test',
391                  5, 2
392                  );
393     DoTestSimple('SelText (write)',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
394                  'caller.SelText := ''X'';',
395                  '   Xo',
396                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
397                  );
398 
399     // ClearSelection (does delete the text)
400     DoTestSimple('ClearSelection',   'Test123',
401                  'caller.ClearSelection;',
402                  'T123',
403                  2, 1,   -1, -1, True,   5, 1 // select "est"
404                  );
405 
406     // SelectAll
407     DoTestSimple('SelectAll',   'Test123',
408                  'caller.SelectAll;' + LineEnding +
409                  'caller.SelText := '''';',
410                  ''+LineEnding,
411                  2, 1,   -1, -1, False,   5, 1 // select "est"
412                  );
413 
414     // SelectToBrace
415     DoTestSimple('SelectToBrace',   'Test (123);',
416                  'caller.SelectToBrace;' + LineEnding +
417                  'caller.SelText := '''';',
418                  'Test ;'+LineEnding,
419                  6, 1
420                  );
421 
422     // SelectWord
423     DoTestSimple('SelectWord',   'Test abc def',
424                  'caller.SelectWord;' + LineEnding +
425                  'caller.SelText := '''';',
426                  'Test  def'+LineEnding,
427                  7, 1
428                  );
429 
430     // SelectLine
431     DoTestSimple('SelectLine false',   '  Test abc ',
432                  'caller.SelectLine(False);' + LineEnding +
433                  'caller.SelText := ''X'';',
434                  '  X'+LineEnding,
435                  7, 1
436                  );
437     DoTestSimple('SelectLine true',   '  Test abc ',
438                  'caller.SelectLine(True);' + LineEnding +
439                  'caller.SelText := ''X'';',
440                  'X'+LineEnding,
441                  7, 1,  -1,-1, False
442                  );
443 
444     DoTestSimple('SelectParagraph',   'Test'+ LineEnding + 'Foo' + LineEnding + LineEnding +'abc'+ LineEnding,
445                  'caller.SelectParagraph;' + LineEnding +
446                  'caller.SelText := '''';',
447                  'abc',
448                  1, 1
449                  );
450 
451 
452     // TODO: SelectionMode
453     {%endregion Selection *}
454 
455 
456     {%region Logical / Physical *}
457     // LogicalToPhysicalPos
458     DoTestSimple('LogicalToPhysicalPos', ' öabc',
459                  'var p: TPoint; begin'+LineEnding+
460                  '  p := Caller.LogicalToPhysicalPos(point(4,1));'+LineEnding+ // "a|b"
461                  '  Caller.InsertTextAtCaret(inttostr(p.x)+'',''+inttostr(p.y), scamBegin);'+LineEnding+
462                  'end.',
463                  '3,1');
464 
465     // LogicalToPhysicalCol
466     DoTestSimple('LogicalToPhysicalCol', ' öabc'+LineEnding+'x',
467                  'var i: Integer; begin'+LineEnding+
468                  '  i := Caller.LogicalToPhysicalCol(''ööabc'', 2, 6);'+LineEnding+ // "a|b"
469                  '  Caller.InsertTextAtCaret(inttostr(i), scamBegin);'+LineEnding+
470                  'end.',
471                  '4');
472 
473     // PhysicalToLogicalPos
474     DoTestSimple('PhysicalToLogicalPos', ' öabc',
475                  'var p: TPoint; begin'+LineEnding+
476                  '  p := Caller.PhysicalToLogicalPos(point(3,1));'+LineEnding+ // "a|b"
477                  '  Caller.InsertTextAtCaret(inttostr(p.x)+'',''+inttostr(p.y), scamBegin);'+LineEnding+
478                  'end.',
479                  '4,1');
480 
481     // PhysicalToLogicalCol
482     DoTestSimple('PhysicalToLogicalCol', ' öabc'+LineEnding+'x',
483                  'var i: Integer; begin'+LineEnding+
484                  '  i := Caller.PhysicalToLogicalCol(''ööabc'', 2, 4);'+LineEnding+ // "a|b"
485                  '  Caller.InsertTextAtCaret(inttostr(i), scamBegin);'+LineEnding+
486                  'end.',
487                  '6');
488 
489     // PhysicalLineLength
490     DoTestSimple('PhysicalLineLength', ' öabc'+LineEnding+'x',
491                  'var i: Integer; begin'+LineEnding+
492                  '  i := Caller.PhysicalLineLength(''ööabc'', 2);'+LineEnding+
493                  '  Caller.InsertTextAtCaret(inttostr(i), scamBegin);'+LineEnding+
494                  'end.',
495                  '5');
496 
497     {%endregion Logical / Physical *}
498 
499 
500     {%region Search *}
501     DoTestSimple('Find',   'Test abc abcde 123',
502                  'Caller.SearchReplace(''abc'', '''', []);',
503                  'Test abc abcde 123',
504                  1,1,  9,1 // caret at end of "abc"
505                  );
506     DoTestSimple('Find result',   'Test abc abcde 123',
507                  'if Caller.SearchReplace(''abc'', '''', []) > 0 then ecChar(''X'');',
508                  'Test X abcde 123',
509                  1,1,  7,1
510                  );
511     DoTestSimple('Find NO result',   'Test abc abcde 123',
512                  'if Caller.SearchReplace(''aXbc'', '''', []) > 0 then ecChar(''X'');',
513                  'Test abc abcde 123' + LineEnding,
514                  1,1,  -1,-1, False
515                  );
516 
517     DoTestSimple('Replace',   'Test abc abcde 123',
518                  'Caller.SearchReplace(''abc'', ''XYZ'', [ssoReplace]);',
519                  'Test XYZ abcde 123'
520                  );
521     DoTestSimple('Replace All',   'Test abc abcde 123',
522                  'Caller.SearchReplace(''abc'', ''XYZ'', [ssoReplaceAll]);',
523                  'Test XYZ XYZde 123'
524                  );
525     DoTestSimple('Replace All whole word',   'Test abc abcde 123',
526                  'Caller.SearchReplace(''abc'', ''XYZ'', [ssoReplaceAll, ssoWholeWord]);',
527                  'Test XYZ abcde 123'
528                  );
529 
530     DoTestSimple('Replace All EX',   'Test abc abcde 123',
531                  'Caller.SearchReplaceEx(''abc'', ''XYZ'', [ssoReplaceAll], point(8,1));',
532                  'Test abc XYZde 123'
533                  );
534 
535     {%endregion Search *}
536 
537 
538     {%region Clipboard *}
539     DoTestSimple('Clipboard write AsText',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
540                  'Clipboard.AsText:= ''X'';',
541                  'Foo',
542                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
543                  );
544     AssertEquals('Clipboard write AsText', 'X', Clipboard.AsText);
545 
546 
547     Clipboard.AsText := 'MM';
548     DoTestSimple('Clipboard read AsText',   ' ',
549                  'Caller.InsertTextAtCaret(Clipboard.AsText, scamEnd);',
550                  'MM'
551                  );
552 
553     DoTestSimple('CopyToClipboard',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
554                  'Caller.CopyToClipboard;',
555                  'Foo',
556                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
557                  );
558     AssertEquals('CopyToClipboard', 'Fo', Clipboard.AsText);
559 
560     DoTestSimple('CutToClipboard',   'Test'+ LineEnding + 'Ö   Foo' + LineEnding,
561                  'Caller.CutToClipboard;',
562                  ' o',
563                  5, 2,   -1, -1, True,   8, 2 // select "Fo"
564                  );
565     AssertEquals('CutToClipboard', 'Fo', Clipboard.AsText);
566 
567     Clipboard.AsText := 'OO';
568     DoTestSimple('PasteFromClipboard',   ' ',
569                  'Caller.PasteFromClipboard;',
570                  'OO'
571                  );
572 
573     // CanPaste
574     {%endregion Clipboard *}
575 
576 
577   finally
578     FTestMacro.Free;
579     FTestSyn.Free;
580   end;
581 end;
582 
583 procedure TTestCase1.TestSelfTest;
584 begin
585   AssertTrue(DoSelfTest);
586 end;
587 
588 procedure TTestCase1.TestInteractiv;
589 begin
590   FTestSyn := TSynEdit.Create(nil);
591   FTestMacro := TEMSelfTestEditorMacro.Create(nil);
592   try
593 
594     DoTestSimple('ShowMessage',   'Y',
595                  'ShowMessage(''Hello World'')',
596                  'Y');
597 
598     DoTestSimple('ShowMessagePos',   'Y',
599                  'ShowMessagePos(''I am at 10,10'', 10, 10)',
600                  'Y');
601 
602     DoTestSimple('MessageDlg',   '',
603                  'if MessageDlg(''Please press ok'', mtConfirmation, [mbOK, mbCancel], 0) = mrOk' + LineEnding +
604                  'then Caller.InsertTextAtCaret(''Y'', scamEnd)' + LineEnding +
605                  'else Caller.InsertTextAtCaret(''N'', scamEnd);',
606                  'Y');
607 
608     DoTestSimple('MessageDlgPos',   '',
609                  'if MessageDlgPos(''Am I at x=10,y=10? Please press CANCEL if I am'', mtConfirmation, [mbOK, mbCancel], 0, 10,10) = mrCancel' + LineEnding +
610                  'then Caller.InsertTextAtCaret(''Y'', scamEnd)' + LineEnding +
611                  'else Caller.InsertTextAtCaret(''N'', scamEnd);',
612                  'Y');
613 
614     DoTestSimple('MessageDlgPosHelp',   '',
615                  'if MessageDlgPosHelp(''Am I at x=50,y=50? Please press YES if I am'', mtConfirmation, [mbOK, mbCancel, mbYes], 0, 50,50,'''') = mrYes' + LineEnding +
616                  'then Caller.InsertTextAtCaret(''Y'', scamEnd)' + LineEnding +
617                  'else Caller.InsertTextAtCaret(''N'', scamEnd);',
618                  'Y');
619 
620     DoTestSimple('InputBox',   '',
621                  'var s: string; begin '+ LineEnding +
622                  's := ''replace me'';' + LineEnding +
623                  's := InputBox(''Need Input'', ''Please enter 123'', s);' + LineEnding +
624                  'Caller.InsertTextAtCaret(s, scamEnd);'+ LineEnding +
625                  'end.',
626                  '123');
627 
628     DoTestSimple('InputQuery Ok',   '',
629                  'var s: string; begin '+ LineEnding +
630                  's := ''replace me AGAIN'';' + LineEnding +
631                  'if InputQuery(''Need Input'', ''Plese enter 123 and press ok'', s)' + LineEnding +
632                  'then Caller.InsertTextAtCaret(s, scamEnd);' + LineEnding +
633                  'end.',
634                  '123');
635 
636     DoTestSimple('InputQuery Cancel',   '',
637                  'var s: string; begin '+ LineEnding +
638                  's := ''do NOT replace me'';' + LineEnding +
639                  'if not InputQuery(''Need Input'', ''Please press CANCEL'', s)' + LineEnding +
640                  'then Caller.InsertTextAtCaret(s, scamEnd);' + LineEnding +
641                  'end.',
642                  'do NOT replace me');
643 
644     DoTestSimple('InputQuery Cancel',   '',
645                  'var s: string; begin '+ LineEnding +
646                  's := '''';' + LineEnding +
647                  'if InputQuery(''Need Input'', ''enter 123 / press OK'', s)' + LineEnding +
648                  'then Caller.InsertTextAtCaret(s, scamEnd);' + LineEnding +
649                  'end.',
650                  '123');
651 
652 
653   finally
654     FTestMacro.Free;
655     FTestSyn.Free;
656   end;
657 end;
658 
659 
660 
661 initialization
662 
663   RegisterTest(TTestCase1);
664 end.
665 
666