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:
Luís Ferreira 2021-05-31 23:15:22 +01:00 committed by The Dlang Bot
parent afb382485b
commit 808dca99af

View file

@ -2917,6 +2917,8 @@ if (isConvertibleToString!R)
@system unittest @system unittest
{ {
import std.algorithm.comparison : equal; import std.algorithm.comparison : equal;
import std.algorithm.sorting : sort;
import std.array : array;
import std.path : buildPath; import std.path : buildPath;
auto cwd = getcwd; auto cwd = getcwd;
@ -2927,9 +2929,9 @@ if (isConvertibleToString!R)
dir.buildPath("a").write("."); dir.buildPath("a").write(".");
dir.chdir; // step into dir dir.chdir; // step into dir
"b".write("."); "b".write(".");
dirEntries(".", SpanMode.shallow).equal( assert(dirEntries(".", SpanMode.shallow).array.sort.equal(
[".".buildPath("b"), ".".buildPath("a")] [".".buildPath("a"), ".".buildPath("b")]
); ));
} }
@safe unittest @safe unittest
@ -4605,6 +4607,8 @@ enum SpanMode
{ {
import std.algorithm.comparison : equal; import std.algorithm.comparison : equal;
import std.algorithm.iteration : map; import std.algorithm.iteration : map;
import std.algorithm.sorting : sort;
import std.array : array;
import std.path : buildPath, relativePath; import std.path : buildPath, relativePath;
auto root = deleteme ~ "root"; auto root = deleteme ~ "root";
@ -4613,19 +4617,19 @@ enum SpanMode
root.buildPath("animals").mkdir; root.buildPath("animals").mkdir;
root.buildPath("animals", "cat").mkdir; root.buildPath("animals", "cat").mkdir;
root.buildPath("animals", "dog").mkdir;
root.buildPath("plants").mkdir;
alias removeRoot = (return scope e) => e.relativePath(root); alias removeRoot = (return scope e) => e.relativePath(root);
root.dirEntries(SpanMode.shallow).map!removeRoot.equal( assert(root.dirEntries(SpanMode.depth).map!removeRoot.equal(
["plants", "animals"]); [buildPath("animals", "cat"), "animals"]));
root.dirEntries(SpanMode.depth).map!removeRoot.equal( assert(root.dirEntries(SpanMode.breadth).map!removeRoot.equal(
["plants", "animals/dog", "animals/cat", "animals"]); ["animals", buildPath("animals", "cat")]));
root.dirEntries(SpanMode.breadth).map!removeRoot.equal( root.buildPath("plants").mkdir;
["plants", "animals", "animals/dog", "animals/cat"]);
assert(root.dirEntries(SpanMode.shallow).array.sort.map!removeRoot.equal(
["animals", "plants"]));
} }
private struct DirIteratorImpl private struct DirIteratorImpl
@ -4898,6 +4902,9 @@ public:
directory is traversed. The name of each iterated directory entry directory is traversed. The name of each iterated directory entry
contains the absolute or relative _path (depending on _pathname). 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: Params:
path = The directory to iterate over. path = The directory to iterate over.
If empty, the current directory will be iterated. If empty, the current directory will be iterated.