mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-05 11:38:04 +02:00
ide: extended TrimSearchPath to consider star directories
This commit is contained in:
parent
edac588a96
commit
c438c4e4b4
@ -23,6 +23,7 @@ type
|
||||
published
|
||||
procedure TestRelateDirectoryMasks;
|
||||
procedure TestFileIsInSPDirectory;
|
||||
procedure TestTrimSearchPath;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -71,15 +72,38 @@ begin
|
||||
t([''],0,0,TSPFileMaskRelation.None);
|
||||
t(['a'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['foo'],0,0,TSPFileMaskRelation.Equal);
|
||||
{$IFDEF MSWindows}
|
||||
t(['C:\foo'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['C:\foo\bar'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['C:\foo\bar','C:\foo\bar\'],0,1,TSPFileMaskRelation.Equal);
|
||||
{$ELSE}
|
||||
t(['/foo'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['/foo/bar'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['/foo/bar','/foo/bar/'],0,1,TSPFileMaskRelation.Equal);
|
||||
{$ENDIF}
|
||||
|
||||
// star
|
||||
t(['*'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['*','a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['*','.'],0,1,TSPFileMaskRelation.None);
|
||||
t(['*','..'],0,1,TSPFileMaskRelation.None);
|
||||
{$IFDEF MSWindows}
|
||||
t(['C:\*'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['C:\foo\*'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['*','a\'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['C:\*','C:\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['C:\*','a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\foo\*','C:\foo\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['C:\foo\*','C:\foo\a\'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['foo\*','foo\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['C:\foo\*','C:\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['foo\*','a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\foo\*','C:\foo\bar\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['foo\*','foo\bar\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\*','C:\'],0,1,TSPFileMaskRelation.None);
|
||||
{$ELSE}
|
||||
t(['/*'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['/foo/*'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['*','a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['*','a/'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['/*','/a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['/*','a'],0,1,TSPFileMaskRelation.None);
|
||||
@ -90,23 +114,33 @@ begin
|
||||
t(['foo/*','a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['/foo/*','/foo/bar/a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['foo/*','foo/bar/a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['*','.'],0,1,TSPFileMaskRelation.None);
|
||||
t(['*','..'],0,1,TSPFileMaskRelation.None);
|
||||
t(['/*','/'],0,1,TSPFileMaskRelation.None);
|
||||
{$ENDIF}
|
||||
|
||||
// star star
|
||||
t(['**'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['**','a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','.'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','..'],0,1,TSPFileMaskRelation.None);
|
||||
t(['**','foo\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
{$IFDEF MSWindows}
|
||||
t(['C:\**'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['C:\bar\**'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['**','C:\foo\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\**','foo\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\foo\**','foo\a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['C:\foo\**','C:\foo\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['C:\foo\**','C:\foo\bar\a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
{$ELSE}
|
||||
t(['/**'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['/bar/**'],0,0,TSPFileMaskRelation.Equal);
|
||||
t(['**','a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','foo/a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','/foo/a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['/**','foo/a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['/foo/**','foo/a'],0,1,TSPFileMaskRelation.None);
|
||||
t(['/foo/**','/foo/a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['/foo/**','/foo/bar/a'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','.'],0,1,TSPFileMaskRelation.LeftMoreGeneral);
|
||||
t(['**','..'],0,1,TSPFileMaskRelation.None);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TTestSearchPathProcs.TestFileIsInSPDirectory;
|
||||
@ -134,6 +168,16 @@ begin
|
||||
t('foo/','foo',TSPMaskType.None,true);
|
||||
t('foo/a','foo',TSPMaskType.None,true);
|
||||
t('foo/bar/a','foo',TSPMaskType.None,false);
|
||||
{$IFDEF MSWindows}
|
||||
t('C:\a','',TSPMaskType.None,false);
|
||||
t('C:\a\b','',TSPMaskType.None,false);
|
||||
t('C:\','foo',TSPMaskType.None,false);
|
||||
t('C:\','C:\foo',TSPMaskType.None,false);
|
||||
t('C:\a','C:\foo',TSPMaskType.None,false);
|
||||
t('C:\foo\','C:\foo',TSPMaskType.None,true);
|
||||
t('C:\foo\a','C:\foo',TSPMaskType.None,true);
|
||||
t('C:\foo\bar\a','C:\foo',TSPMaskType.None,false);
|
||||
{$ELSE}
|
||||
t('/a','',TSPMaskType.None,false);
|
||||
t('/a/b','',TSPMaskType.None,false);
|
||||
t('/','foo',TSPMaskType.None,false);
|
||||
@ -142,6 +186,7 @@ begin
|
||||
t('/foo/','/foo',TSPMaskType.None,true);
|
||||
t('/foo/a','/foo',TSPMaskType.None,true);
|
||||
t('/foo/bar/a','/foo',TSPMaskType.None,false);
|
||||
{$ENDIF}
|
||||
|
||||
t('','',TSPMaskType.Star,false);
|
||||
t('.','',TSPMaskType.Star,false);
|
||||
@ -156,6 +201,18 @@ begin
|
||||
t('foo/bar','foo',TSPMaskType.Star,false);
|
||||
t('foo/bar/a','foo',TSPMaskType.Star,true);
|
||||
t('foo/bar/a/b','foo',TSPMaskType.Star,false);
|
||||
{$IFDEF MSWindows}
|
||||
t('C:\a','',TSPMaskType.Star,false);
|
||||
t('C:\a','C:\',TSPMaskType.Star,false);
|
||||
t('C:\a\b','C:\',TSPMaskType.Star,true);
|
||||
t('C:\a\b\c','C:\',TSPMaskType.Star,false);
|
||||
t('C:\','C:\foo',TSPMaskType.Star,false);
|
||||
t('C:\a','C:\foo',TSPMaskType.Star,false);
|
||||
t('C:\foo\','C:\foo',TSPMaskType.Star,false);
|
||||
t('C:\foo\bar','C:\foo',TSPMaskType.Star,false);
|
||||
t('C:\foo\bar\a','C:\foo',TSPMaskType.Star,true);
|
||||
t('C:\foo\bar\a\b','C:\foo',TSPMaskType.Star,false);
|
||||
{$ELSE}
|
||||
t('/a','',TSPMaskType.Star,false);
|
||||
t('/a','/',TSPMaskType.Star,false);
|
||||
t('/a/b','/',TSPMaskType.Star,true);
|
||||
@ -166,6 +223,7 @@ begin
|
||||
t('/foo/bar','/foo',TSPMaskType.Star,false);
|
||||
t('/foo/bar/a','/foo',TSPMaskType.Star,true);
|
||||
t('/foo/bar/a/b','/foo',TSPMaskType.Star,false);
|
||||
{$ENDIF}
|
||||
|
||||
t('','',TSPMaskType.StarStar,false);
|
||||
t('.','',TSPMaskType.StarStar,true);
|
||||
@ -181,6 +239,19 @@ begin
|
||||
t('foo/bar','foo/bar',TSPMaskType.StarStar,false);
|
||||
t('foo/bar/a','foo',TSPMaskType.StarStar,true);
|
||||
t('foo/bar/a','foo/bar',TSPMaskType.StarStar,true);
|
||||
{$IFDEF MSWindows}
|
||||
t('foo\','C:\foo',TSPMaskType.StarStar,false);
|
||||
t('C:\a','C:\',TSPMaskType.StarStar,true);
|
||||
t('C:\a\b','C:\',TSPMaskType.StarStar,true);
|
||||
t('C:\a\b\c','C:\',TSPMaskType.StarStar,true);
|
||||
t('C:\','C:\foo',TSPMaskType.StarStar,false);
|
||||
t('C:\a','C:\foo',TSPMaskType.StarStar,false);
|
||||
t('C:\foo\','C:\foo',TSPMaskType.StarStar,true);
|
||||
t('C:\foo\bar','C:\foo',TSPMaskType.StarStar,true);
|
||||
t('C:\foo\bar','C:\foo\bar',TSPMaskType.StarStar,false);
|
||||
t('C:\foo\bar\a','C:\foo',TSPMaskType.StarStar,true);
|
||||
t('C:\foo\bar\a','C:\foo\bar',TSPMaskType.StarStar,true);
|
||||
{$ELSE}
|
||||
t('foo/','/foo',TSPMaskType.StarStar,false);
|
||||
t('/a','/',TSPMaskType.StarStar,true);
|
||||
t('/a/b','/',TSPMaskType.StarStar,true);
|
||||
@ -192,6 +263,31 @@ begin
|
||||
t('/foo/bar','/foo/bar',TSPMaskType.StarStar,false);
|
||||
t('/foo/bar/a','/foo',TSPMaskType.StarStar,true);
|
||||
t('/foo/bar/a','/foo/bar',TSPMaskType.StarStar,true);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TTestSearchPathProcs.TestTrimSearchPath;
|
||||
|
||||
procedure t(SearchPath, BaseDirectory: string;
|
||||
DeleteDoubles, ExpandPaths: boolean; Expected: string);
|
||||
var
|
||||
Actual: String;
|
||||
begin
|
||||
SearchPath:=SetDirSeparators(SearchPath);
|
||||
BaseDirectory:=SetDirSeparators(BaseDirectory);
|
||||
Actual:=TrimSearchPath(SearchPath,BaseDirectory,DeleteDoubles,ExpandPaths);
|
||||
if Actual=Expected then exit;
|
||||
Fail('SearchPath="'+SearchPath+'" BaseDirectory="'+BaseDirectory+'" DeleteDoubles='+dbgs(DeleteDoubles)+' ExpandPaths='+dbgs(ExpandPaths)+' expected "'+Expected+'", but was "'+Actual+'"');
|
||||
end;
|
||||
|
||||
begin
|
||||
t('/a','',true,false,'/a');
|
||||
t('/foo/*;/foo/*','',true,false,'/foo/*');
|
||||
t('/foo/*;/foo/bar','',true,false,'/foo/*');
|
||||
t('/foo/bar;/foo/*','',true,false,'/foo/bar;/foo/*');
|
||||
t('/a;/foo/*;/b;/foo/bar','',true,false,'/a;/foo/*;/b');
|
||||
t('/a;/foo/*;/b;/foo/**','',true,false,'/a;/foo/*;/b;/foo/**');
|
||||
t('/a;/foo/**;/b;/foo/*','',true,false,'/a;/foo/**;/b');
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user