Skip to content

Commit

Permalink
LDEV-1247 test case for directory filter arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Jan 3, 2025
1 parent 4271d68 commit d15409c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/resource/fld/core-base.fld
Original file line number Diff line number Diff line change
Expand Up @@ -3855,7 +3855,7 @@ Defines the return type of this function:
<description>
Specifies a filter to be used to filter the results:
- A string that uses `*` as a wildcard, for example, `*.cfm`.
- A UDF (User Defined Function) using the following pattern: `functionName(String path):boolean`. The function is run for every single file; if the function returns `true`, the file is included in the list; otherwise, it is omitted.
- A UDF (User Defined Function) using the following pattern: `functionName(String path, String type, String ext):boolean`. The function is run for every single file; if the function returns `true`, the file is included in the list; otherwise, it is omitted. Type is either File or Directory
</description>
</argument>
<argument>
Expand Down
48 changes: 48 additions & 0 deletions test/tickets/LDEV1247.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
component extends="org.lucee.cfml.test.LuceeTestCase" {

public function beforeAll() {
variables.SEP = Server.separator.file;
variables.path = getTempDirectory() & "ldev1247";
if ( directoryExists( path ) )
directoryDelete( path, true );
var path2 = path & "#SEP#a";
directoryCreate( path2 );
cffile( fixnewline=false, output="aaa", file="#path##SEP#b.txt", addnewline=true, action="write" );
cffile( fixnewline=false, output="aaa", file="#path2##SEP#c.txt", addnewline=true, action="write" );
}

public function afterAll() {
directoryDelete( path, true );
structDelete( request, "ldev1427" );
}

function run( testResults , testBox ) {
describe( "test case for DirectoryList() filter", function() {
it(title = "check directoryList filter has arguments (path, type, ext)", body = function( currentSpec ) {
var request.ldev1247 = {};
function filter( path, type, ext ) {
request.ldev1247[ arguments.path ] = duplicate( arguments );
return true;
}
var dir = directoryList( path, true, "query", filter );
expect( dir.recordcount ).toBe( 3 );
expect( structCount( request.ldev1247 ) ).toBe( 3 );
loop query="dir" {
var p = dir.directory & sep & dir.name;
expect ( request.ldev1247 ).toHaveKey( p );
var pp = request.ldev1247[ p ];
if ( pp.type eq "directory" ){
expect( "dir" ).toBe( dir.type ); // note: type query has "dir" instead of "directory"
expect( pp.ext ).toBe( "" );
} else {
expect( pp.type ).toBe( dir.type );
expect( pp.ext ).toBe( listLast( dir.name, "." ) );
}
}
structDelete( request, "ldev1427" );
});

});
}

}

0 comments on commit d15409c

Please sign in to comment.