* test for new split option

git-svn-id: trunk@47069 -
This commit is contained in:
michael 2020-10-09 11:33:57 +00:00
parent 5283049a62
commit be371d901c
2 changed files with 94 additions and 0 deletions

1
.gitattributes vendored
View File

@ -16130,6 +16130,7 @@ tests/test/units/sysutils/tbytesof.pp svneol=native#text/pascal
tests/test/units/sysutils/tdirex.pp svneol=native#text/plain
tests/test/units/sysutils/tencodingerrors.pp svneol=native#text/pascal
tests/test/units/sysutils/tencodingtest.pp svneol=native#text/pascal
tests/test/units/sysutils/testspo.pp svneol=native#text/plain
tests/test/units/sysutils/texec1.pp svneol=native#text/plain
tests/test/units/sysutils/texec2.pp svneol=native#text/plain
tests/test/units/sysutils/texpfncase.pp svneol=native#text/plain

View File

@ -0,0 +1,93 @@
program testspo;
{$APPTYPE CONSOLE}
uses
SysUtils;
{$IFNDEF FPC}
type
TStringArray = TArray<string>;
{$ENDIF}
procedure Test(TestString: String; const Expected: TStringArray; Options: TStringSplitOptions;
UseChar: Boolean);
var
sa: TStringArray;
i: Integer;
begin
Write('Testing "', TestString, '"...');
{$IFDEF FPC}
if UseChar then
sa := TestString.Split(',', Options)
else
{$ENDIF}
sa := TestString.Split([','], Options);
if Length(sa) <> Length(Expected) then
begin
WriteLn(' --> Length difference');
Halt(1);
end;
for i := Low(sa) to High(sa) do
if sa[i] <> Expected[i] then
begin
WriteLn(' --> Difference found at pos ', i, ': "', sa[i], '" vs "', Expected[i], '"');
Halt(1);
end;
WriteLn(' --> ok');
end;
begin
{$IFDEF FPC}
WriteLn('Testing ExcludeLastEmpty with individual separator');
WriteLn('--------------------------------------------------');
Test('a,b,c', ['a', 'b', 'c'], TStringSplitOptions.ExcludeLastEmpty, true);
Test('a,b,', ['a', 'b'], TStringSplitOptions.ExcludeLastEmpty, true);
Test('a,,c', ['a', '', 'c'], TStringSplitOptions.ExcludeLastEmpty, true);
Test(',b,c', ['', 'b', 'c'], TStringSplitOptions.ExcludeLastEmpty, true);
Test('a,,', ['a', ''], TStringSplitOptions.ExcludeLastEmpty, true);
Test(',b,', ['','b'], TStringSplitOptions.ExcludeLastEmpty, true);
Test(',,', ['', ''], TStringSplitOptions.ExcludeLastEmpty, true);
WriteLn;
WriteLn('Testing ExcludeEmpty with individual separator');
WriteLn('----------------------------------------------');
Test('a,b,c', ['a', 'b', 'c'], TStringSplitOptions.ExcludeEmpty, true);
Test('a,b,,', ['a', 'b'], TStringSplitOptions.ExcludeEmpty, true);
Test('a,,c', ['a', 'c'], TStringSplitOptions.ExcludeEmpty, true);
Test(',b,c', ['b', 'c'], TStringSplitOptions.ExcludeEmpty, true);
Test('a,,', ['a'], TStringSplitOptions.ExcludeEmpty, true);
Test(',b,', ['b'], TStringSplitOptions.ExcludeEmpty, true);
Test(',,', [], TStringSplitOptions.ExcludeEmpty, true);
{$ENDIF}
WriteLn('Testing ExcludeLastEmpty with set separators');
WriteLn('--------------------------------------------');
Test('a,b,c', ['a', 'b', 'c'], TStringSplitOptions.ExcludeLastEmpty, false);
Test('a,b,', ['a', 'b'], TStringSplitOptions.ExcludeLastEmpty, false);
Test('a,,c', ['a', '', 'c'], TStringSplitOptions.ExcludeLastEmpty, false);
Test(',b,c', ['', 'b', 'c'], TStringSplitOptions.ExcludeLastEmpty, false);
Test('a,,', ['a', ''], TStringSplitOptions.ExcludeLastEmpty, false);
Test(',b,', ['','b'], TStringSplitOptions.ExcludeLastEmpty, false);
Test(',,', ['', ''], TStringSplitOptions.ExcludeLastEmpty, false);
WriteLn;
WriteLn('Testing ExcludeEmpty with set separators');
WriteLn('----------------------------------------');
Test('a,b,c', ['a', 'b', 'c'], TStringSplitOptions.ExcludeEmpty, false);
Test('a,b,,', ['a', 'b'], TStringSplitOptions.ExcludeEmpty, false);
Test('a,,c', ['a', 'c'], TStringSplitOptions.ExcludeEmpty, false);
Test(',b,c', ['b', 'c'], TStringSplitOptions.ExcludeEmpty, false);
Test('a,,', ['a'], TStringSplitOptions.ExcludeEmpty, false);
Test(',b,', ['b'], TStringSplitOptions.ExcludeEmpty, false);
Test(',,', [], TStringSplitOptions.ExcludeEmpty, false);
{$IFNDEF FPC}
WriteLn;
WriteLn('Press ENTER to quit...');
ReadLn;
{$ENDIF}
end.