From a5564ccfa1d862292f5704bf8360d958b89e8bd1 Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 31 Jul 2017 02:56:44 +0000 Subject: [PATCH] SynEdit: test for fix crash in fold structure code TLazSynEditNestedFoldsList git-svn-id: trunk@55614 - --- .gitattributes | 1 + components/synedit/test/SynTest.lpr | 4 +- .../synedit/test/testnestedfoldslist.pas | 142 ++++++++++++++++++ 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 components/synedit/test/testnestedfoldslist.pas diff --git a/.gitattributes b/.gitattributes index 10f72cdc8f..b91b8fb835 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4252,6 +4252,7 @@ components/synedit/test/testmarkupifdef.pas svneol=native#text/pascal components/synedit/test/testmarkupwordgroup.pas svneol=native#text/pascal components/synedit/test/testmulticaret.pas svneol=native#text/plain components/synedit/test/testnavigation.pas svneol=native#text/pascal +components/synedit/test/testnestedfoldslist.pas svneol=native#text/pascal components/synedit/test/testpaintcolormerging.pas svneol=native#text/pascal components/synedit/test/testsearch.pas svneol=native#text/pascal components/synedit/test/testsynbeautifier.pas svneol=native#text/pascal diff --git a/components/synedit/test/SynTest.lpr b/components/synedit/test/SynTest.lpr index 32ed314101..0640a4914e 100644 --- a/components/synedit/test/SynTest.lpr +++ b/components/synedit/test/SynTest.lpr @@ -8,8 +8,8 @@ uses TestSynBeautifier, TestTrimSpace, TestSyncroEdit, TestSynTextArea, TestHighlightPas, TestHighlightXml, TestHighlightMulti, TestMarkupwordGroup, TestMarkupHighAll, TestFoldedView, TestSynSharedEdits, TestHighlighterLfm, - TestHighlightFoldBase, TestMarkupIfDef, testPaintColorMerging, -TestMarkupFoldColoring; + TestNestedFoldsList, TestMarkupIfDef, testPaintColorMerging, + TestMarkupFoldColoring; {$IFDEF WINDOWS}{ $R SynTest.rc}{$ENDIF} diff --git a/components/synedit/test/testnestedfoldslist.pas b/components/synedit/test/testnestedfoldslist.pas new file mode 100644 index 0000000000..cc1312990c --- /dev/null +++ b/components/synedit/test/testnestedfoldslist.pas @@ -0,0 +1,142 @@ +unit TestNestedFoldsList; + +{$mode objfpc}{$H+} + +interface + +uses + SysUtils, TestBase, testregistry, SynEdit, SynHighlighterPas, + SynEditHighlighterFoldBase, LazLoggerBase, TestHighlightPas; + +type + + { TTestNestedFoldsList } + + TTestNestedFoldsList = class(TTestBaseHighlighterPas) + private + FNestList: TLazSynEditNestedFoldsList; + protected + procedure TearDown; override; + procedure ReCreateEdit; reintroduce; + procedure ReCreateList; + function TestText1: TStringArray; + published + procedure Test1; + end; + + +implementation + +{ TTestNestedFoldsList } + +procedure TTestNestedFoldsList.TearDown; +begin + FreeAndNil(FNestList); + inherited TearDown; +end; + +procedure TTestNestedFoldsList.ReCreateEdit; +begin + FreeAndNil(FNestList); + inherited ReCreateEdit; + ReCreateList; +end; + +procedure TTestNestedFoldsList.ReCreateList; +begin + FreeAndNil(FNestList); + FNestList := TLazSynEditNestedFoldsList.Create(SynEdit.TextBuffer, PasHighLighter); + FNestList.ResetFilter; + FNestList.FoldGroup := 0; + FNestList.FoldFlags := [sfbIncludeDisabled]; + FNestList.IncludeOpeningOnLine := True; +end; + +function TTestNestedFoldsList.TestText1: TStringArray; +begin + SetLength(Result, 26); + Result[0] := 'program Foo;'; + Result[1] := 'begin'; + Result[2] := ' while FTheDebugger.DebugProcessRunning and not(FTheDebugger.State in [dsError, dsDestroying]) do'; + Result[3] := ' begin'; + Result[4] := ''; + Result[5] := ' {$IFDEF DBG_ASYNC_WAIT}'; + Result[6] := ' if GotPrompt > 0 then begin'; + Result[7] := ' {$ENDIF}'; + Result[8] := ''; + Result[9] := ' if (S = ''(gdb) '') or'; + Result[10] := ' ( (S = '') and FDidKillNow )'; + Result[11] := ' then'; + Result[12] := ' {$IFDEF DBG_ASYNC_WAIT}'; + Result[13] := ' begin'; + Result[14] := ' if (not FGotStopped) and (not FDidKillNow) and (GotPrompt = 0) then'; + Result[15] := ' GotPrompt := 1'; + Result[16] := ' else'; + Result[17] := ' break;'; + Result[18] := ' end;'; + Result[19] := ' {$ELSE}'; + Result[20] := ' Break;'; + Result[21] := ' {$ENDIF}'; + Result[22] := ''; + Result[23] := ' end;'; + Result[24] := ' end;'; + Result[25] := ''; +end; + +procedure TTestNestedFoldsList.Test1; +var + start, start2, nth, grp, i, j: Integer; +begin + // this test currently only checks that no ASSERT is triggered + +// PushBaseName(''); + for start := 0 to 24 do begin + for start2 := 0 to 3 do begin + for nth := 1 to 4 do begin + for grp := 0 to 1 do begin + ReCreateEdit; + //PopPushBaseName('Text 1 -- [cfbtBeginEnd..cfbtNone], [], 0'); + SetLines(TestText1); + EnableFolds([cfbtBeginEnd..cfbtNone], []); + FNestList.FoldGroup := grp; + + for i := start to 25 do begin + FNestList.Line := i; + if i mod nth = 0 then + for j := start2*2 to FNestList.Count - 1 do begin + FNestList.HLNode[j]; + FNestList.NodeEndLine[j] + end; + end; + + ReCreateEdit; + //PopPushBaseName('Text 1 -- [cfbtBeginEnd..cfbtNone], [], 0'); + SetLines(TestText1); + EnableFolds([cfbtBeginEnd..cfbtNone], []); + FNestList.FoldGroup := grp; + FNestList.FoldFlags := []; + + for i := start to 25 do begin + FNestList.Line := i; + if i mod nth = 0 then + for j := start2*2 to FNestList.Count - 1 do begin + FNestList.HLNode[j]; + FNestList.NodeEndLine[j] + end; + end; + + + end; + end; + end; + end; + +end; + + +initialization + + RegisterTest(TTestNestedFoldsList); + +end. +