mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
file: document dirEntries as no garantee of sorted output
Some unittests should compare with a sorted array to be correct. Signed-off-by: Luís Ferreira <contact@lsferreira.net>
This commit is contained in:
parent
afb382485b
commit
808dca99af
1 changed files with 18 additions and 11 deletions
29
std/file.d
29
std/file.d
|
@ -2917,6 +2917,8 @@ if (isConvertibleToString!R)
|
|||
@system unittest
|
||||
{
|
||||
import std.algorithm.comparison : equal;
|
||||
import std.algorithm.sorting : sort;
|
||||
import std.array : array;
|
||||
import std.path : buildPath;
|
||||
|
||||
auto cwd = getcwd;
|
||||
|
@ -2927,9 +2929,9 @@ if (isConvertibleToString!R)
|
|||
dir.buildPath("a").write(".");
|
||||
dir.chdir; // step into dir
|
||||
"b".write(".");
|
||||
dirEntries(".", SpanMode.shallow).equal(
|
||||
[".".buildPath("b"), ".".buildPath("a")]
|
||||
);
|
||||
assert(dirEntries(".", SpanMode.shallow).array.sort.equal(
|
||||
[".".buildPath("a"), ".".buildPath("b")]
|
||||
));
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
|
@ -4605,6 +4607,8 @@ enum SpanMode
|
|||
{
|
||||
import std.algorithm.comparison : equal;
|
||||
import std.algorithm.iteration : map;
|
||||
import std.algorithm.sorting : sort;
|
||||
import std.array : array;
|
||||
import std.path : buildPath, relativePath;
|
||||
|
||||
auto root = deleteme ~ "root";
|
||||
|
@ -4613,19 +4617,19 @@ enum SpanMode
|
|||
|
||||
root.buildPath("animals").mkdir;
|
||||
root.buildPath("animals", "cat").mkdir;
|
||||
root.buildPath("animals", "dog").mkdir;
|
||||
root.buildPath("plants").mkdir;
|
||||
|
||||
alias removeRoot = (return scope e) => e.relativePath(root);
|
||||
|
||||
root.dirEntries(SpanMode.shallow).map!removeRoot.equal(
|
||||
["plants", "animals"]);
|
||||
assert(root.dirEntries(SpanMode.depth).map!removeRoot.equal(
|
||||
[buildPath("animals", "cat"), "animals"]));
|
||||
|
||||
root.dirEntries(SpanMode.depth).map!removeRoot.equal(
|
||||
["plants", "animals/dog", "animals/cat", "animals"]);
|
||||
assert(root.dirEntries(SpanMode.breadth).map!removeRoot.equal(
|
||||
["animals", buildPath("animals", "cat")]));
|
||||
|
||||
root.dirEntries(SpanMode.breadth).map!removeRoot.equal(
|
||||
["plants", "animals", "animals/dog", "animals/cat"]);
|
||||
root.buildPath("plants").mkdir;
|
||||
|
||||
assert(root.dirEntries(SpanMode.shallow).array.sort.map!removeRoot.equal(
|
||||
["animals", "plants"]));
|
||||
}
|
||||
|
||||
private struct DirIteratorImpl
|
||||
|
@ -4898,6 +4902,9 @@ public:
|
|||
directory is traversed. The name of each iterated directory entry
|
||||
contains the absolute or relative _path (depending on _pathname).
|
||||
|
||||
Note: The order of returned directory entries is as it is provided by the
|
||||
operating system / filesystem, and may not follow any particular sorting.
|
||||
|
||||
Params:
|
||||
path = The directory to iterate over.
|
||||
If empty, the current directory will be iterated.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue