~ubuntu-branches/ubuntu/saucy/lazarus/saucy

« back to all changes in this revision

Viewing changes to components/synedit/test/testfoldedview.pas

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Bart Martens, Paul Gevers
  • Date: 2013-06-08 14:12:17 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20130608141217-7k0cy9id8ifcnutc
Tags: 1.0.8+dfsg-1
[ Abou Al Montacir ]
* New upstream major release and multiple maintenace release offering many
  fixes and new features marking a new milestone for the Lazarus development
  and its stability level.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_fixes_branch
* LCL changes:
  - LCL is now a normal package.
      + Platform independent parts of the LCL are now in the package LCLBase
      + LCL is automatically recompiled when switching the target platform,
        unless pre-compiled binaries for this target are already installed.
      + No impact on existing projects.
      + Linker options needed by LCL are no more added to projects that do
        not use the LCL package.
  - Minor changes in LCL basic classes behaviour
      + TCustomForm.Create raises an exception if a form resource is not
        found.
      + TNotebook and TPage: a new implementation of these classes was added.
      + TDBNavigator: It is now possible to have focusable buttons by setting
        Options = [navFocusableButtons] and TabStop = True, useful for
        accessibility and for devices with neither mouse nor touch screen.
      + Names of TControlBorderSpacing.GetSideSpace and GetSpace were swapped
        and are now consistent. GetSideSpace = Around + GetSpace.
      + TForm.WindowState=wsFullscreen was added
      + TCanvas.TextFitInfo was added to calculate how many characters will
        fit into a specified Width. Useful for word-wrapping calculations.
      + TControl.GetColorResolvingParent and
        TControl.GetRGBColorResolvingParent were added, simplifying the work
        to obtain the final color of the control while resolving clDefault
        and the ParentColor.
      + LCLIntf.GetTextExtentExPoint now has a good default implementation
        which works in any platform not providing a specific implementation.
        However, Widgetset specific implementation is better, when available.
      + TTabControl was reorganized. Now it has the correct class hierarchy
        and inherits from TCustomTabControl as it should.
  - New unit in the LCL:
      + lazdialogs.pas: adds non-native versions of various native dialogs,
        for example TLazOpenDialog, TLazSaveDialog, TLazSelectDirectoryDialog.
        It is used by widgetsets which either do not have a native dialog, or
        do not wish to use it because it is limited. These dialogs can also be
        used by user applications directly.
      + lazdeviceapis.pas: offers an interface to more hardware devices such
        as the accelerometer, GPS, etc. See LazDeviceAPIs
      + lazcanvas.pas: provides a TFPImageCanvas descendent implementing
        drawing in a LCL-compatible way, but 100% in Pascal.
      + lazregions.pas. LazRegions is a wholly Pascal implementation of
        regions for canvas clipping, event clipping, finding in which control
        of a region tree one an event should reach, for drawing polygons, etc.
      + customdrawncontrols.pas, customdrawndrawers.pas,
        customdrawn_common.pas, customdrawn_android.pas and
        customdrawn_winxp.pas: are the Lazarus Custom Drawn Controls -controls
        which imitate the standard LCL ones, but with the difference that they
        are non-native and support skinning.
  - New APIs added to the LCL to improve support of accessibility software
    such as screen readers.
* IDE changes:
  - Many improvments.
  - The detailed list of changes can be found here:
    http://wiki.lazarus.freepascal.org/New_IDE_features_since#v1.0_.282012-08-29.29
    http://wiki.lazarus.freepascal.org/Lazarus_1.0_release_notes#IDE_Changes
* Debugger / Editor changes:
  - Added pascal sources and breakpoints to the disassembler
  - Added threads dialog.
* Components changes:
  - TAChart: many fixes and new features
  - CodeTool: support Delphi style generics and new syntax extensions.
  - AggPas: removed to honor free licencing. (Closes: Bug#708695)
[Bart Martens]
* New debian/watch file fixing issues with upstream RC release.
[Abou Al Montacir]
* Avoid changing files in .pc hidden directory, these are used by quilt for
  internal purpose and could lead to surprises during build.
[Paul Gevers]
* Updated get-orig-source target and it compinion script orig-tar.sh so that they
  repack the source file, allowing bug 708695 to be fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
uses
14
14
  Classes, SysUtils, testregistry, TestBase, TestHighlightPas, Forms, LCLProc,
15
15
  SynEdit, SynHighlighterPas, SynEditFoldedView, SynEditHighlighterFoldBase,
16
 
  SynGutterCodeFolding;
 
16
  SynGutterCodeFolding, SynEditKeyCmds, SynEditTypes;
17
17
 
18
18
type
19
19
 
22
22
  TTestFoldedView = class(TTestBaseHighlighterPas)
23
23
  private
24
24
    FoldedView: TSynEditFoldedView;
25
 
    DoAutoFoldDescTests: Boolean;
 
25
    DoAutoFoldDescTests, DoAutoFoldDescTestsReadOnly: Boolean;
26
26
    DoAllowScrollPastEof: Boolean;
27
27
    EnableDebug: Boolean;
28
28
 
37
37
    function TestTextPasHl(AIfCol: Integer): TStringArray;
38
38
    function TestText4: TStringArray;
39
39
    function TestText5: TStringArray;
 
40
    function TestText6: TStringArray;
 
41
    function TestText7: TStringArray;
 
42
    function TestText8: TStringArray;
 
43
    function TestText9: TStringArray;
 
44
    function TestText10: TStringArray;
40
45
    function TestTextHide(ALen: Integer): TStringArray;
41
46
    function TestTextHide2(ALen: Integer): TStringArray;
42
47
    function TestTextHide3: TStringArray;
43
48
    function TestTextHide4: TStringArray;
 
49
    function TestTextPlain: TStringArray;
 
50
    function TestTextBug21473: TStringArray;
 
51
  protected
 
52
    procedure TstSetText(AName: String; AText: Array of String);
 
53
    procedure TstFold(AName: String; AFoldAtIndex: integer; AExpectedLines: Array of Integer);
 
54
    procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum: integer; AExpectedLines: Array of Integer);
 
55
    procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
56
      AExpectedLines: Array of Integer);
 
57
    procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
58
      AFoldAtSkip: Boolean; AExpectedLines: Array of Integer);
 
59
    procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
60
      AFoldAtSkip: Boolean; AVisibleLines: Integer; AExpectedLines: Array of Integer);
 
61
    procedure TstUnFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
62
      AFoldAtSkip: Boolean; AVisibleLines: Integer; AExpectedLines: Array of Integer);
 
63
    procedure TstUnFoldAtCaret(AName: String; X, Y: integer; AExpectedLines: Array of Integer);
 
64
    procedure TstTxtIndexToViewPos(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
65
    procedure TstViewPosToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
66
    procedure TstTextIndexToScreenLine(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
67
    procedure TstScreenLineToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
44
68
  published
45
69
    procedure TestFold;
 
70
    procedure TestFoldEdit;
46
71
    procedure TestFoldStateFromText;
47
72
    procedure TestFoldStateDesc;
 
73
    procedure TestFoldProvider;
 
74
    procedure TestNestedFoldsList;
48
75
  end;
49
76
 
50
77
implementation
51
78
 
 
79
type
 
80
  TSynEditFoldedViewHack = class(TSynEditFoldedView) end;
 
81
 
 
82
procedure TTestFoldedView.TstSetText(AName: String; AText: array of String);
 
83
begin
 
84
  PopBaseName;
 
85
  ReCreateEdit;
 
86
  SetLines(AText);
 
87
  PushBaseName(AName);
 
88
end;
 
89
 
 
90
procedure TTestFoldedView.TstFold(AName: String; AFoldAtIndex: integer; AExpectedLines: Array of Integer);
 
91
begin
 
92
  FoldedView.FoldAtTextIndex(AFoldAtIndex);
 
93
  TestFoldedText(AName, AExpectedLines);
 
94
end;
 
95
procedure TTestFoldedView.TstFold(AName: String; AFoldAtIndex, AFoldAtColum: integer; AExpectedLines: Array of Integer);
 
96
begin
 
97
  FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum);
 
98
  TestFoldedText(AName, AExpectedLines);
 
99
end;
 
100
procedure TTestFoldedView.TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
101
  AExpectedLines: Array of Integer);
 
102
begin
 
103
  FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt);
 
104
  TestFoldedText(AName, AExpectedLines);
 
105
end;
 
106
procedure TTestFoldedView.TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
107
  AFoldAtSkip: Boolean; AExpectedLines: Array of Integer);
 
108
begin
 
109
  FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt, AFoldAtSkip);
 
110
  TestFoldedText(AName, AExpectedLines);
 
111
end;
 
112
procedure TTestFoldedView.TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
 
113
  AFoldAtSkip: Boolean; AVisibleLines: Integer; AExpectedLines: Array of Integer);
 
114
begin
 
115
  FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt, AFoldAtSkip, AVisibleLines);
 
116
  TestFoldedText(AName, AExpectedLines);
 
117
end;
 
118
 
 
119
procedure TTestFoldedView.TstUnFold(AName: String; AFoldAtIndex, AFoldAtColum,
 
120
  AFoldAtColCnt: integer; AFoldAtSkip: Boolean; AVisibleLines: Integer;
 
121
  AExpectedLines: array of Integer);
 
122
begin
 
123
  FoldedView.UnFoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt, AFoldAtSkip, AVisibleLines);
 
124
  TestFoldedText(AName, AExpectedLines);
 
125
end;
 
126
 
 
127
procedure TTestFoldedView.TstUnFoldAtCaret(AName: String; X, Y: integer; AExpectedLines: Array of Integer);
 
128
begin
 
129
  SynEdit.CaretXY := Point(X, Y);
 
130
  TestFoldedText('UnfoldCaret - '+AName, AExpectedLines);
 
131
end;
 
132
 
 
133
// ViewPos is 1 based
 
134
procedure TTestFoldedView.TstTxtIndexToViewPos(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
135
var i: Integer;
 
136
begin
 
137
  i := 0;
 
138
  while i < high(AExpectedPairs)-1 do begin
 
139
    AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') ',
 
140
                 AExpectedPairs[i+1], FoldedView.TextIndexToViewPos(AExpectedPairs[i]));
 
141
    if ADoReverse then
 
142
      AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') to TxtIdx('+IntToStr( AExpectedPairs[i])+') [R]',
 
143
                 AExpectedPairs[i], FoldedView.ViewPosToTextIndex(AExpectedPairs[i+1]));
 
144
    inc(i, 2);
 
145
  end;
 
146
end;
 
147
// ViewPos is 1 based // Reverse of the above
 
148
procedure TTestFoldedView.TstViewPosToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
149
var i: Integer;
 
150
begin
 
151
  i := 0;
 
152
  while i < high(AExpectedPairs)-1 do begin
 
153
    AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') to TxtIdx('+IntToStr( AExpectedPairs[i+1])+')',
 
154
                 AExpectedPairs[i+1], FoldedView.ViewPosToTextIndex(AExpectedPairs[i]));
 
155
    if ADoReverse then
 
156
      AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i+1])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') [R]',
 
157
                 AExpectedPairs[i], FoldedView.TextIndexToViewPos(AExpectedPairs[i+1]));
 
158
    inc(i, 2);
 
159
  end;
 
160
end;
 
161
 
 
162
// ScreenLine is 0 based
 
163
procedure TTestFoldedView.TstTextIndexToScreenLine(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
164
var i: Integer;
 
165
begin
 
166
  i := 0;
 
167
  while i < high(AExpectedPairs)-1 do begin
 
168
    AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i])+') to ScreenLine[0-based]('+IntToStr( AExpectedPairs[i+1])+') ',
 
169
                 AExpectedPairs[i+1], FoldedView.TextIndexToScreenLine(AExpectedPairs[i]));
 
170
    if ADoReverse then
 
171
      AssertEquals(AName+' ScreenLine[0-based]('+IntToStr( AExpectedPairs[i+1])+') to TxtIdx('+IntToStr( AExpectedPairs[i])+') [R]',
 
172
                 AExpectedPairs[i], FoldedView.ScreenLineToTextIndex(AExpectedPairs[i+1]));
 
173
    inc(i, 2);
 
174
  end;
 
175
end;
 
176
// ScreenLine is 0 based // Reverse of the above
 
177
procedure TTestFoldedView.TstScreenLineToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
 
178
var i: Integer;
 
179
begin
 
180
  i := 0;
 
181
  while i < high(AExpectedPairs)-1 do begin
 
182
    AssertEquals(AName+' ScreenLine[0-based]('+IntToStr( AExpectedPairs[i])+') to TxtIdx('+IntToStr( AExpectedPairs[i+1])+') ',
 
183
                 AExpectedPairs[i+1], FoldedView.ScreenLineToTextIndex(AExpectedPairs[i]));
 
184
    if ADoReverse then
 
185
      AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i+1])+') to ScreenLine[0-based]('+IntToStr( AExpectedPairs[i])+') [R]',
 
186
                 AExpectedPairs[i], FoldedView.TextIndexToScreenLine(AExpectedPairs[i+1]));
 
187
    inc(i, 2);
 
188
  end;
 
189
end;
 
190
 
 
191
 
 
192
 
 
193
 
52
194
procedure TTestFoldedView.TestFoldedText(AName: String; ALines: array of Integer);
53
195
var
54
196
  ExpTxt: String;
55
197
  i: Integer;
56
 
  tmp: String;
 
198
  tmp, tmp1, tmp2, tmp3: String;
57
199
  function GetFoldedText: String;
58
200
  var I: Integer;
59
201
  begin
67
209
  for i := 0 to high(ALines) do ExpTxt := ExpTxt + SynEdit.Lines[ALines[i]] + LineEnding;
68
210
  TestCompareString('', ExpTxt, GetFoldedText);
69
211
 
 
212
  if DoAutoFoldDescTests or DoAutoFoldDescTestsReadOnly then begin
 
213
    tmp  := FoldedView.GetFoldDescription(0, 1, -1, -1, False, False);
 
214
    tmp1 := FoldedView.GetFoldDescription(0, 1, -1, -1, False, True);
 
215
    tmp2 := FoldedView.GetFoldDescription(0, 1, -1, -1, True, False);
 
216
    tmp3 := FoldedView.GetFoldDescription(0, 1, -1, -1, True, True);
 
217
  end;
 
218
 
 
219
 
70
220
  FoldedView.FixFoldingAtTextIndex(0, SynEdit.Lines.Count-1);
71
221
  TestCompareString('after FixFolding', ExpTxt, GetFoldedText);
72
222
 
 
223
  if DoAutoFoldDescTests or DoAutoFoldDescTestsReadOnly then begin
 
224
    TestCompareString('GetFoldDesc after Fix fold 1', tmp,  FoldedView.GetFoldDescription(0, 1, -1, -1, False, False));
 
225
    TestCompareString('GetFoldDesc after Fix fold 2', tmp1, FoldedView.GetFoldDescription(0, 1, -1, -1, False, True));
 
226
    TestCompareString('GetFoldDesc after Fix fold 3', tmp2, FoldedView.GetFoldDescription(0, 1, -1, -1, True, False));
 
227
    TestCompareString('GetFoldDesc after Fix fold 4', tmp3, FoldedView.GetFoldDescription(0, 1, -1, -1, True, True));
 
228
  end;
 
229
 
73
230
  if DoAutoFoldDescTests then begin
74
231
    tmp := FoldedView.GetFoldDescription(0, 1, -1, -1, False, False);
75
232
    //debugln(MyDbg(tmp));
210
367
  Result[7] := '';
211
368
end;
212
369
 
 
370
function TTestFoldedView.TestText6: TStringArray;
 
371
begin
 
372
  SetLength(Result, 8);
 
373
  Result[0] := 'program Foo;';
 
374
  Result[1] := 'procedure a; procedure b;';          // 2 folds open on one line
 
375
  Result[2] := '  begin writeln(1);';
 
376
  Result[3] := '  end; // inner';
 
377
  Result[4] := 'begin';
 
378
  Result[5] := '    writeln(2)';
 
379
  Result[6]:= 'end;';
 
380
  Result[7]:= '';
 
381
end;
 
382
 
 
383
function TTestFoldedView.TestText7: TStringArray;
 
384
begin
 
385
  SetLength(Result, 27);
 
386
  Result[0] := 'program Foo;';
 
387
  Result[1] := '{$IFDEF x1}';
 
388
  Result[2] := '{$IFDEF x2} {$IFDEF x3}';
 
389
  Result[3] := '{$IFDEF x4} {$IFDEF x5} {$IFDEF x6} {$IFDEF x7}';
 
390
  Result[4] := '{$IFDEF x8} {$IFDEF x9} {$IFDEF xA}';
 
391
  Result[5] := '//foo A';
 
392
  Result[6] := '{$ENDIF XA}';
 
393
  Result[7] := '//foo 9';
 
394
  Result[8] := '{$ENDIF X9}';
 
395
  Result[9] := '//foo 8';
 
396
  Result[10] := '{$ENDIF X8}';
 
397
  Result[11] := '//foo 7';
 
398
  Result[12] := '{$ENDIF X7}';
 
399
  Result[13] := '//foo 6';
 
400
  Result[14] := '{$ENDIF X6}';
 
401
  Result[15] := '//foo 5';
 
402
  Result[16] := '{$ENDIF X5}';
 
403
  Result[17] := '//foo 4';
 
404
  Result[18] := '{$ENDIF X4}';
 
405
  Result[19] := '//foo 3';
 
406
  Result[20] := '{$ENDIF X3}';
 
407
  Result[21] := '//foo 2';
 
408
  Result[22] := '{$ENDIF X2}';
 
409
  Result[23] := '//foo 1';
 
410
  Result[24] := '{$ENDIF X1}';
 
411
  Result[25] := '//bar';
 
412
  Result[26] := '';
 
413
end;
 
414
 
 
415
function TTestFoldedView.TestText8: TStringArray;
 
416
begin
 
417
  // end begin lines, with mixed type
 
418
  SetLength(Result, 20);
 
419
  Result[0]  := 'program Foo;';
 
420
  Result[1]  := 'procedure a;';
 
421
  Result[2]  := 'begin';
 
422
  Result[3]  := '{%region}';
 
423
  Result[4]  := '{%endregion} {$ifdef x}';
 
424
  Result[5]  := '             {$endif} if a then begin';
 
425
  Result[6]  := '                      end;             {%region}';
 
426
  Result[7]  := '{%endregion} {$ifdef x}';
 
427
  Result[8]  := '             {$endif} if a then begin';
 
428
  Result[9]  := '                        writeln(1);';
 
429
  Result[10] := '{%region}             end;';
 
430
  Result[11] := '  writeln(1);';
 
431
  Result[12] := '{%endregion}  if a then begin';
 
432
  Result[13] := '                        writeln(1);';
 
433
  Result[14] := '{$ifdef x}    end;';
 
434
  Result[15] := '  writeln(1);';
 
435
  Result[16] := '{$endif}';
 
436
  Result[17] := '  writeln(1);';
 
437
  Result[18] := 'end';
 
438
  Result[19] := '';
 
439
end;
 
440
 
 
441
function TTestFoldedView.TestText9: TStringArray;
 
442
begin
 
443
  // end begin lines, with mixed type
 
444
  SetLength(Result, 9);
 
445
  Result[0]  := 'program Foo;';
 
446
  Result[1]  := 'procedure a;';
 
447
  Result[2]  := 'begin  {%region}';
 
448
  Result[3]  := '';
 
449
  Result[4]  := '{%endregion} ';
 
450
  Result[5]  := '';
 
451
  Result[6]  := 'end;';
 
452
  Result[7] := 'end';
 
453
  Result[8] := '';
 
454
 
 
455
end;
 
456
 
 
457
function TTestFoldedView.TestText10: TStringArray;
 
458
begin
 
459
  SetLength(Result, 17);
 
460
  Result[0]  := 'program Project1;';
 
461
  Result[1]  := 'begin';
 
462
  Result[2]  := '';
 
463
  Result[3]  := '  if 1=2 then begin';
 
464
  Result[4]  := '';
 
465
  Result[5]  := '  end;';
 
466
  Result[6]  := '';
 
467
  Result[7]  := '  if 1=3 then begin';
 
468
  Result[8]  := '';
 
469
  Result[9]  := '';
 
470
  Result[10] := '';
 
471
  Result[11] := '';
 
472
  Result[12] := '  end;';
 
473
  Result[13] := '';
 
474
  Result[14] := 'end.';
 
475
  Result[15] := '';
 
476
  Result[16] := '';
 
477
 
 
478
end;
 
479
 
213
480
function TTestFoldedView.TestTextHide(ALen: Integer): TStringArray;
214
481
begin
215
482
  SetLength(Result, 3+ALen);
262
529
 
263
530
end;
264
531
 
 
532
function TTestFoldedView.TestTextPlain: TStringArray;
 
533
begin
 
534
  SetLength(Result, 11);
 
535
  Result[0] := 'begin';
 
536
  Result[1] := 'l1';
 
537
  Result[2] := 'end';
 
538
  Result[3] := 'l2';
 
539
  Result[4] := 'l3';
 
540
  Result[5] := 'l4';
 
541
  Result[6] := 'l5';
 
542
  Result[7] := 'begin';
 
543
  Result[8] := 'l6';
 
544
  Result[9] := 'end';
 
545
  Result[10] := '';
 
546
 
 
547
end;
 
548
 
 
549
function TTestFoldedView.TestTextBug21473: TStringArray;
 
550
begin
 
551
  SetLength(Result, 35);
 
552
  Result[ 0] := 'program a;';
 
553
  Result[ 1] := '';
 
554
  Result[ 2] := '// 1';
 
555
  Result[ 3] := '// 2';
 
556
  Result[ 4] := 'procedure Bar;';
 
557
  Result[ 5] := '';
 
558
  Result[ 6] := '  procedure BarA;';
 
559
  Result[ 7] := '  begin';
 
560
  Result[ 8] := '  end;';
 
561
  Result[ 9] := '';
 
562
  Result[10] := '  procedure BarB;';
 
563
  Result[11] := '  begin';
 
564
  Result[12] := '  end;';
 
565
  Result[13] := '';
 
566
  Result[14] := 'begin';
 
567
  Result[15] := 'end;';
 
568
  Result[16] := '';
 
569
  Result[17] := '// 1';
 
570
  Result[18] := '// 2';
 
571
  Result[19] := 'procedure Foo;';
 
572
  Result[20] := '';
 
573
  Result[21] := '  procedure FooA;';
 
574
  Result[22] := '  begin';
 
575
  Result[23] := '  end;';
 
576
  Result[24] := '';
 
577
  Result[25] := '  procedure FooB;';
 
578
  Result[26] := '  begin';
 
579
  Result[27] := '  end;';
 
580
  Result[28] := '';
 
581
  Result[29] := 'begin';
 
582
  Result[30] := 'end;';
 
583
  Result[31] := '';
 
584
  Result[32] := 'end.';
 
585
  Result[33] := '';
 
586
  Result[34] := '';
 
587
end;
 
588
 
265
589
 
266
590
procedure TTestFoldedView.TestFold;
267
 
 
268
 
  procedure TstSetText(AName: String; AText: TStringArray);
269
 
  begin
270
 
    PopBaseName;
271
 
    ReCreateEdit;
272
 
    SetLines(AText);
273
 
    PushBaseName(AName);
274
 
  end;
275
 
 
276
 
  procedure TstFold(AName: String; AFoldAtIndex: integer; AExpectedLines: Array of Integer);
277
 
  begin
278
 
    FoldedView.FoldAtTextIndex(AFoldAtIndex);
279
 
    TestFoldedText(AName, AExpectedLines);
280
 
  end;
281
 
  procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum: integer; AExpectedLines: Array of Integer);
282
 
  begin
283
 
    FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum);
284
 
    TestFoldedText(AName, AExpectedLines);
285
 
  end;
286
 
  procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
287
 
    AExpectedLines: Array of Integer);
288
 
  begin
289
 
    FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt);
290
 
    TestFoldedText(AName, AExpectedLines);
291
 
  end;
292
 
  procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
293
 
    AFoldAtSkip: Boolean; AExpectedLines: Array of Integer);
294
 
  begin
295
 
    FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt, AFoldAtSkip);
296
 
    TestFoldedText(AName, AExpectedLines);
297
 
  end;
298
 
  procedure TstFold(AName: String; AFoldAtIndex, AFoldAtColum, AFoldAtColCnt: integer;
299
 
    AFoldAtSkip: Boolean; AVisibleLines: Integer; AExpectedLines: Array of Integer);
300
 
  begin
301
 
    FoldedView.FoldAtTextIndex(AFoldAtIndex, AFoldAtColum, AFoldAtColCnt, AFoldAtSkip, AVisibleLines);
302
 
    TestFoldedText(AName, AExpectedLines);
303
 
  end;
304
 
 
305
 
  procedure TstUnFoldAtCaret(AName: String; X, Y: integer; AExpectedLines: Array of Integer);
306
 
  begin
307
 
    SynEdit.CaretXY := Point(X, Y);
308
 
    TestFoldedText('UnfoldCaret - '+AName, AExpectedLines);
309
 
  end;
310
 
 
311
 
  // ViewPos is 1 based
312
 
  procedure TstTxtIndexToViewPos(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
313
 
  var i: Integer;
314
 
  begin
315
 
    i := 0;
316
 
    while i < high(AExpectedPairs)-1 do begin
317
 
      AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') ',
318
 
                   AExpectedPairs[i+1], FoldedView.TextIndexToViewPos(AExpectedPairs[i]));
319
 
      if ADoReverse then
320
 
        AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i+1])+') to TxtIdx('+IntToStr( AExpectedPairs[i])+') [R]',
321
 
                   AExpectedPairs[i], FoldedView.ViewPosToTextIndex(AExpectedPairs[i+1]));
322
 
      inc(i, 2);
323
 
    end;
324
 
  end;
325
 
  // ViewPos is 1 based // Reverse of the above
326
 
  procedure TstViewPosToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
327
 
  var i: Integer;
328
 
  begin
329
 
    i := 0;
330
 
    while i < high(AExpectedPairs)-1 do begin
331
 
      AssertEquals(AName+' ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') to TxtIdx('+IntToStr( AExpectedPairs[i+1])+')',
332
 
                   AExpectedPairs[i+1], FoldedView.ViewPosToTextIndex(AExpectedPairs[i]));
333
 
      if ADoReverse then
334
 
        AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i+1])+') to ViewPos[1-based]('+IntToStr( AExpectedPairs[i])+') [R]',
335
 
                   AExpectedPairs[i], FoldedView.TextIndexToViewPos(AExpectedPairs[i+1]));
336
 
      inc(i, 2);
337
 
    end;
338
 
  end;
339
 
 
340
 
  // ScreenLine is 0 based
341
 
  procedure TstTextIndexToScreenLine(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
342
 
  var i: Integer;
343
 
  begin
344
 
    i := 0;
345
 
    while i < high(AExpectedPairs)-1 do begin
346
 
      AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i])+') to ScreenLine[0-based]('+IntToStr( AExpectedPairs[i+1])+') ',
347
 
                   AExpectedPairs[i+1], FoldedView.TextIndexToScreenLine(AExpectedPairs[i]));
348
 
      if ADoReverse then
349
 
        AssertEquals(AName+' ScreenLine[0-based]('+IntToStr( AExpectedPairs[i+1])+') to TxtIdx('+IntToStr( AExpectedPairs[i])+') [R]',
350
 
                   AExpectedPairs[i], FoldedView.ScreenLineToTextIndex(AExpectedPairs[i+1]));
351
 
      inc(i, 2);
352
 
    end;
353
 
  end;
354
 
  // ScreenLine is 0 based // Reverse of the above
355
 
  procedure TstScreenLineToTextIndex(AName: String; AExpectedPairs: Array of Integer; ADoReverse: Boolean = false);
356
 
  var i: Integer;
357
 
  begin
358
 
    i := 0;
359
 
    while i < high(AExpectedPairs)-1 do begin
360
 
      AssertEquals(AName+' ScreenLine[0-based]('+IntToStr( AExpectedPairs[i])+') to TxtIdx('+IntToStr( AExpectedPairs[i+1])+') ',
361
 
                   AExpectedPairs[i+1], FoldedView.ScreenLineToTextIndex(AExpectedPairs[i]));
362
 
      if ADoReverse then
363
 
        AssertEquals(AName+' TxtIdx('+IntToStr( AExpectedPairs[i+1])+') to ScreenLine[0-based]('+IntToStr( AExpectedPairs[i])+') [R]',
364
 
                   AExpectedPairs[i], FoldedView.TextIndexToScreenLine(AExpectedPairs[i+1]));
365
 
      inc(i, 2);
366
 
    end;
367
 
  end;
368
 
 
369
591
  procedure RunTest;
 
592
  var
 
593
    i: Integer;
370
594
  begin
371
595
    PushBaseName('');
372
596
 
573
797
    AssertEquals(FoldedView.Count, 4999-2);
574
798
  {%endregion}
575
799
 
 
800
  {%region Text7 fold at indes, skip, ...}
 
801
    (* Arguments for (Un)FoldAt* (Line, ViewPos, TextIndex):
 
802
       - ColumnIndex (0-based)
 
803
           Can be negative, to access the highest(-1) available, 2nd highest(-2) ...
 
804
           If negative, count points downward
 
805
       - ColCount = 0 => all
 
806
       - Skip => Do not count nodes that are already in the desired state
 
807
           (or can not archive the desired state: e.g. can not hide)
 
808
       - AVisibleLines: 0 = Hide / 1 = Fold
 
809
    *)
 
810
    TstSetText('Text7 fold at indes, skip, ...', TestText7);
 
811
    {%region fold one}
 
812
    for i := 0 to 1 do begin
 
813
      PushBaseName('X='+IntToStr(i));
 
814
      SynEdit.UnfoldAll;
 
815
      TstFold('fold one col (pos): 0,1,x', 3,   0, 1, i=0, 1,  [0, 1, 2, 3,  19, 20, 21, 22, 23, 24, 25]);
 
816
      SynEdit.UnfoldAll;
 
817
      TstFold('fold one col (pos): 1,1,x', 3,   1, 1, i=0, 1,  [0, 1, 2, 3,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
818
      SynEdit.UnfoldAll;
 
819
      TstFold('fold one col (pos): 2,1,x', 3,   2, 1, i=0, 1,  [0, 1, 2, 3,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
820
      SynEdit.UnfoldAll;
 
821
      TstFold('fold one col (pos): 3,1,x', 3,   3, 1, i=0, 1,  [0, 1, 2, 3,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
822
      SynEdit.UnfoldAll;
 
823
      TstFold('NOT fold one col (pos): 4,1,x', 3,   4, 1, i=0, 1,  [0, 1, 2, 3, 4,5,6,7,8,9,10,11,12, 13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
824
 
 
825
      SynEdit.UnfoldAll;
 
826
      TstFold('fold one col (neg): -4,1,x', 3,   -4, 1, i=0, 1,  [0, 1, 2, 3,  19, 20, 21, 22, 23, 24, 25]);
 
827
      SynEdit.UnfoldAll;
 
828
      TstFold('fold one col (neg): -3,1,x', 3,   -3, 1, i=0, 1,  [0, 1, 2, 3,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
829
      SynEdit.UnfoldAll;
 
830
      TstFold('fold one col (neg): -2,1,x', 3,   -2, 1, i=0, 1,  [0, 1, 2, 3,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
831
      SynEdit.UnfoldAll;
 
832
      TstFold('fold one col (neg): -1,1,x', 3,   -1, 1, i=0, 1,  [0, 1, 2, 3,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
833
      SynEdit.UnfoldAll;
 
834
      TstFold('NOT fold one col (neg): -5,1,x', 3,   -5, 1, i=0, 1,  [0, 1, 2, 3, 4,5,6,7,8,9,10,11,12, 13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
835
 
 
836
 
 
837
      DoAutoFoldDescTestsReadOnly := DoAutoFoldDescTests;
 
838
      DoAutoFoldDescTests := False;
 
839
      // SKIP, if DoAutoFoldDescTests, since fold-info-apply checks for correct node type, and this code force hide.
 
840
 
 
841
      SynEdit.UnfoldAll;
 
842
      TstFold('hide one col (pos): 0,1,x', 3,   0, 1, i=0, 0,  [0, 1, 2,  19, 20, 21, 22, 23, 24, 25]);
 
843
      SynEdit.UnfoldAll;
 
844
      TstFold('hide one col (pos): 1,1,x', 3,   1, 1, i=0, 0,  [0, 1, 2,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
845
      SynEdit.UnfoldAll;
 
846
      TstFold('hide one col (pos): 2,1,x', 3,   2, 1, i=0, 0,  [0, 1, 2,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
847
      SynEdit.UnfoldAll;
 
848
      TstFold('hide one col (pos): 3,1,x', 3,   3, 1, i=0, 0,  [0, 1, 2,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
849
      SynEdit.UnfoldAll;
 
850
      TstFold('NOT hide one col (pos): 4,1,x', 3,   4, 1, i=0, 0,  [0, 1, 2, 3, 4,5,6,7,8,9,10,11,12, 13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
851
 
 
852
      SynEdit.UnfoldAll;
 
853
      TstFold('hide all-after col (pos): 0,1,x', 3,   0, 0, i=0, 0,  [0, 1, 2,  19, 20, 21, 22, 23, 24, 25]);
 
854
      SynEdit.UnfoldAll;
 
855
      TstFold('hide all-after col (pos): 1,1,x', 3,   1, 0, i=0, 0,  [0, 1, 2,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
856
      SynEdit.UnfoldAll;
 
857
      TstFold('hide all-after col (pos): 2,1,x', 3,   2, 0, i=0, 0,  [0, 1, 2,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
858
      SynEdit.UnfoldAll;
 
859
      TstFold('hide all-after col (pos): 3,1,x', 3,   3, 0, i=0, 0,  [0, 1, 2,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
860
      SynEdit.UnfoldAll;
 
861
      TstFold('NOT hide all-after col (pos): 4,1,x', 3,   4, 1, i=0, 0,  [0, 1, 2, 3, 4,5,6,7,8,9,10,11,12, 13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
862
 
 
863
      DoAutoFoldDescTests := DoAutoFoldDescTestsReadOnly;
 
864
 
 
865
 
 
866
      PopBaseName;
 
867
    end;
 
868
    {%endregion}
 
869
 
 
870
    {%region fold two}
 
871
      {%region  1st:: 0,1,F}
 
872
        // 1st:: 0,1,F // SKIP=False
 
873
        SynEdit.UnfoldAll; PushBaseName('(1st:: 0,1,F / 2nd::  x=1 no-sk c=1)');
 
874
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
875
        TstFold  ('  fold 2nd col (pos/no-sk): 1,1,F', 3,   1, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
876
        TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
877
 
 
878
        SynEdit.UnfoldAll; PushBaseName('(1st:: 0,1,F / 2nd::  x=2 no-sk c=1)');
 
879
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
880
        TstFold  ('  fold 3rd col (pos/no-sk): 2,1,F', 3,   2, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
881
        TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
882
 
 
883
        SynEdit.UnfoldAll; PushBaseName('(1st:: 0,1,F / 2nd::  x=3 no-sk c=1)');
 
884
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
885
        TstFold  ('  fold 4th col (pos/no-sk): 3,1,F', 3,   3, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
886
        TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
887
 
 
888
        // 1st:: 0,1,F // SKIP=True
 
889
        SynEdit.UnfoldAll; PopPushBaseName('(1st:: 0,1,F / 2nd::  x=0 skip c=1)');
 
890
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
891
        TstFold  ('  fold 2nd col (pos/skip):  0,1,T', 3,   0, 1, True,  1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
892
  //      TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  17,18,19, 20, 21, 22, 23, 24, 25]);
 
893
 
 
894
        SynEdit.UnfoldAll; PopPushBaseName('(1st:: 0,1,F / 2nd::  x=1 skip c=1)');
 
895
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
896
        TstFold  ('  fold 3rd col (pos/skip):  1,1,T', 3,   1, 1, True,  1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
897
  //      TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
898
 
 
899
        SynEdit.UnfoldAll; PopPushBaseName('(1st:: 0,1,F / 2nd::  x=2 skip c=1)');
 
900
        TstFold  ('  fold pre-one col (pos):   0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
901
        TstFold  ('  fold 4th col (pos/skip):  2,1,T', 3,   2, 1, True,  1,  [0,1,2,3,  19, 20, 21, 22, 23, 24, 25]);
 
902
  //      TstUnFold('UNfold 1st col (pos/no-sk): 0,1,F', 3,   0, 1, False, 1,  [0,1,2,3,  13,14,15,16,17,18,19, 20, 21, 22, 23, 24, 25]);
 
903
      {%endregion}
 
904
 
 
905
      {%region  1st:: 1,1,F}
 
906
      {%endregion}
 
907
 
 
908
      {%region  1st:: -1,1,F}
 
909
      {%endregion}
 
910
 
 
911
      {%region  1st:: -2,1,F}
 
912
      {%endregion}
 
913
    {%endregion}
 
914
  {%endregion Text7 fold at indes, skip, ...}
 
915
 
 
916
 
576
917
  end;
577
918
 
578
919
begin
587
928
  RunTest;
588
929
end;
589
930
 
 
931
procedure TTestFoldedView.TestFoldEdit;
 
932
 
 
933
  procedure DoChar(x, y: integer; char: String);
 
934
  begin
 
935
    SynEdit.CaretXY := Point(x,y);
 
936
    SynEdit.CommandProcessor(ecChar, char, nil);
 
937
  end;
 
938
  procedure DoNewLine(x, y: integer);
 
939
  begin
 
940
    SynEdit.CaretXY := Point(x,y);
 
941
    SynEdit.CommandProcessor(ecLineBreak, '', nil);
 
942
  end;
 
943
  procedure DoBackspace(x, y: integer);
 
944
  begin
 
945
    SynEdit.CaretXY := Point(x,y);
 
946
    SynEdit.CommandProcessor(ecDeleteLastChar, '', nil);
 
947
  end;
 
948
 
 
949
  procedure TestNodeAtPos(name: string; x, y: integer; ExpClassification: TFoldNodeClassification = fncHighlighter);
 
950
  var
 
951
    n: TSynTextFoldAVLNode;
 
952
  begin
 
953
    n := TSynEditFoldedViewHack(FoldedView).FoldTree.FindFoldForLine(y, true);
 
954
    AssertTrue(BaseTestName+' '+ name+ ' got node for line '+inttostr(y), n.IsInFold);
 
955
    AssertTrue(BaseTestName+' '+ name+ ' got node Classification for line '+inttostr(y), n.Classification = ExpClassification);
 
956
    AssertEquals(BaseTestName+' '+ name+ ' got node for src-line '+inttostr(y), y, n.SourceLine);
 
957
    AssertEquals(BaseTestName+' '+ name+ ' got node for src-line '+inttostr(y)+' col='+inttostr(x), x, n.FoldColumn);
 
958
  end;
 
959
 
 
960
var
 
961
  n: string;
 
962
  i: integer;
 
963
  s: String;
 
964
begin
 
965
 
 
966
  {%region simple}
 
967
    TstSetText('Simple: fold Prc', TestText);
 
968
 
 
969
    TstFold('', 1, [0, 1]);
 
970
    TestNodeAtPos('', 1, 2);
 
971
 
 
972
    DoChar(1,2, ' ');
 
973
    TestFoldedText('(ins char)', [0, 1]);
 
974
    TestNodeAtPos('(ins char)', 2, 2);
 
975
 
 
976
    DoNewLine(13,1);
 
977
    TestFoldedText('(newline before)', [0, 1, 2]);
 
978
    TestNodeAtPos('(newline before)', 2, 3);
 
979
 
 
980
    DoBackspace(1,2);
 
981
    TestFoldedText('(del newline)', [0, 1]);
 
982
    TestNodeAtPos('(del newline)', 2, 2);
 
983
 
 
984
    DoBackspace(2,2);
 
985
    TestFoldedText('(del char)', [0, 1]);
 
986
    TestNodeAtPos('(del char)', 1, 2);
 
987
 
 
988
    DoBackspace(1,2);
 
989
    TestFoldedText('(del to prev line)', [0]);
 
990
    TestNodeAtPos('(del to prev line)', 13, 1);
 
991
 
 
992
    DoNewLine(13,1);  // newline, on same line
 
993
    TestFoldedText('(newline on srcline)', [0, 1]);
 
994
    TestNodeAtPos('(newline on srcline)', 1, 2);
 
995
    PopBaseName;
 
996
 
 
997
    TstSetText('Simple 2: edit del foldable line', TestText3);
 
998
    TstFold('', 7, [0, 1, 2, 3, 4, 5, 6, 7,  10, 11]);
 
999
    SetCaretAndSel(1,3, 1,4);
 
1000
    SynEdit.CommandProcessor(ecDeleteChar, '', nil);
 
1001
    TestFoldedText('fold after', [0, 1, 2, 3, 4, 5, 6,  9, 10]);
 
1002
 
 
1003
 
 
1004
    PopBaseName;
 
1005
  {%endregion}
 
1006
 
 
1007
  {%region Nested}
 
1008
    TstSetText('Nested: fold Prc Beg ', TestText);
 
1009
 
 
1010
    for i := 0 to 63 do begin
 
1011
      PushBaseName(inttostr(i));
 
1012
      SetLines(TestText);
 
1013
      SynEdit.UnfoldAll;
 
1014
      n := '';
 
1015
      TstFold(n, 2, [0, 1, 2]);             TestNodeAtPos(n, 1, 3);
 
1016
      n := 'outer';
 
1017
      TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2);
 
1018
 
 
1019
      n := '(ins char)';
 
1020
      //debugln(['############### ',n]);
 
1021
      DoChar(1,2, ' ');
 
1022
      TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 2, 2);
 
1023
      if (i and 1) <> 0 then begin
 
1024
        n := '(ins char) nested';
 
1025
        //debugln(['############### ',n]);
 
1026
        TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 1, 3);
 
1027
        n := '(ins char) refold';
 
1028
        TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 2, 2); // re-folded
 
1029
      end;
 
1030
 
 
1031
      n := '(newline before)';
 
1032
        //debugln(['############### ',n]);
 
1033
      DoNewLine(13,1);
 
1034
      TestFoldedText(n, [0, 1, 2]);         TestNodeAtPos(n, 2, 3);
 
1035
      if (i and 2) <> 0 then begin
 
1036
        n := '(newline before) nested';
 
1037
        //debugln(['############### ',n]);
 
1038
        TstUnFoldAtCaret(n, 1,4, [0,1,2,3]);  TestNodeAtPos(n, 1, 4);
 
1039
        n := '(newline before) refold';
 
1040
        TstFold(n, 2, [0, 1, 2]);             TestNodeAtPos(n, 2, 3); // re-folded
 
1041
      end;
 
1042
 
 
1043
      n := '(del newline)';
 
1044
      //debugln(['############### ',n]);
 
1045
      DoBackspace(1,2);
 
1046
      TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 2, 2);
 
1047
      if (i and 4) <> 0 then begin
 
1048
        n := '(del newline) nested';
 
1049
        //debugln(['############### ',n]);
 
1050
        TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 1, 3);
 
1051
        n := '(del newline) refold';
 
1052
        TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 2, 2); // re-folded
 
1053
      end;
 
1054
 
 
1055
      n := '(del char)';
 
1056
      //debugln(['############### ',n]);
 
1057
      DoBackspace(2,2);
 
1058
      TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 1, 2);
 
1059
      if (i and 8) <> 0 then begin
 
1060
        n := '(del char) nested';
 
1061
        //debugln(['############### ',n]);
 
1062
        TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 1, 3);
 
1063
        n := '(del char) refold';
 
1064
        TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2); // re-folded
 
1065
      end;
 
1066
 
 
1067
      n := '(del to prev line)';
 
1068
      //debugln(['############### ',n]);
 
1069
      DoBackspace(1,2);
 
1070
      TestFoldedText(n, [0]);               TestNodeAtPos(n, 13, 1);
 
1071
      if (i and 16) <> 0 then begin
 
1072
        n := '(del to prev line) nested';
 
1073
        TstUnFoldAtCaret(n, 1,2, [0,1]);    TestNodeAtPos(n, 1, 2);
 
1074
        n := '(del to prev line) refold';
 
1075
        TstFold(n, 0, [0]);                TestNodeAtPos(n, 13, 1); // re-folded
 
1076
      end;
 
1077
 
 
1078
      n := '(newline on srcline)';
 
1079
      DoNewLine(13,1);  // newline, on same line
 
1080
      TestFoldedText(n, [0, 1]);           TestNodeAtPos(n, 1, 2);
 
1081
      if (i and 32) <> 0 then begin
 
1082
        n := '(del to prev line) nested';
 
1083
        TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 1, 3);
 
1084
        n := '(del to prev line) refold';
 
1085
        TstFold(n, 1, [0,1]);                TestNodeAtPos(n, 1, 2); // re-folded
 
1086
      end;
 
1087
 
 
1088
      PopBaseName;
 
1089
    end;
 
1090
    PopBaseName;
 
1091
  {%endregion}
 
1092
 
 
1093
  {%region Nested}
 
1094
  TstSetText('Nested, same line: fold Prc Beg', TestText6);
 
1095
 
 
1096
    for i := 0 to 255 do begin
 
1097
      PushBaseName(inttostr(i));
 
1098
      SetLines(TestText6);
 
1099
      SynEdit.UnfoldAll;
 
1100
      n := '';
 
1101
      TstFold(n, 1, 1, [0, 1, 4,5,6]);             TestNodeAtPos(n, 14, 2);
 
1102
      n := 'outer';
 
1103
      TstFold(n, 1, 0, [0, 1]);                    TestNodeAtPos(n, 1, 2);
 
1104
 
 
1105
      n := '(ins char)';
 
1106
      //debugln(['############### ',n]);
 
1107
      DoChar(1,2, ' ');
 
1108
      TestFoldedText(n, [0, 1]);                    TestNodeAtPos(n, 2, 2);
 
1109
      if (i and 1) <> 0 then begin
 
1110
        n := '(ins char) nested';
 
1111
        //debugln(['############### ',n]);
 
1112
        TstUnFoldAtCaret(n, 1,5, [0,1,4,5,6]);      TestNodeAtPos(n, 15, 2);
 
1113
        n := '(ins char) refold';
 
1114
        TstFold(n, 1, 0, [0, 1]);                   TestNodeAtPos(n, 2, 2); // re-folded
 
1115
      end;
 
1116
 
 
1117
      n := '(ins char middle)';
 
1118
      //debugln(['############### ',n]);
 
1119
      DoChar(14,2, ' ');
 
1120
      TestFoldedText(n, [0, 1]);                    TestNodeAtPos(n, 2, 2);
 
1121
      if (i and 2) <> 0 then begin
 
1122
        n := '(ins char middle) nested';
 
1123
        //debugln(['############### ',n]);
 
1124
        TstUnFoldAtCaret(n, 1,5, [0,1,4,5,6]);      TestNodeAtPos(n, 16, 2);
 
1125
        n := '(ins char middle) refold';
 
1126
        TstFold(n, 1, 0, [0, 1]);                   TestNodeAtPos(n, 2, 2); // re-folded
 
1127
      end;
 
1128
 
 
1129
 
 
1130
      n := '(newline before)';
 
1131
        //debugln(['############### ',n]);
 
1132
      DoNewLine(13,1);
 
1133
      TestFoldedText(n, [0, 1, 2]);                 TestNodeAtPos(n, 2, 3);
 
1134
      if (i and 4) <> 0 then begin
 
1135
        n := '(newline before) nested';
 
1136
        //debugln(['############### ',n]);
 
1137
        TstUnFoldAtCaret(n, 1,6, [0,1,2, 5,6,7]);   TestNodeAtPos(n, 16, 3);
 
1138
        n := '(newline before) refold';
 
1139
        TstFold(n, 2, 0, [0, 1, 2]);                TestNodeAtPos(n, 2, 3); // re-folded
 
1140
      end;
 
1141
 
 
1142
      n := '(del newline)';
 
1143
      //debugln(['############### ',n]);
 
1144
      DoBackspace(1,2);
 
1145
      TestFoldedText(n, [0, 1]);                   TestNodeAtPos(n, 2, 2);
 
1146
      if (i and 8) <> 0 then begin
 
1147
        n := '(del newline) nested';
 
1148
        //debugln(['############### ',n]);
 
1149
        TstUnFoldAtCaret(n, 1,5, [0,1, 4,5,6]);    TestNodeAtPos(n, 16, 2);
 
1150
        n := '(del newline) refold';
 
1151
        TstFold(n, 1, 0, [0, 1]);                  TestNodeAtPos(n, 2, 2); // re-folded
 
1152
      end;
 
1153
 
 
1154
      n := '(del char)';
 
1155
      //debugln(['############### ',n]);
 
1156
      DoBackspace(2,2);
 
1157
      TestFoldedText(n, [0, 1]);                   TestNodeAtPos(n, 1, 2);
 
1158
      if (i and 16) <> 0 then begin
 
1159
        n := '(del char) nested';
 
1160
        //debugln(['############### ',n]);
 
1161
        TstUnFoldAtCaret(n, 1,5, [0,1,4,5,6]);     TestNodeAtPos(n, 15, 2);
 
1162
        n := '(del char) refold';
 
1163
        TstFold(n, 1, 0, [0, 1]);                  TestNodeAtPos(n, 1, 2); // re-folded
 
1164
      end;
 
1165
 
 
1166
      n := '(del char middle)';
 
1167
      //debugln(['############### ',n]);
 
1168
      DoBackspace(15,2);
 
1169
      TestFoldedText(n, [0, 1]);                   TestNodeAtPos(n, 1, 2);
 
1170
      if (i and 32) <> 0 then begin
 
1171
        n := '(del char middle) nested';
 
1172
        //debugln(['############### ',n]);
 
1173
        TstUnFoldAtCaret(n, 1,5, [0,1,4,5,6]);     TestNodeAtPos(n, 14, 2);
 
1174
        n := '(del char middle) refold';
 
1175
        TstFold(n, 1, 0, [0, 1]);                  TestNodeAtPos(n, 1, 2); // re-folded
 
1176
      end;
 
1177
 
 
1178
 
 
1179
      n := '(del to prev line)';
 
1180
      //debugln(['############### ',n]);
 
1181
      DoBackspace(1,2);
 
1182
      TestFoldedText(n, [0]);               TestNodeAtPos(n, 13, 1);
 
1183
      if (i and 64) <> 0 then begin
 
1184
        n := '(del to prev line) nested';
 
1185
        TstUnFoldAtCaret(n, 1,4, [0,3,4,5]);    TestNodeAtPos(n, 26, 1);
 
1186
        n := '(del to prev line) refold';
 
1187
        TstFold(n, 0,1, [0]);                TestNodeAtPos(n, 13, 1); // re-folded idx=1, prg is at 0
 
1188
      end;
 
1189
 
 
1190
      n := '(newline on srcline)';
 
1191
      DoNewLine(13,1);  // newline, on same line
 
1192
      TestFoldedText(n, [0, 1]);           TestNodeAtPos(n, 1, 2);
 
1193
      if (i and 128) <> 0 then begin
 
1194
        n := '(del to prev line) nested';
 
1195
        TstUnFoldAtCaret(n, 1,5, [0,1,4,5,6]);    TestNodeAtPos(n, 14, 2);
 
1196
        n := '(del to prev line) refold';
 
1197
        TstFold(n, 1, 0, [0,1]);                TestNodeAtPos(n, 1, 2); // re-folded
 
1198
      end;
 
1199
 
 
1200
      PopBaseName;
 
1201
    end;
 
1202
  {%endregion}
 
1203
 
 
1204
  {%region}
 
1205
    TstSetText('Nested, same line, new line in middle:', TestText6);
 
1206
    SynEdit.UnfoldAll;
 
1207
    n := '';
 
1208
    TstFold(n, 1, 1, [0, 1, 4,5,6]);             TestNodeAtPos(n, 14, 2);
 
1209
    n := 'outer';
 
1210
    TstFold(n, 1, 0, [0, 1]);                    TestNodeAtPos(n, 1, 2);
 
1211
    n := '(new line)';
 
1212
    //debugln(['############### ',n]);
 
1213
    DoNewLine(14,2);
 
1214
    TestFoldedText(n, [0, 1, 2, 5,6,7]);
 
1215
    TestNodeAtPos(n, 1, 3);
 
1216
    PopBaseName;
 
1217
 
 
1218
    TstSetText('Nested, same line, new line in middle: (2)', TestText6);
 
1219
    SynEdit.UnfoldAll;
 
1220
    n := '';
 
1221
    TstFold(n, 1, 1, [0, 1, 4,5,6]);             TestNodeAtPos(n, 14, 2);
 
1222
    TstFold(n, 1, 0, [0, 1]);                    TestNodeAtPos(n, 1, 2);
 
1223
    n := '(new line)';
 
1224
    //debugln(['############### ',n]);
 
1225
    DoNewLine(13,2);
 
1226
    TestFoldedText(n, [0, 1, 2, 5,6,7]);
 
1227
    TestNodeAtPos(n, 2, 3);
 
1228
    PopBaseName;
 
1229
  {%endregion}
 
1230
 
 
1231
  {%region simple, block edit}
 
1232
    TstSetText('Simple: block edit', TestText);
 
1233
 
 
1234
    TstFold('', 1, [0, 1]);
 
1235
    TestNodeAtPos('', 1, 2);
 
1236
 
 
1237
    SynEdit.TextBetweenPoints[point(1,2), point(1,2)] := ' ';
 
1238
    TestFoldedText('(ins char)', [0, 1]);
 
1239
    TestNodeAtPos('(ins char)', 2, 2);
 
1240
 
 
1241
    SynEdit.TextBetweenPoints[point(13,1), point(13,1)] := LineEnding;
 
1242
    TestFoldedText('(newline before)', [0, 1, 2]);
 
1243
    TestNodeAtPos('(newline before)', 2, 3);
 
1244
 
 
1245
    SynEdit.TextBetweenPoints[point(13,1), point(1,2)] := '';
 
1246
    TestFoldedText('(del newline)', [0, 1]);
 
1247
    TestNodeAtPos('(del newline)', 2, 2);
 
1248
 
 
1249
    SynEdit.TextBetweenPoints[point(1,2), point(2,2)] := '';
 
1250
    TestFoldedText('(del char)', [0, 1]);
 
1251
    TestNodeAtPos('(del char)', 1, 2);
 
1252
 
 
1253
    SynEdit.TextBetweenPoints[point(13,1), point(1,2)] := '';
 
1254
    TestFoldedText('(del to prev line)', [0]);
 
1255
    TestNodeAtPos('(del to prev line)', 13, 1);
 
1256
 
 
1257
    SynEdit.TextBetweenPoints[point(13,1), point(13,1)] := LineEnding;
 
1258
    TestFoldedText('(newline on srcline)', [0, 1]);
 
1259
    TestNodeAtPos('(newline on srcline)', 1, 2);
 
1260
 
 
1261
 
 
1262
    SynEdit.TextBetweenPoints[point(1,3), point(1,3)] := LineEnding;
 
1263
    TestFoldedText('(newline, 1st fold line)', [0, 1]);
 
1264
    TestNodeAtPos('(newline 1st fold line)', 1, 2);
 
1265
 
 
1266
    SynEdit.TextBetweenPoints[point(1,3), point(1,4)] := '';
 
1267
    TestFoldedText('(del newline, 1st fold line)', [0, 1]);
 
1268
    TestNodeAtPos('(del newline 1st fold line)', 1, 2);
 
1269
 
 
1270
    PopBaseName;
 
1271
  {%endregion}
 
1272
 
 
1273
  {%region Nested block edit}
 
1274
    TstSetText('Nested: block edit ', TestText);
 
1275
    //SetLines(TestText);
 
1276
 
 
1277
    n := '(ins char)';
 
1278
    TstFold(n, 2, [0, 1, 2]);             TestNodeAtPos(n, 1, 3);
 
1279
    TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2);
 
1280
    //debugln(['############### ',n]);
 
1281
    SynEdit.TextBetweenPoints[point(1,3), point(1,3)] := ' ';
 
1282
    TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 1, 2);
 
1283
    TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 2, 3);
 
1284
 
 
1285
    n := '(repl char to newline)';
 
1286
    TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2);
 
1287
    //debugln(['############### ',n]);
 
1288
    SynEdit.TextBetweenPoints[point(1,3), point(2,3)] := LineEnding;
 
1289
    TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 1, 2);
 
1290
    TstUnFoldAtCaret(n, 1,4, [0,1,2,3]);    TestNodeAtPos(n, 1, 4);
 
1291
 
 
1292
    n := '(repl newline to char)';
 
1293
    TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2);
 
1294
    //debugln(['############### ',n]);
 
1295
    SynEdit.TextBetweenPoints[point(1,3), point(1,4)] := '  ';
 
1296
    TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 1, 2);
 
1297
    TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 3, 3);
 
1298
 
 
1299
    n := '(del char)';
 
1300
    TstFold(n, 1, [0, 1]);                TestNodeAtPos(n, 1, 2);
 
1301
    //debugln(['############### ',n]);
 
1302
    SynEdit.TextBetweenPoints[point(1,3), point(3,3)] := '';
 
1303
    TestFoldedText(n, [0, 1]);            TestNodeAtPos(n, 1, 2);
 
1304
    TstUnFoldAtCaret(n, 1,3, [0,1,2]);    TestNodeAtPos(n, 1, 3);
 
1305
 
 
1306
  PopBaseName;
 
1307
  {%endregion}
 
1308
 
 
1309
  {%region simple, lines access}
 
1310
    TstSetText('Simple: lines access', TestText);
 
1311
 
 
1312
    TstFold('', 1, [0, 1]);
 
1313
    TestNodeAtPos('', 1, 2);
 
1314
 
 
1315
    SynEdit.Lines.Insert(1,'// foo');
 
1316
    TestFoldedText('(insert before)', [0, 1, 2]);
 
1317
    TestNodeAtPos('(insert before)', 1, 3);
 
1318
 
 
1319
    SynEdit.Lines.Delete(1);
 
1320
    TestFoldedText('(del before)', [0, 1]);
 
1321
    TestNodeAtPos('(del before)', 1, 2);
 
1322
 
 
1323
    SynEdit.Lines.Insert(2,'// foo');
 
1324
    TestFoldedText('(insert inside)', [0, 1]);
 
1325
    TestNodeAtPos('(insert inside)', 1, 2);
 
1326
 
 
1327
    SynEdit.Lines.Delete(2);
 
1328
    TestFoldedText('(del inside)', [0, 1]);
 
1329
    TestNodeAtPos('(del inside)', 1, 2);
 
1330
 
 
1331
    PopBaseName;
 
1332
  {%endregion}
 
1333
 
 
1334
 
 
1335
  {%region hide}
 
1336
    TstSetText('Simple HIDE', TestTextHide(3));
 
1337
 
 
1338
    TstFold('', 1, -1, 1, False, 0, [0, 4]);
 
1339
    TestNodeAtPos('', 1, 2);
 
1340
 
 
1341
    DoNewLine(13,1);
 
1342
    TestFoldedText('(ins newline)', [0, 1, 5]);
 
1343
    TestNodeAtPos('(ins newline)', 1, 3);
 
1344
 
 
1345
    SynEdit.Undo; // cannot use backspace, since caret would unfold
 
1346
    TestFoldedText('(del newline)', [0, 4]);
 
1347
    TestNodeAtPos('(del newline)', 1, 2);
 
1348
 
 
1349
    PopBaseName;
 
1350
  {%endregion}
 
1351
 
 
1352
  {%region hide, block edit}
 
1353
    TstSetText('Simple HIDE: block edit', TestTextHide(3));
 
1354
 
 
1355
// TODO /newline BEFORE
 
1356
    TstFold('', 1, -1, 1, False, 0, [0, 4]);
 
1357
    TestNodeAtPos('', 1, 2);
 
1358
 
 
1359
    SynEdit.TextBetweenPoints[point(13,1), point(13,1)] := LineEnding;
 
1360
    TestFoldedText('(newline before)', [0, 1, 5]);
 
1361
    TestNodeAtPos('(newline before)', 1, 3);
 
1362
 
 
1363
    SynEdit.TextBetweenPoints[point(13,1), point(1,2)] := '';
 
1364
    TestFoldedText('(del newline before)', [0, 4]);
 
1365
    TestNodeAtPos('(del newline before)', 1, 2);
 
1366
 
 
1367
 
 
1368
 
 
1369
    SynEdit.TextBetweenPoints[point(1,2), point(1,2)] := ' ';
 
1370
    TestFoldedText('(ins char)', [0, 4]);
 
1371
    TestNodeAtPos('(ins char)', 2, 2);
 
1372
 
 
1373
    debugln(['############### ins newline']);
 
1374
    SynEdit.TextBetweenPoints[point(1,2), point(2,2)] := LineEnding;
 
1375
    TestFoldedText('(ins newline)', [0, 1, 5]);
 
1376
    TestNodeAtPos('(ins newline)', 1, 3);
 
1377
 
 
1378
    debugln(['############### del newline']);
 
1379
    SynEdit.TextBetweenPoints[point(1,2), point(1,3)] := '  ';
 
1380
    TestFoldedText('(del newline)', [0, 4]);
 
1381
    TestNodeAtPos('(del newline)', 3, 2);
 
1382
 
 
1383
    debugln(['############### del char']);
 
1384
    SynEdit.TextBetweenPoints[point(1,2), point(3,2)] := ' ';
 
1385
    TestFoldedText('(del char)', [0, 4]);
 
1386
    TestNodeAtPos('(del char)', 2, 2);
 
1387
 
 
1388
    debugln(['############### ins newline (again)']);
 
1389
    SynEdit.TextBetweenPoints[point(1,2), point(2,2)] := LineEnding;
 
1390
    TestFoldedText('(ins newline)', [0, 1, 5]);
 
1391
    TestNodeAtPos('(ins newline)', 1, 3);
 
1392
 
 
1393
    debugln(['############### del TWO newline']);
 
1394
    SynEdit.TextBetweenPoints[point(1,2), point(1,4)] := '';
 
1395
    TestFoldedText('(del newline)', [0, 3]);
 
1396
    TestNodeAtPos('(del newline)', 1, 2);
 
1397
 
 
1398
    PopBaseName;
 
1399
  {%endregion}
 
1400
 
 
1401
  {%region lines access}
 
1402
    TstSetText('Simple HIDE: lines access', TestTextHide(3));
 
1403
 
 
1404
    TstFold('', 1, -1, 1, False, 0, [0, 4]);
 
1405
    TestNodeAtPos('', 1, 2);
 
1406
 
 
1407
    SynEdit.Lines.Insert(1,'var a: integer;');
 
1408
    TestFoldedText('(ins newline before)', [0, 1, 5]);
 
1409
    TestNodeAtPos('(ins newline before)', 1, 3);
 
1410
 
 
1411
    SynEdit.Lines.Delete(1);
 
1412
    TestFoldedText('(del newline before)', [0, 4]);
 
1413
    TestNodeAtPos('(del newline before)', 1, 2);
 
1414
 
 
1415
    SynEdit.Lines.Insert(2,'// foo bar');
 
1416
    TestFoldedText('(ins newline inside)', [0, 5]);
 
1417
    TestNodeAtPos('(ins newline inside)', 1, 2);
 
1418
 
 
1419
    SynEdit.Lines.Delete(2);
 
1420
    TestFoldedText('(del newline inside)', [0, 4]);
 
1421
    TestNodeAtPos('(del newline inside)', 1, 2);
 
1422
 
 
1423
    PopBaseName;
 
1424
  {%endregion}
 
1425
 
 
1426
  {%region}
 
1427
    TstSetText('TestText10 remove one entire fold', TestText10);
 
1428
    TstFold('f1', 7, -1, 1, False, 1, [0, 1, 2, 3, 4, 5, 6, 7, 13, 14, 15]);
 
1429
    TstFold('f2', 3, -1, 1, False, 1, [0, 1, 2, 3, 6, 7, 13, 14, 15]);
 
1430
    TestNodeAtPos('n1', 15, 4);
 
1431
    TestNodeAtPos('n2', 15, 8);
 
1432
 
 
1433
    SetCaretAndSel(1, 4, 1, 8);
 
1434
    SynEdit.CutToClipboard;
 
1435
 
 
1436
    TstFold('f2', 3, -1, 1, False, 1, [0, 1, 2, 3, 9, 10, 11]);
 
1437
    TestNodeAtPos('n3', 15, 4);
 
1438
 
 
1439
    PopBaseName;
 
1440
  {%endregion}
 
1441
 
 
1442
  {%region}
 
1443
    // 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
 
1444
    TstSetText('TestTextBug21473', TestTextBug21473);
 
1445
    TstFold('FooB', 25, -1, 1, False, 1, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,  28,29,30,31,32,33]);
 
1446
    TstFold('FooA', 21, -1, 1, False, 1, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,  24,25,  28,29,30,31,32,33]);
 
1447
    TstFold('Foo ', 19, -1, 1, False, 1, [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,  31,32,33]);
 
1448
 
 
1449
    TestNodeAtPos('n1', 1, 20);
 
1450
 
 
1451
    s := SynEdit.TextBetweenPoints[point(1,7), point(1,10)];
 
1452
    SynEdit.TextBetweenPoints[point(1,6), point(1,9)] := '';
 
1453
 
 
1454
    TestFoldedText('Cut', [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,   28,29,30]);
 
1455
    TestNodeAtPos('n1 Cut', 1, 17);
 
1456
 
 
1457
    SynEdit.TextBetweenPoints[point(1,7), point(1,7)] := s;
 
1458
 
 
1459
    TestFoldedText('Restore', [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,  31,32,33]);
 
1460
    TestNodeAtPos('n1 Restore', 1, 20);
 
1461
 
 
1462
    SynEdit.Undo;
 
1463
    //debugln('*********AFTER UNDO');  FoldedView.debug;
 
1464
 
 
1465
    TestFoldedText('Undone', [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,   28,29,30]);
 
1466
    TestNodeAtPos('n1 Undone', 1, 17);
 
1467
 
 
1468
    //SetCaretAndSel(1, 4, 1, 8);
 
1469
    //SynEdit.CutToClipboard;
 
1470
    PopBaseName;
 
1471
  {%endregion}
 
1472
 
 
1473
 
 
1474
 
 
1475
end;
 
1476
 
590
1477
procedure TTestFoldedView.TestFoldStateFromText;
591
 
  procedure TstSetText(AName: String; AText: TStringArray);
592
 
  begin
593
 
    PopBaseName;
594
 
    ReCreateEdit;
595
 
    SetLines(AText);
596
 
    PushBaseName(AName);
597
 
  end;
598
1478
 
599
1479
  procedure TstFoldState(AName, AFoldDesc: String; AExpectedLines: Array of Integer);
600
1480
  begin
667
1547
end;
668
1548
 
669
1549
procedure TTestFoldedView.TestFoldStateDesc;
 
1550
var
 
1551
  a1,a2, a3, a4: String;
670
1552
begin
671
1553
  (* - The values returned by GetFoldDescription can change in future versions
672
1554
       Therefore there is only a limited number of tests.
698
1580
  //TestCompareString('FoldDesc (txt / ext)', ' TA004 T12025',
699
1581
  //                  FoldedView.GetFoldDescription(0,1,-1,-1, True,  True)
700
1582
  //                 );
 
1583
 
 
1584
 
 
1585
 
 
1586
 
 
1587
  // No crash,if folded selection
 
1588
  ReCreateEdit;
 
1589
  SetLines(TestTextPlain);
 
1590
  SetCaretAndSel(1,5, 2,6);
 
1591
  FoldedView.FoldAtTextIndex(4, 0, 1, False, 0);
 
1592
  AssertEquals(FoldedView.Count, 8);
 
1593
 
 
1594
  FoldedView.GetFoldDescription(0, 0, -1, -1, True,  False);
 
1595
  FoldedView.GetFoldDescription(0, 0, -1, -1, False, False);
 
1596
  FoldedView.GetFoldDescription(0, 0, -1, -1, True,  True);
 
1597
  FoldedView.GetFoldDescription(0, 0, -1, -1, False, True);
 
1598
 
 
1599
  // compare fold desc with/without selection-fold
 
1600
  ReCreateEdit;
 
1601
  SetLines(TestTextPlain);
 
1602
  FoldedView.FoldAtTextIndex(0);
 
1603
  FoldedView.FoldAtTextIndex(7);
 
1604
  AssertEquals(FoldedView.Count, 6);
 
1605
 
 
1606
  a1 := FoldedView.GetFoldDescription(0, 0, -1, -1, True,  False);
 
1607
  a2 := FoldedView.GetFoldDescription(0, 0, -1, -1, False, False);
 
1608
  a3 := FoldedView.GetFoldDescription(0, 0, -1, -1, True,  True);
 
1609
  a4 := FoldedView.GetFoldDescription(0, 0, -1, -1, False, True);
 
1610
 
 
1611
  SetCaretAndSel(1,5, 2,6);
 
1612
  FoldedView.FoldAtTextIndex(4, 0, 1, False, 0);
 
1613
  AssertEquals(FoldedView.Count, 4);
 
1614
 
 
1615
  TestCompareString('1', a1, FoldedView.GetFoldDescription(0, 0, -1, -1, True,  False));
 
1616
  TestCompareString('2', a2, FoldedView.GetFoldDescription(0, 0, -1, -1, False, False));
 
1617
//  a3 := FoldedView.GetFoldDescription(0, 0, -1, -1, True,  True);
 
1618
//  a4 := FoldedView.GetFoldDescription(0, 0, -1, -1, False, True);
 
1619
 
 
1620
end;
 
1621
 
 
1622
procedure TTestFoldedView.TestFoldProvider;
 
1623
  procedure DoTestOpenCounts(AName: string; AType: Integer; AExp: Array of Integer);
 
1624
  var
 
1625
    i: Integer;
 
1626
  begin
 
1627
    AName := AName + ' (type=' + IntToStr(AType)+') ';
 
1628
    for i := low(AExp) to high(AExp) do
 
1629
      DebugLn([BaseTestName+AName+ ' line=' + IntToStr(i)+ ' exp=', AExp[i],'   Got=', FoldedView.FoldProvider.FoldOpenCount(i, AType)]);
 
1630
    for i := low(AExp) to high(AExp) do
 
1631
      AssertEquals(BaseTestName+AName+ ' line=' + IntToStr(i),
 
1632
                   AExp[i], FoldedView.FoldProvider.FoldOpenCount(i, AType));
 
1633
  end;
 
1634
 
 
1635
var
 
1636
  i: Integer;
 
1637
begin
 
1638
  // TSynEditFoldProvider.FoldOpenCount(ALineIdx: Integer; AType: Integer = 0): Integer;
 
1639
  PushBaseName('');
 
1640
 
 
1641
  TstSetText('TestText1', TestText);
 
1642
  EnableFolds([cfbtBeginEnd..cfbtNone]);
 
1643
  //                       p  P  B  ~  -
 
1644
  DoTestOpenCounts('', 0, [1, 1, 1, 0, 0]); // all (fold conf)
 
1645
  DoTestOpenCounts('', 1, [1, 1, 1, 0, 0]); // pas
 
1646
  //DoTestOpenCounts('', 4, [1, 1, 1, 0, 0]); // pas (incl unfolded)
 
1647
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0]); // %region
 
1648
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0]); // $if
 
1649
 
 
1650
  TstSetText('TestText1 (2)', TestText);
 
1651
  EnableFolds([cfbtTopBeginEnd]);
 
1652
  //                       p  P  B  ~  -
 
1653
  DoTestOpenCounts('', 0, [0, 0, 1, 0, 0]); // all (fold conf)
 
1654
  DoTestOpenCounts('', 1, [0, 0, 1, 0, 0]); // pas
 
1655
  //DoTestOpenCounts('', 4, [1, 1, 1, 0, 0]); // pas (incl unfolded)
 
1656
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0]); // %region
 
1657
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0]); // $if
 
1658
 
 
1659
  TstSetText('TestText1 (3)', TestText);
 
1660
  EnableFolds([cfbtProcedure, cfbtBeginEnd]);
 
1661
  //                       p  P  B  ~  -
 
1662
  DoTestOpenCounts('', 0, [0, 1, 0, 0, 0]); // all (fold conf)
 
1663
  DoTestOpenCounts('', 1, [0, 1, 0, 0, 0]); // pas
 
1664
  //DoTestOpenCounts('', 4, [1, 1, 1, 0, 0]); // pas (incl unfolded)
 
1665
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0]); // %region
 
1666
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0]); // $if
 
1667
 
 
1668
 
 
1669
 
 
1670
  TstSetText('TestText2', TestText2);
 
1671
  EnableFolds([cfbtBeginEnd..cfbtNone]);
 
1672
  //                                      if    else
 
1673
  //                       p  PP B  -  B  B  ~  -B ~  -  -  ~
 
1674
  DoTestOpenCounts('', 0, [1, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1675
  DoTestOpenCounts('', 1, [1, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1676
  //DoTestOpenCounts('', 4, [1, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1677
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
1678
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
1679
 
 
1680
  TstSetText('TestText2 (2)', TestText2);
 
1681
  EnableFolds([cfbtBeginEnd..cfbtNone]-[cfbtProgram, cfbtRegion]);
 
1682
  //                       p  PP B  -  B  B  ~  -B ~  -  -  ~
 
1683
  DoTestOpenCounts('', 0, [0, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1684
  DoTestOpenCounts('', 1, [0, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1685
  //DoTestOpenCounts('', 4, [1, 2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1686
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
1687
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
 
1688
 
 
1689
 
 
1690
 
 
1691
  TstSetText('TestText3', TestText3);
 
1692
  EnableFolds([cfbtBeginEnd..cfbtNone],  [cfbtSlashComment]);
 
1693
  //                                      if    else        // one-line-comment
 
1694
  //                       p  $  P  -  B  %B ~  --B~  -  -  /
 
1695
  DoTestOpenCounts('', 0, [1, 1, 1, 0, 1, 2, 0, 1, 0, 0, 0, 1]);
 
1696
  DoTestOpenCounts('', 1, [1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1697
  //DoTestOpenCounts('', 4, [1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1698
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]); // %region
 
1699
  DoTestOpenCounts('', 3, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // %if
 
1700
 
 
1701
  TstSetText('TestText3 (2)', TestText3);
 
1702
  EnableFolds([cfbtBeginEnd..cfbtNone]-[cfbtProgram, cfbtRegion],  [cfbtSlashComment]);
 
1703
  //                       p  $  P  -  B  %B ~  --B~  -  -  /
 
1704
  DoTestOpenCounts('', 0, [0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1705
  DoTestOpenCounts('', 1, [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1706
  //DoTestOpenCounts('', 4, [1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1707
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // %region
 
1708
  DoTestOpenCounts('', 3, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // %if
 
1709
 
 
1710
  TstSetText('TestText3 (3)', TestText3);
 
1711
  EnableFolds([cfbtBeginEnd..cfbtNone]-[cfbtProgram, cfbtIfDef], []);
 
1712
  //                       p  $  P  -  B  %B ~  --B~  -  -  /
 
1713
  DoTestOpenCounts('', 0, [0, 0, 1, 0, 1, 2, 0, 1, 0, 0, 0, 0]);
 
1714
  DoTestOpenCounts('', 1, [0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0]);
 
1715
  //DoTestOpenCounts('', 4, [1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1]);
 
1716
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]); // %region
 
1717
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // %if
 
1718
 
 
1719
 
 
1720
 
 
1721
  for i := 0 to 2 do begin // pos of $IFDEF does not matter
 
1722
    TstSetText('TestTextPasHl-'+IntToStr(i)+'', TestTextPasHl(i));
 
1723
    EnableFolds([cfbtBeginEnd..cfbtNone],  [cfbtSlashComment]);
 
1724
    //                             if       $E // one-line-comment
 
1725
    //                       p  P  $bb-  -  -  /
 
1726
    DoTestOpenCounts('', 0, [1, 1, 3, 0, 0, 0, 1]);
 
1727
    DoTestOpenCounts('', 1, [1, 1, 2, 0, 0, 0, 1]);
 
1728
    //DoTestOpenCounts('', 4, [1, 1, 2, 0, 0, 0, 1]);
 
1729
    DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0]); // %region
 
1730
    DoTestOpenCounts('', 3, [0, 0, 1, 0, 0, 0, 0]); // %if
 
1731
 
 
1732
    TstSetText('TestTextPasHl-'+IntToStr(i)+'', TestTextPasHl(i));
 
1733
    EnableFolds([cfbtBeginEnd..cfbtNone]-[cfbtBeginEnd],  [cfbtSlashComment]);
 
1734
    //                             if       $E // one-line-comment
 
1735
    //                       p  P  $bb-  -  -  /
 
1736
    DoTestOpenCounts('', 0, [1, 1, 2, 0, 0, 0, 1]);
 
1737
    DoTestOpenCounts('', 1, [1, 1, 1, 0, 0, 0, 1]);
 
1738
    //DoTestOpenCounts('', 4, [1, 1, 1, 0, 0, 0, 1]);
 
1739
    DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0]); // %region
 
1740
    DoTestOpenCounts('', 3, [0, 0, 1, 0, 0, 0, 0]); // %if
 
1741
 
 
1742
    TstSetText('TestTextPasHl-'+IntToStr(i)+'', TestTextPasHl(i));
 
1743
    EnableFolds([cfbtBeginEnd..cfbtNone]-[cfbtIfDef],  [cfbtSlashComment]);
 
1744
    //                             if       $E // one-line-comment
 
1745
    //                       p  P  $bb-  -  -  /
 
1746
    DoTestOpenCounts('', 0, [1, 1, 2, 0, 0, 0, 1]);
 
1747
    DoTestOpenCounts('', 1, [1, 1, 2, 0, 0, 0, 1]);
 
1748
    //DoTestOpenCounts('', 4, [1, 1, 2, 0, 0, 0, 1]);
 
1749
    DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0, 0]); // %region
 
1750
    DoTestOpenCounts('', 3, [0, 0, 0, 0, 0, 0, 0]); // %if
 
1751
  end;
 
1752
 
 
1753
 
 
1754
 
 
1755
  TstSetText('TestText4', TestText4);
 
1756
  EnableFolds([cfbtBeginEnd..cfbtNone],  [cfbtSlashComment]);
 
1757
  //                       pPBB  -  B  -  B  -
 
1758
  DoTestOpenCounts('', 0, [3, 1, 0, 1, 0, 1]);
 
1759
  DoTestOpenCounts('', 1, [3, 1, 0, 1, 0, 1]);
 
1760
  //DoTestOpenCounts('', 4, [3, 1, 0, 1, 0, 1]);
 
1761
  DoTestOpenCounts('', 2, [0, 0, 0, 0, 0, 0]);
 
1762
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 0, 0]);
 
1763
 
 
1764
 
 
1765
 
 
1766
  TstSetText('TestText8', TestText8);
 
1767
  EnableFolds([cfbtBeginEnd..cfbtNone],  [cfbtSlashComment]);
 
1768
  //                       p  P  B  %  $  B  %  $  B  ~  %  ~  B  ~  $  ~  -  ~  -
 
1769
  DoTestOpenCounts('', 0, [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0]);
 
1770
  DoTestOpenCounts('', 1, [1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]);
 
1771
//DoTestOpenCounts('', 4, [1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]);
 
1772
  DoTestOpenCounts('', 2, [0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]);
 
1773
  DoTestOpenCounts('', 3, [0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]);
 
1774
 
 
1775
end;
 
1776
 
 
1777
procedure TTestFoldedView.TestNestedFoldsList;
 
1778
  Procedure CheckNode(nd: TSynFoldNodeInfo; ALine: TLineIdx; AColumn: integer;
 
1779
    LogXStart, LogXEnd,  FoldLvlStart, FoldLvlEnd,  NestLvlStart, NestLvlEnd: Integer;
 
1780
    FoldType: integer;  FoldTypeCompatible: integer; FoldGroup: Integer;
 
1781
    FoldAction: TSynFoldActions);
 
1782
  begin
 
1783
    AssertEquals(Format('%s (%d/%d) LineIndex',    [BaseTestName, ALine, AColumn]), ALine, nd.LineIndex);
 
1784
    AssertEquals(Format('%s (%d/%d) NodeIndex',    [BaseTestName, ALine, AColumn]), AColumn, nd.NodeIndex);
 
1785
    if not(sfaInvalid in nd.FoldAction) then begin
 
1786
      AssertEquals(Format('%s (%d/%d) LogXStart',    [BaseTestName, ALine, AColumn]), LogXStart, nd.LogXStart);
 
1787
      AssertEquals(Format('%s (%d/%d) LogXEnd',      [BaseTestName, ALine, AColumn]), LogXEnd, nd.LogXEnd);
 
1788
      if FoldLvlStart >= 0 then
 
1789
      AssertEquals(Format('%s (%d/%d) FoldLvlStart', [BaseTestName, ALine, AColumn]), FoldLvlStart, nd.FoldLvlStart);
 
1790
      if FoldLvlEnd >= 0 then
 
1791
      AssertEquals(Format('%s (%d/%d) FoldLvlEnd',   [BaseTestName, ALine, AColumn]), FoldLvlEnd, nd.FoldLvlEnd);
 
1792
      AssertEquals(Format('%s (%d/%d) NestLvlStart', [BaseTestName, ALine, AColumn]), NestLvlStart, nd.NestLvlStart);
 
1793
      AssertEquals(Format('%s (%d/%d) NestLvlEnd',   [BaseTestName, ALine, AColumn]), NestLvlEnd, nd.NestLvlEnd);
 
1794
      AssertEquals(Format('%s (%d/%d) FoldType',     [BaseTestName, ALine, AColumn]), PtrUInt(FoldType), PtrUInt(nd.FoldType));
 
1795
      AssertEquals(Format('%s (%d/%d) FoldTypeCompatible', [BaseTestName, ALine, AColumn]), PtrUInt(FoldTypeCompatible), PtrUInt(nd.FoldTypeCompatible));
 
1796
      AssertEquals(Format('%s (%d/%d) FoldGroup:',   [BaseTestName, ALine, AColumn]), FoldGroup, nd.FoldGroup);
 
1797
    end;
 
1798
    AssertEquals(Format('%s (%d/%d) FoldAction',   [BaseTestName, ALine, AColumn]), FoldActionsToString(FoldAction), FoldActionsToString(nd.FoldAction));
 
1799
  end;
 
1800
var
 
1801
  TheList: TLazSynEditNestedFoldsList;
 
1802
begin
 
1803
// L= *(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?(\d+).*?A=(.*)
 
1804
// CheckNode(TheList.HLNode[2],  $1, $2,  $3, $4,  $5, $6,  $7, $8,  $9, $10, $11, $12);
 
1805
 
 
1806
  PushBaseName('');
 
1807
 
 
1808
  {%region TestText1}
 
1809
    TstSetText('TestText1', TestText);
 
1810
    TheList := FoldedView.FoldProvider.NestedFoldsList;
 
1811
    EnableFolds([cfbtBeginEnd..cfbtNone]);
 
1812
 
 
1813
    PushBaseName('All Enabled - group 0');
 
1814
    TheList.ResetFilter;
 
1815
    TheList.Line := 2;
 
1816
    TheList.FoldGroup := 0;
 
1817
    TheList.FoldFlags := [];
 
1818
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1819
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1820
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1821
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1822
 
 
1823
 
 
1824
    PopPushBaseName('All Enabled - group 1');
 
1825
    TheList.ResetFilter;
 
1826
    TheList.Line := 2;
 
1827
    TheList.FoldGroup := 1;
 
1828
    TheList.FoldFlags := [];
 
1829
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1830
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1831
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1832
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1833
 
 
1834
 
 
1835
    PopPushBaseName('All Enabled - group 2');
 
1836
    TheList.ResetFilter;
 
1837
    TheList.Line := 2;
 
1838
    TheList.FoldGroup := 2;
 
1839
    TheList.FoldFlags := [];
 
1840
    AssertEquals(BaseTestName + 'Cnt', 0, TheList.Count);
 
1841
 
 
1842
 
 
1843
    PopPushBaseName('All Enabled - group 0 - NoCurrentLine');
 
1844
    TheList.ResetFilter;
 
1845
    TheList.Line := 2;
 
1846
    TheList.FoldGroup := 0;
 
1847
    TheList.FoldFlags := [];
 
1848
    TheList.IncludeOpeningOnLine := False;
 
1849
    AssertEquals(BaseTestName + 'Cnt', 2, TheList.Count);
 
1850
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1851
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1852
 
 
1853
 
 
1854
    PopPushBaseName('All Enabled - group 0 - NoCurrentLine - line 3');
 
1855
    TheList.ResetFilter;
 
1856
    TheList.Line := 3;
 
1857
    TheList.FoldGroup := 0;
 
1858
    TheList.FoldFlags := [];
 
1859
    TheList.IncludeOpeningOnLine := False;
 
1860
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1861
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1862
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1863
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1864
 
 
1865
 
 
1866
    EnableFolds([cfbtTopBeginEnd]);
 
1867
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0');
 
1868
    TheList.ResetFilter;
 
1869
    TheList.Line := 2;
 
1870
    TheList.FoldGroup := 0;
 
1871
    TheList.FoldFlags := [];
 
1872
    AssertEquals(BaseTestName + 'Cnt', 1, TheList.Count);
 
1873
    CheckNode(TheList.HLNode[0],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1874
 
 
1875
 
 
1876
    EnableFolds([cfbtTopBeginEnd]);
 
1877
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 1');
 
1878
    TheList.ResetFilter;
 
1879
    TheList.Line := 2;
 
1880
    TheList.FoldGroup := 1;
 
1881
    TheList.FoldFlags := [];
 
1882
    AssertEquals(BaseTestName + 'Cnt', 1, TheList.Count);
 
1883
    CheckNode(TheList.HLNode[0],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1884
 
 
1885
 
 
1886
    EnableFolds([cfbtTopBeginEnd]);
 
1887
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0 - NoCurrentLine');
 
1888
    TheList.ResetFilter;
 
1889
    TheList.Line := 2;
 
1890
    TheList.FoldGroup := 0;
 
1891
    TheList.FoldFlags := [];
 
1892
    TheList.IncludeOpeningOnLine := False;
 
1893
    AssertEquals(BaseTestName + 'Cnt', 0, TheList.Count);
 
1894
 
 
1895
 
 
1896
    EnableFolds([cfbtTopBeginEnd]);
 
1897
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0 - NoCurrentLine line 3');
 
1898
    TheList.ResetFilter;
 
1899
    TheList.Line := 3;
 
1900
    TheList.FoldGroup := 0;
 
1901
    TheList.FoldFlags := [];
 
1902
    TheList.IncludeOpeningOnLine := False;
 
1903
    AssertEquals(BaseTestName + 'Cnt', 1, TheList.Count);
 
1904
    CheckNode(TheList.HLNode[0],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1905
 
 
1906
 
 
1907
 
 
1908
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0 - sfbIncludeDisabled');
 
1909
    TheList.ResetFilter;
 
1910
    TheList.Line := 2;
 
1911
    TheList.FoldGroup := 0;
 
1912
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1913
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1914
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1915
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9, -1,-1,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup]);
 
1916
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7, -1,-1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup]);
 
1917
 
 
1918
 
 
1919
    EnableFolds([cfbtTopBeginEnd]);
 
1920
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 1 - sfbIncludeDisabled');
 
1921
    TheList.ResetFilter;
 
1922
    TheList.Line := 2;
 
1923
    TheList.FoldGroup := 1;
 
1924
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1925
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1926
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1927
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9, -1,-1,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup]);
 
1928
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7, -1,-1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup]);
 
1929
 
 
1930
 
 
1931
    EnableFolds([cfbtTopBeginEnd]);
 
1932
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 2 - sfbIncludeDisabled');
 
1933
    TheList.ResetFilter;
 
1934
    TheList.Line := 2;
 
1935
    TheList.FoldGroup := 2;
 
1936
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1937
    AssertEquals(BaseTestName + 'Cnt', 0, TheList.Count);
 
1938
 
 
1939
 
 
1940
    EnableFolds([cfbtTopBeginEnd]);
 
1941
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0 - NoCurrentLine - sfbIncludeDisabled');
 
1942
    TheList.ResetFilter;
 
1943
    TheList.Line := 2;
 
1944
    TheList.FoldGroup := 0;
 
1945
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1946
    TheList.IncludeOpeningOnLine := False;
 
1947
    AssertEquals(BaseTestName + 'Cnt', 2, TheList.Count);
 
1948
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9, -1,-1,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup]);
 
1949
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7, -1,-1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup]);
 
1950
 
 
1951
 
 
1952
    EnableFolds([cfbtTopBeginEnd]);
 
1953
    PopPushBaseName('cfbtTopBeginEnd Enabled - group 0 - NoCurrentLine line 3 - sfbIncludeDisabled');
 
1954
    TheList.ResetFilter;
 
1955
    TheList.Line := 3;
 
1956
    TheList.FoldGroup := 0;
 
1957
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1958
    TheList.IncludeOpeningOnLine := False;
 
1959
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1960
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  0, 1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1961
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9, -1,-1,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup]);
 
1962
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7, -1,-1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup]);
 
1963
 
 
1964
 
 
1965
    // TODO line, currently ignores the opening "begin" on current line
 
1966
    EnableFolds([]);
 
1967
    PopPushBaseName('None Enabled - group 0 - sfbIncludeDisabled - line 3');
 
1968
    TheList.ResetFilter;
 
1969
    TheList.Line := 3;
 
1970
    TheList.FoldGroup := 0;
 
1971
    TheList.FoldFlags := [sfbIncludeDisabled];
 
1972
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1973
    CheckNode(TheList.HLNode[2],  2, 0,  0, 5, -1,-1,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup]);
 
1974
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9, -1,-1,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup]);
 
1975
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7, -1,-1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup]);
 
1976
 
 
1977
 
 
1978
    PopBaseName;
 
1979
  {%endregion TestText1}
 
1980
 
 
1981
 
 
1982
  {%region TestText2}
 
1983
    TstSetText('TestText2', TestText2);
 
1984
    TheList := FoldedView.FoldProvider.NestedFoldsList;
 
1985
    EnableFolds([cfbtBeginEnd..cfbtNone]);
 
1986
 
 
1987
    PushBaseName('All Enabled - group 0 - line 1');
 
1988
    TheList.ResetFilter;
 
1989
    TheList.Line := 1;
 
1990
    TheList.FoldGroup := 0;
 
1991
    TheList.FoldFlags := [];
 
1992
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
1993
    CheckNode(TheList.HLNode[2],  1, 1,  13, 22,  2, 3,  2, 3,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1994
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1995
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
1996
 
 
1997
 
 
1998
    PopPushBaseName('All Enabled - group 0 - line 1 - no current');
 
1999
    TheList.ResetFilter;
 
2000
    TheList.Line := 1;
 
2001
    TheList.FoldGroup := 0;
 
2002
    TheList.FoldFlags := [];
 
2003
    TheList.IncludeOpeningOnLine := False;
 
2004
    AssertEquals(BaseTestName + 'Cnt', 1, TheList.Count);
 
2005
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2006
 
 
2007
 
 
2008
    PopPushBaseName('All Enabled - group 0 - line 3');
 
2009
    TheList.ResetFilter;
 
2010
    TheList.Line := 3;
 
2011
    TheList.FoldGroup := 0;
 
2012
    TheList.FoldFlags := [];
 
2013
    AssertEquals(BaseTestName + 'Cnt', 4, TheList.Count);
 
2014
    CheckNode(TheList.HLNode[3],  2, 0,  2, 7,  3, 4,  3, 4,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2015
    CheckNode(TheList.HLNode[2],  1, 1,  13, 22,  2, 3,  2, 3,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2016
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2017
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2018
 
 
2019
 
 
2020
    PopPushBaseName('All Enabled - group 0 - line 4');
 
2021
    TheList.ResetFilter;
 
2022
    TheList.Line := 4;
 
2023
    TheList.FoldGroup := 0;
 
2024
    TheList.FoldFlags := [];
 
2025
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
2026
    CheckNode(TheList.HLNode[2],  4, 0,  23, 28,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2027
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2028
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2029
 
 
2030
 
 
2031
    PopPushBaseName('All Enabled - group 0 - line 4 - NO IncludeOpeningOnLine');
 
2032
    TheList.ResetFilter;
 
2033
    TheList.Line := 4;
 
2034
    TheList.FoldGroup := 0;
 
2035
    TheList.FoldFlags := [];
 
2036
    TheList.IncludeOpeningOnLine := False;
 
2037
    AssertEquals(BaseTestName + 'Cnt', 2, TheList.Count);
 
2038
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2039
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2040
 
 
2041
 
 
2042
    PopPushBaseName('All Enabled - group 0 - line 5');
 
2043
    TheList.ResetFilter;
 
2044
    TheList.Line := 5;
 
2045
    TheList.FoldGroup := 0;
 
2046
    TheList.FoldFlags := [];
 
2047
    AssertEquals(BaseTestName + 'Cnt', 4, TheList.Count);
 
2048
    CheckNode(TheList.HLNode[3],  5, 0,  12, 17,  3, 4,  3, 4,  0, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2049
    CheckNode(TheList.HLNode[2],  4, 0,  23, 28,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2050
    CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2051
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2052
 
 
2053
    PopBaseName;
 
2054
  {%endregion TestText2}
 
2055
 
 
2056
 
 
2057
  {%region TestText3}
 
2058
 
 
2059
    TstSetText('TestText3', TestText3);
 
2060
    TheList := FoldedView.FoldProvider.NestedFoldsList;
 
2061
    EnableFolds([cfbtBeginEnd..cfbtNone]);
 
2062
 
 
2063
    PushBaseName('All Enabled - group 0 - line 3');
 
2064
    TheList.ResetFilter;
 
2065
    TheList.Line := 3;
 
2066
    TheList.FoldGroup := 0;
 
2067
    TheList.FoldFlags := [];
 
2068
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
2069
    CheckNode(TheList.HLNode[2],  2, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2070
    CheckNode(TheList.HLNode[1],  1, 0,  2, 7,  0, 1,  0, 1,  18, 18, 3, [sfaOpen,sfaFold,sfaFoldFold]);
 
2071
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2072
 
 
2073
 
 
2074
    PushBaseName('All Enabled - group 1 - line 3');
 
2075
    TheList.ResetFilter;
 
2076
    TheList.Line := 3;
 
2077
    TheList.FoldGroup := 1;
 
2078
    TheList.FoldFlags := [];
 
2079
    AssertEquals(BaseTestName + 'Cnt', 2, TheList.Count);
 
2080
    CheckNode(TheList.HLNode[1],  2, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2081
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2082
 
 
2083
 
 
2084
    PushBaseName('All Enabled - group 3 - line 3');
 
2085
    TheList.ResetFilter;
 
2086
    TheList.Line := 3;
 
2087
    TheList.FoldGroup := 3;
 
2088
    TheList.FoldFlags := [];
 
2089
    AssertEquals(BaseTestName + 'Cnt', 1, TheList.Count);
 
2090
    CheckNode(TheList.HLNode[0],  1, 0,  2, 7,  0, 1,  0, 1,  18, 18, 3, [sfaOpen,sfaFold,sfaFoldFold]);
 
2091
 
 
2092
 
 
2093
    PopPushBaseName('All Enabled - group 0 - line 3');
 
2094
    TheList.ResetFilter;
 
2095
    TheList.Line := 4;
 
2096
    TheList.FoldGroup := 0;
 
2097
    TheList.FoldFlags := [];
 
2098
    AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
2099
    CheckNode(TheList.HLNode[2],  4, 0,  0, 5,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2100
    CheckNode(TheList.HLNode[1],  2, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2101
    CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2102
 
 
2103
    PopBaseName;
 
2104
  {%endregion TestText2}
 
2105
 
 
2106
 
 
2107
  TstSetText('TestText9', TestText9);
 
2108
  TheList := FoldedView.FoldProvider.NestedFoldsList;
 
2109
  EnableFolds([cfbtBeginEnd..cfbtNone]);
 
2110
 
 
2111
  PushBaseName('All Enabled - group 0 - line 3');
 
2112
  TheList.ResetFilter;
 
2113
  TheList.Line := 5;
 
2114
  TheList.FoldGroup := 0;
 
2115
  TheList.FoldFlags := [];
 
2116
  AssertEquals(BaseTestName + 'Cnt', 3, TheList.Count);
 
2117
  CheckNode(TheList.HLNode[2],  2, 0,  0, 5,  2, 3,  2, 3,  1, 0, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2118
  CheckNode(TheList.HLNode[1],  1, 0,  0, 9,  1, 2,  1, 2,  3, 3, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2119
  CheckNode(TheList.HLNode[0],  0, 0,  0, 7,  0, 1,  0, 1,  10, 10, 1, [sfaOpen,sfaMarkup,sfaFold,sfaFoldFold]);
 
2120
  PopBaseName;
 
2121
 
701
2122
end;
702
2123
 
703
2124
initialization