Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,12 @@ if (isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && hasAssig
// Loop invariant
version(unittest)
{
import std.algorithm.searching : all;
assert(r[0 .. lo].all!(x => !lt(p, x)));
assert(r[hi + 1 .. r.length].all!(x => !lt(x, p)));
// this used to import std.algorithm.all, but we want to save
// imports when unittests are enabled if possible.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment here to prevent regression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be version (StdUnittest) anyway?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StdUnittest was reverted because apparently -deps includes all unittests and thus usage of StdUnittest caused breakage for projects using -deps

foreach (x; r[0 .. lo])
assert(!lt(p, x));
foreach (x; r[hi+1 .. r.length])
assert(!lt(x, p));
}
do ++lo; while (lt(r[lo], p));
r[hi] = r[lo];
Expand Down Expand Up @@ -3444,21 +3447,14 @@ done:
{
auto a = [ 10, 5, 3, 4, 8, 11, 13, 3, 9, 4, 10 ];
assert(expandPartition!((a, b) => a < b)(a, 4, 5, 6) == 9);
a = randomArray;
if (a.length == 0) return;
expandPartition!((a, b) => a < b)(a, a.length / 2, a.length / 2,
a.length / 2 + 1);
}

version(unittest)
private T[] randomArray(Flag!"exactSize" flag = No.exactSize, T = int)(
size_t maxSize = 1000,
T minValue = 0, T maxValue = 255)
{
import std.algorithm.iteration : map;
import std.random : uniform;
auto size = flag == Yes.exactSize ? maxSize : uniform(1, maxSize);
return iota(0, size).map!(_ => uniform(minValue, maxValue)).array;
auto size = uniform(1, 1000);
a = iota(0, size).map!(_ => uniform(0, 1000)).array;
if (a.length == 0) return;
expandPartition!((a, b) => a < b)(a, a.length / 2, a.length / 2,
a.length / 2 + 1);
}

@safe unittest
Expand Down
5 changes: 3 additions & 2 deletions std/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ private template blockAttribute(T)
enum blockAttribute = GC.BlkAttr.NO_SCAN;
}
}
version(unittest)

@safe unittest
{
import core.memory : UGC = GC;
static assert(!(blockAttribute!void & UGC.BlkAttr.NO_SCAN));
Expand All @@ -572,7 +573,7 @@ private template nDimensions(T)
}
}

version(unittest)
@safe unittest
{
static assert(nDimensions!(uint[]) == 1);
static assert(nDimensions!(float[][]) == 2);
Expand Down
23 changes: 14 additions & 9 deletions std/ascii.d
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ $(TR $(TD Enums) $(TD
+/
module std.ascii;

version(unittest)
{
// FIXME: When dmd bug #314 is fixed, make these selective.
import std.meta; // : AliasSeq;
import std.range; // : chain;
import std.traits; // : functionAttributes, FunctionAttribute, isSafe;
}


immutable fullHexDigits = "0123456789ABCDEFabcdef"; /// 0 .. 9A .. Fa .. f
immutable hexDigits = fullHexDigits[0 .. 16]; /// 0 .. 9A .. F
immutable lowerHexDigits = "0123456789abcdef"; /// 0 .. 9a .. f
Expand Down Expand Up @@ -142,6 +133,7 @@ bool isAlphaNum(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; chain(digits, octalDigits, fullHexDigits, letters, lowercase, uppercase))
assert(isAlphaNum(c));

Expand Down Expand Up @@ -173,6 +165,7 @@ bool isAlpha(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; chain(letters, lowercase, uppercase))
assert(isAlpha(c));

Expand Down Expand Up @@ -204,6 +197,7 @@ bool isLower(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; lowercase)
assert(isLower(c));

Expand Down Expand Up @@ -235,6 +229,7 @@ bool isUpper(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; uppercase)
assert(isUpper(c));

Expand Down Expand Up @@ -267,6 +262,7 @@ bool isDigit(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; digits)
assert(isDigit(c));

Expand Down Expand Up @@ -296,6 +292,7 @@ bool isOctalDigit(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; octalDigits)
assert(isOctalDigit(c));

Expand Down Expand Up @@ -326,6 +323,7 @@ bool isHexDigit(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; fullHexDigits)
assert(isHexDigit(c));

Expand Down Expand Up @@ -363,6 +361,7 @@ bool isWhite(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (c; whitespace)
assert(isWhite(c));

Expand Down Expand Up @@ -399,6 +398,7 @@ bool isControl(dchar c) @safe pure nothrow @nogc

@safe unittest
{
import std.range;
foreach (dchar c; 0 .. 32)
assert(isControl(c));
assert(isControl(127));
Expand Down Expand Up @@ -590,6 +590,7 @@ if (is(C : dchar))
@safe pure nothrow unittest
{

import std.meta;
static foreach (C; AliasSeq!(char, wchar, dchar, immutable char, ubyte))
{
foreach (i, c; uppercase)
Expand Down Expand Up @@ -651,6 +652,7 @@ if (is(C : dchar))

@safe pure nothrow unittest
{
import std.meta;
static foreach (C; AliasSeq!(char, wchar, dchar, immutable char, ubyte))
{
foreach (i, c; lowercase)
Expand All @@ -676,6 +678,9 @@ if (is(C : dchar))

@safe unittest //Test both toUpper and toLower with non-builtin
{
import std.meta;
import std.traits;

//User Defined [Char|Wchar|Dchar]
static struct UDC { char c; alias c this; }
static struct UDW { wchar c; alias c this; }
Expand Down
9 changes: 3 additions & 6 deletions std/bitmanip.d
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ import std.range.primitives;
public import std.system : Endian;
import std.traits;

version(unittest)
{
import std.stdio;
}


private string myToString(ulong n)
{
import core.internal.string : UnsignedStringBuf, unsignedToTempString;
Expand Down Expand Up @@ -2770,6 +2764,7 @@ private ulong swapEndianImpl(ulong val) @trusted pure nothrow @nogc
@safe unittest
{
import std.meta;
import std.stdio;
static foreach (T; AliasSeq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong, char, wchar, dchar))
{{
scope(failure) writeln("Failed type: ", T.stringof);
Expand Down Expand Up @@ -2898,6 +2893,7 @@ if (isFloatOrDouble!T)
@safe unittest
{
import std.meta;
import std.stdio;
static foreach (T; AliasSeq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong,
char, wchar, dchar
/* The trouble here is with floats and doubles being compared against nan
Expand Down Expand Up @@ -3072,6 +3068,7 @@ if (isFloatOrDouble!T)
@safe unittest
{
import std.meta;
import std.stdio;
static foreach (T; AliasSeq!(bool, byte, ubyte, short, ushort, int, uint, long, ulong,
char, wchar, dchar/*,
float, double*/))
Expand Down