LazUtils: Update unit test for Masks.

git-svn-id: trunk@64666 -
This commit is contained in:
juha 2021-02-26 08:25:24 +00:00
parent 4113f5b16f
commit b8a5b2df73

View File

@ -33,15 +33,18 @@ type
private
FS, FMask: String;
procedure Test;
protected
procedure TestMask(const S, Mask: String; Result: Boolean);
procedure TestMaskException(const S, Mask: String; AFail: Boolean);
procedure TestWindowsMask(const S, Mask: String; Result: Boolean);
published
procedure TestMaskSyntax;
procedure TestNil;
procedure TestAnyText;
procedure TestAnyChar;
procedure TestCharSet;
procedure TestMaskSyntax;
procedure TestCase;
procedure TestSpecial;
procedure TestWindows;
end;
procedure TTestMask.Test;
@ -49,11 +52,6 @@ begin
MatchesMask(FS, FMask);
end;
procedure TTestMask.TestMask(const S, Mask: String; Result: Boolean);
begin
AssertEquals(S + ' match ' + Mask + ': ', Result, MatchesMask(S, Mask));
end;
procedure TTestMask.TestMaskException(const S, Mask: String; AFail: Boolean);
begin
FS := S;
@ -89,17 +87,23 @@ begin
TestMaskException('', '[', True);
TestMaskException('', '[a', True);
TestMaskException('', '[]', True);
TestMaskException('', '[!]', True);
TestMaskException('', '[-]', True);
//TestMaskException('', '[!]', True);
//TestMaskException('', '[-]', True);
TestMaskException('', '[a-]', True);
TestMaskException('', '[-a]', True);
TestMaskException('', '[--a]', True);
//TestMaskException('', '[-a]', True);
//TestMaskException('', '[--a]', True);
end;
procedure TTestMask.TestMask(const S, Mask: String; Result: Boolean);
begin
AssertEquals(S + ' match ' + Mask + ': ', Result, MatchesMask(S, Mask));
end;
procedure TTestMask.TestNil;
begin
TestMask('', '', True);
TestMask('', '*', True);
TestMask('', '?', False);
TestMask('', 'a', False);
TestMask('', '[a]', False);
@ -158,6 +162,9 @@ begin
TestMask('abcde', 'a*d', False); // ASCII
TestMask('abcde', 'a*c*d', False);
TestMask('abcde', 'b*d*e', False);
TestMask('abc.txt', '.*', False);
TestMask('abc.txt', '*.', False);
TestMask('abc', '*.', False);
TestMask('äöæ獵豹☺', 'ä*獵豹', False); // Unicode
TestMask('äöæ獵豹☺', 'ä*æ*獵豹', False);
@ -207,7 +214,7 @@ begin
TestMask('ö', '[ö]', True); // Unicode
TestMask('ö', '[!ä]', True);
TestMask('ö', '[ä-ũ]', True);
//TestMask('ö', '[a-d]', True);
TestMask('է', '[ՠ-կ]', True);
TestMask('ö', '[!☺-☂]', True);
TestMask('ö', '[äũö]', True);
@ -218,10 +225,60 @@ begin
TestMask('ö', '[ä]', False); // Unicode
TestMask('ö', '[!ö]', False);
//TestMask('ö', '[a-b]', False);
TestMask('ö', '[ՠ-կ]', False);
TestMask('ö', '[äũæ]', False);
end;
procedure TTestMask.TestCase;
begin
TestMask('aBc', '?b?', True);
TestMask('äÖæ', 'Äö?', True);
TestMask('abcÖ', '*[äũö]', True);
end;
procedure TTestMask.TestSpecial;
begin
TestMask('a?c', '?[?]?', True);
TestMask('abc', '?[?]?', True);
TestMask('ac', '?[?]?', True);
TestMask('a?c', '?\??', True);
TestMask('ab*.x', '??\*.x', True);
TestMask('a[c]d', '?\[*', True);
TestMask('x \ y', '? \\ ?', True);
TestMask('C:\x', 'C:\x', False);
TestMask('abcd', '?[?]?', False);
end;
procedure TTestMask.TestWindowsMask(const S, Mask: String; Result: Boolean);
begin
AssertEquals(S + ' match ' + Mask + ': ', Result, MatchesWindowsMask(S, Mask));
end;
procedure TTestMask.TestWindows;
begin
TestWindowsMask('abc.txt', '*.*', True);
TestWindowsMask('abc', '*.*', True);
TestWindowsMask('abc.txt', '*', True);
TestWindowsMask('abc', '*', True);
TestWindowsMask('abc', '*.', True);
TestWindowsMask('abcd.txt', 'abc???.*', True);
TestWindowsMask('abcd.txt', 'abc???.txt?', True);
TestWindowsMask('abcd.txt', 'abc*', True);
TestWindowsMask('C:\x', 'C:\x', True);
TestWindowsMask('C:\ab[c]d', 'C:*[*]*', True);
TestWindowsMask('', '*', True);
TestWindowsMask('', '?', True);
TestWindowsMask('abcd.txt', '*.txtx', False);
TestWindowsMask('abc.txt', '*.', False);
TestWindowsMask('abc.txt', '.*', False);
TestWindowsMask('abc', '.*', False);
TestWindowsMask('x \ y', '? \\ ?', False);
TestWindowsMask('', 'a', False);
TestWindowsMask('', '[a]', False);
end;
begin
RegisterTest(TTestMask);