Skip to content

Instantly share code, notes, and snippets.

@dimmaq
Created February 12, 2020 13:31
Show Gist options
  • Save dimmaq/146d434d9c2c525802bdb3a689e6eed1 to your computer and use it in GitHub Desktop.
Save dimmaq/146d434d9c2c525802bdb3a689e6eed1 to your computer and use it in GitHub Desktop.
function TestWrapText(const AText: AnsiString): Boolean;
var t1, t2: AnsiString;
begin
t1 := AText;
t2 := WrapMultiLineText(AText, #13#10, ['>', #1..#32], RandomRange(1, 100));
G_Compact(t1);
G_Compact(t2);
Result := t1 = t2
end;
function StringFromChars(const AChars: TCharSet): AnsiString;
var k: Integer;
ch: AnsiChar;
begin
SetLength(Result, 256);
k := 0;
for ch in AChars do
begin
Result[k] := ch;
Inc(k);
end;
SetLength(Result, k);
end;
function GetRandomText: AnsiString;
var
j: Integer;
chars: AnsiString;
begin
chars := StringFromChars(['a'..'z', '0'..'9', '>', #32, #13]);
Result := RandomString(chars, 100, 100000);
for j := 1 to Length(Result) do
begin
if Result[j] = #13 then
if j < Length(Result) then
Result[j+1] := #10
// else
// Result[j] = #32
end;
end;
function TestWrapTextRandom(var AText: AnsiString): Boolean;
begin
AText := GetRandomText();
Result := TestWrapText(AText);
end;
function TestWrapTextRandomCount(ACount: Integer; var AErrorText: AnsiString): Boolean;
begin
Result := False;
while ACount > 0 do
begin
Result := TestWrapTextRandom(AErrorText);
if not Result then
Exit;
end;
end;
function TextWrapTextRandom1000(var AErrorText: AnsiString): Boolean;
begin
Result := TestWrapTextRandomCount(1000, AErrorText)
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment