Skip to content
Permalink
Browse files

slightly refactored TSynTestCase.AddRandomTextParagraph

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed May 8, 2019
1 parent 807efb5 commit d1ebedacc7b1e0b3cf7dcbe804e0173972a74e01
Showing with 20 additions and 19 deletions.
  1. +19 −18 SynTests.pas
  2. +1 −1 SynopseCommit.inc
@@ -254,7 +254,7 @@ TSynTestCase = class(TSynTest)
/// create a temporary string, containing some fake text, with paragraphs
class function RandomTextParagraph(WordCount: Integer;
LastPunctuation: AnsiChar='.'; const RandomInclude: RawUTF8=''): RawUTF8;
/// add containing some fake text, with paragraphs
/// add containing some "bla bli blo blu" fake text, with paragraphs
class procedure AddRandomTextParagraph(WR: TTextWriter; WordCount: Integer;
LastPunctuation: AnsiChar='.'; const RandomInclude: RawUTF8=''; NoLineFeed: boolean=false);
/// this method is triggered internaly - e.g. by Check() - when a test failed
@@ -738,7 +738,7 @@ class function TSynTestCase.RandomTextParagraph(WordCount: Integer;
class procedure TSynTestCase.AddRandomTextParagraph(WR: TTextWriter; WordCount: Integer;
LastPunctuation: AnsiChar; const RandomInclude: RawUTF8; NoLineFeed: boolean);
type TKind = (space, comma, dot, question, paragraph);
const bla: array[0..4] of string[3]=('bla','ble','bli','blo','blu');
const bla: array[0..7] of string[3]=('bla','ble','bli','blo','blu','bla','bli','blo');
endKind = [dot,paragraph,question];
var n: integer;
s: string[3];
@@ -747,31 +747,33 @@ class procedure TSynTestCase.AddRandomTextParagraph(WR: TTextWriter; WordCount:
begin
last := paragraph;
while WordCount>0 do begin
rnd := Random32gsl;
for n := 0 to rnd mod 4 do begin
rnd := Random32gsl; // get 32-bit of randomness
for n := 0 to rnd and 3 do begin // consume up to 20-bit from rnd
rnd := rnd shr 2;
s := bla[rnd and 7];
rnd := rnd shr 3;
s := bla[rnd mod 5];
if last in endKind then
s[1] := upcase(s[1]);
if last in endKind then begin
last := space;
s[1] := NormToUpper[s[1]];
end;
WR.AddShort(s);
WR.Add(' ');
dec(WordCount);
last := space;
end;
WR.CancelLastChar(' ');
case (rnd shr 3) mod 100 of
0..2: begin
case rnd and 127 of // consume 7-bit
0..4: begin
if RandomInclude<>'' then begin
WR.Add(' ');
WR.AddString(RandomInclude);
end;
last := space;
end;
3..40: last := space;
41..70: last := comma;
71..85: last := dot;
86..90: last := question;
91..99: if NoLineFeed then last := dot else last := paragraph;
5..65: last := space;
66..90: last := comma;
91..105: last := dot;
106..115: last := question;
116..127: if NoLineFeed then last := dot else last := paragraph;
end;
case last of
space: WR.Add(' ');
@@ -781,10 +783,9 @@ class procedure TSynTestCase.AddRandomTextParagraph(WR: TTextWriter; WordCount:
paragraph: WR.AddShort('.'#13#10);
end;
end;
if not (last in endKind) then begin
if not(last in endKind) and (LastPunctuation<>' ') then begin
WR.AddShort('bla');
if LastPunctuation<>' ' then
WR.Add(LastPunctuation);
WR.Add(LastPunctuation);
end;
end;

@@ -1 +1 @@
'1.18.5210'
'1.18.5211'

0 comments on commit d1ebeda

Please sign in to comment.
You can’t perform that action at this time.