mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 04:16:06 +02:00
SynEdit: FoldHighlighter (Html, XML): fix invalid fold node on last line. Issue #0023543
git-svn-id: trunk@39686 -
This commit is contained in:
parent
a7f651f86e
commit
a0d96129be
@ -805,7 +805,7 @@ var
|
||||
r: Pointer;
|
||||
begin
|
||||
Assert(CurrentRanges <> nil, 'TSynCustomFoldHighlighter.FoldBlockEndLevel requires CurrentRanges');
|
||||
if (ALineIndex < 0) or (ALineIndex >= CurrentLines.Count) then
|
||||
if (ALineIndex < 0) or (ALineIndex >= CurrentLines.Count - 1) then
|
||||
exit(0);
|
||||
r := CurrentRanges[ALineIndex];
|
||||
if (r <> nil) and (r <> NullRange) then
|
||||
@ -820,7 +820,7 @@ var
|
||||
r: Pointer;
|
||||
begin
|
||||
Assert(CurrentRanges <> nil, 'TSynCustomFoldHighlighter.FoldBlockMinLevelrequires CurrentRanges');
|
||||
if (ALineIndex < 0) or (ALineIndex >= CurrentLines.Count) then
|
||||
if (ALineIndex < 0) or (ALineIndex >= CurrentLines.Count - 1) then
|
||||
exit(0);
|
||||
r := CurrentRanges[ALineIndex];
|
||||
if (r <> nil) and (r <> NullRange) then
|
||||
|
@ -12,6 +12,15 @@ type
|
||||
|
||||
// used by Fold / MarkupWord
|
||||
|
||||
TTestExpValuesForLine = record
|
||||
Line: integer;
|
||||
Exp: Array of integer;
|
||||
end;
|
||||
|
||||
function ExpVLine(ALine: Integer; AExp: Array of integer): TTestExpValuesForLine;
|
||||
|
||||
type
|
||||
|
||||
{ TTestBaseHighlighterPas }
|
||||
|
||||
{ TTestBaseHighlighterFoldBase }
|
||||
@ -25,6 +34,9 @@ type
|
||||
procedure ReCreateEdit; reintroduce;
|
||||
|
||||
procedure CheckFoldOpenCounts(Name: String; Expected: Array of Integer);
|
||||
procedure CheckFoldLengths(Name: String; Expected: Array of TTestExpValuesForLine);
|
||||
procedure CheckFoldEndLines(Name: String; Expected: Array of TTestExpValuesForLine);
|
||||
|
||||
procedure CheckFoldInfoCounts(Name: String; Filter: TSynFoldActions; Expected: Array of Integer);
|
||||
procedure CheckFoldInfoCounts(Name: String; Filter: TSynFoldActions; Group: Integer; Expected: Array of Integer);
|
||||
|
||||
@ -34,6 +46,16 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
function ExpVLine(ALine: Integer; AExp: array of integer): TTestExpValuesForLine;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result.Line := ALine;
|
||||
SetLength(Result.Exp, Length(AExp));
|
||||
for i := low(AExp) to high(AExp) do
|
||||
Result.Exp[i] := AExp[i];
|
||||
end;
|
||||
|
||||
{ TTestBaseHighlighterFoldBase }
|
||||
|
||||
procedure TTestBaseHighlighterFoldBase.SetUp;
|
||||
@ -72,6 +94,28 @@ begin
|
||||
AssertEquals(Name + 'OpenCount Line='+IntToStr(i), Expected[i], FTheHighLighter.FoldBlockOpeningCount(i));
|
||||
end;
|
||||
|
||||
procedure TTestBaseHighlighterFoldBase.CheckFoldLengths(Name: String;
|
||||
Expected: array of TTestExpValuesForLine);
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
for i := 0 to high(Expected) do
|
||||
for j := 0 to high(Expected[i].Exp) do
|
||||
AssertEquals(Name + 'FoldLength Line='+IntToStr(Expected[i].Line) + ' idx='+IntToStr(j),
|
||||
Expected[i].Exp[j], FTheHighLighter.FoldLineLength(Expected[i].Line, j));
|
||||
end;
|
||||
|
||||
procedure TTestBaseHighlighterFoldBase.CheckFoldEndLines(Name: String;
|
||||
Expected: array of TTestExpValuesForLine);
|
||||
var
|
||||
i, j: Integer;
|
||||
begin
|
||||
for i := 0 to high(Expected) do
|
||||
for j := 0 to high(Expected[i].Exp) do
|
||||
AssertEquals(Name + 'FoldEnd Line='+IntToStr(Expected[i].Line) + ' idx='+IntToStr(j),
|
||||
Expected[i].Exp[j], FTheHighLighter.FoldEndLine(Expected[i].Line, j));
|
||||
end;
|
||||
|
||||
procedure TTestBaseHighlighterFoldBase.CheckFoldInfoCounts(Name: String;
|
||||
Filter: TSynFoldActions; Expected: array of Integer);
|
||||
begin
|
||||
|
@ -5,19 +5,27 @@ unit TestHighlightXml;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, TestBase, SynHighlighterXML;
|
||||
Classes, SysUtils, fpcunit, testregistry, TestBase, TestHighlightFoldBase, SynHighlighterXML,
|
||||
SynEditHighlighterFoldBase;
|
||||
|
||||
type
|
||||
|
||||
{ THighlightXml }
|
||||
|
||||
THighlightXml = class(TTestBase)
|
||||
THighlightXml = class(TTestBaseHighlighterFoldBase)
|
||||
protected
|
||||
function CreateTheHighLighter: TSynCustomFoldHighlighter; override;
|
||||
published
|
||||
procedure TestXml;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
function THighlightXml.CreateTheHighLighter: TSynCustomFoldHighlighter;
|
||||
begin
|
||||
Result := TSynXMLSyn.Create(nil);
|
||||
end;
|
||||
|
||||
procedure THighlightXml.TestXml;
|
||||
function TestText: TStringArray;
|
||||
begin
|
||||
@ -31,12 +39,35 @@ var
|
||||
hl: TSynXMLSyn;
|
||||
begin
|
||||
ReCreateEdit;
|
||||
hl := TSynXMLSyn.Create(nil);
|
||||
SynEdit.Highlighter := hl;
|
||||
SetLines(TestText);
|
||||
|
||||
SynEdit.Highlighter := nil;
|
||||
hl.free;
|
||||
CheckFoldOpenCounts('simple', [1,0,0]);
|
||||
CheckFoldLengths ('simple', [ExpVLine(0,[2])]);
|
||||
CheckFoldEndLines ('simple', [ExpVLine(0,[2])]);
|
||||
|
||||
SetLines(['<a>', '<b><c>', '</c>', '', '</b></a>', '']);
|
||||
CheckFoldOpenCounts('nested', [1,2,0,0,0]);
|
||||
CheckFoldLengths ('nested', [ExpVLine(0, [4]), ExpVLine(1, [3,1]) ]);
|
||||
CheckFoldEndLines ('nested', [ExpVLine(0, [4]), ExpVLine(1, [4,2]) ]);
|
||||
|
||||
// c is not closed, and ended by b
|
||||
SetLines(['<a>', '<b><c>', '', '', '</b></a>', '']);
|
||||
CheckFoldOpenCounts('bad nested', [1,2,0,0,0]);
|
||||
CheckFoldLengths ('bad nested', [ExpVLine(0, [4]), ExpVLine(1, [3,3]) ]);
|
||||
CheckFoldEndLines ('bad nested', [ExpVLine(0, [4]), ExpVLine(1, [4,4]) ]);
|
||||
|
||||
// a is not closed
|
||||
SetLines(['<a>', '<b><c>', '</c>', '', '</b>', '']);
|
||||
CheckFoldOpenCounts('open end', [1,2,0,0,0]);
|
||||
CheckFoldLengths ('open end', [ExpVLine(0, [4]), ExpVLine(1, [3,1]) ]);
|
||||
CheckFoldEndLines ('open end', [ExpVLine(0, [4]), ExpVLine(1, [4,2]) ]);
|
||||
|
||||
// a is not closed
|
||||
SetLines(['<a>', '']);
|
||||
CheckFoldOpenCounts('open end (one line)', [0]);
|
||||
//CheckFoldLengths ('open end (one line)', [ExpVLine(0, [0]) ]);
|
||||
//CheckFoldEndLines ('open end (one line)', [ExpVLine(0, [0]) ]);
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user