Skip to content

Commit

Permalink
Make more modules publicly runnable on dlang.org
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Dec 19, 2016
1 parent 9965433 commit 602b23e
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 53 deletions.
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -520,7 +520,7 @@ style: ../dscanner/dsc
publictests: $(LIB)
# parse all public unittests from Phobos, for now some modules are excluded
rm -rf ./out
DFLAGS="$(DFLAGS) $(LIB) -defaultlib= -debuglib= $(LINKDL)" $(DUB) --compiler=$${PWD}/$(DMD) --single ../tools/phobos_tests_extractor.d -- --inputdir . --ignore "allocator/allocator_list.d,allocator/building_blocks/allocator_list.d,allocator/building_blocks/free_list.d,allocator/building_blocks/quantizer,allocator/building_blocks/quantizer,allocator/building_blocks/stats_collector.d,base64.d,bitmanip.d,concurrency.d,conv.d,csv.d,datetime.d,digest/hmac.d,digest/sha.d,file.d,index.d,isemail.d,logger/core.d,logger/nulllogger.d,math.d,ndslice/selection.d,ndslice/slice.d,numeric.d,stdio.d,traits.d,typecons.d,uni.d,utf.d,uuid.d" --outputdir ./out
DFLAGS="$(DFLAGS) $(LIB) -defaultlib= -debuglib= $(LINKDL)" $(DUB) --compiler=$${PWD}/$(DMD) --single ../tools/phobos_tests_extractor.d -- --inputdir . --ignore "base64.d,building_blocks/free_list,building_blocks/quantizer,digest/hmac.d,file.d,index.d,math.d,ndslice/selection.d,stdio.d,traits.d,typecons.d,uuid.d" --outputdir ./out
# execute all parsed tests
for file in $$(find out -name '*.d'); do echo "executing $${file}" && $(DMD) $(DFLAGS) -defaultlib= -debuglib= $(LIB) -main -unittest -run $$file || exit 1 ; done

Expand Down
3 changes: 1 addition & 2 deletions std/bitmanip.d
Expand Up @@ -3015,6 +3015,7 @@ T read(T, Endian endianness = Endian.bigEndian, R)(ref R range)
///
@safe unittest
{
import std.range.primitives : empty;
ubyte[] buffer = [1, 5, 22, 9, 44, 255, 8];
assert(buffer.length == 7);

Expand Down Expand Up @@ -3788,7 +3789,6 @@ private uint countTrailingZeros(T)(T value) @nogc pure nothrow
return bsf(value);
}

///
@safe unittest
{
assert(countTrailingZeros(1) == 0);
Expand Down Expand Up @@ -3869,7 +3869,6 @@ private uint countBitsSet(T)(T value) @nogc pure nothrow
return cast(uint)c;
}

///
@safe unittest
{
assert(countBitsSet(1) == 1);
Expand Down
2 changes: 2 additions & 0 deletions std/concurrency.d
Expand Up @@ -2650,6 +2650,8 @@ auto ref initOnce(alias var)(lazy typeof(var) init, Mutex mutex)
/// Use a separate mutex when init blocks on another thread that might also call initOnce.
@system unittest
{
import core.sync.mutex : Mutex;

static shared bool varA, varB;
__gshared Mutex m;
m = new Mutex;
Expand Down
5 changes: 3 additions & 2 deletions std/conv.d
Expand Up @@ -3934,7 +3934,6 @@ private T octal(T)(const string num)
return value;
}

///
@system unittest
{
int a = octal!int("10");
Expand Down Expand Up @@ -5382,6 +5381,7 @@ auto unsigned(T)(T x) if (isIntegral!T)
///
@safe unittest
{
import std.traits : Unsigned;
immutable int s = 42;
auto u1 = unsigned(s); //not qualified
static assert(is(typeof(u1) == uint));
Expand Down Expand Up @@ -5456,6 +5456,8 @@ auto signed(T)(T x) if (isIntegral!T)
///
@safe unittest
{
import std.traits : Signed;

immutable uint u = 42;
auto s1 = signed(u); //not qualified
static assert(is(typeof(s1) == int));
Expand Down Expand Up @@ -5622,7 +5624,6 @@ private bool isHexLiteral(String)(scope const String hexData)
return !(i & 1);
}

///
@safe unittest
{
// test all the hex digits
Expand Down
4 changes: 3 additions & 1 deletion std/csv.d
Expand Up @@ -1102,7 +1102,7 @@ public:
///
@safe pure unittest
{
import std.algorithm;
import std.algorithm.comparison : equal;

string str = `76;^26^;22`;
int[] ans = [76,26,22];
Expand Down Expand Up @@ -1468,6 +1468,8 @@ void csvNextToken(Range, Malformed ErrorLevel = Malformed.throwException,
@safe unittest
{
import std.array : appender;
import std.range.primitives : popFront;

string str = "65,63\n123,3673";

auto a = appender!(char[])();
Expand Down
14 changes: 14 additions & 0 deletions std/datetime.d
Expand Up @@ -4036,6 +4036,8 @@ public:
///
@safe unittest
{
import std.typecons : No;

auto st1 = SysTime(DateTime(2010, 1, 1, 12, 33, 33));
st1.roll!"months"(1);
assert(st1 == SysTime(DateTime(2010, 2, 1, 12, 33, 33)));
Expand Down Expand Up @@ -10054,6 +10056,8 @@ public:
///
@safe unittest
{
import std.typecons : No;

auto d1 = Date(2010, 1, 1);
d1.add!"months"(11);
assert(d1 == Date(2010, 12, 1));
Expand Down Expand Up @@ -10821,6 +10825,8 @@ public:
///
@safe unittest
{
import std.typecons : No;

auto d1 = Date(2010, 1, 1);
d1.roll!"months"(1);
assert(d1 == Date(2010, 2, 1));
Expand Down Expand Up @@ -15851,6 +15857,8 @@ public:
///
@safe unittest
{
import std.typecons : No;

auto dt1 = DateTime(2010, 1, 1, 12, 30, 33);
dt1.add!"months"(11);
assert(dt1 == DateTime(2010, 12, 1, 12, 30, 33));
Expand Down Expand Up @@ -15914,6 +15922,8 @@ public:
///
@safe unittest
{
import std.typecons : No;

auto dt1 = DateTime(2010, 1, 1, 12, 33, 33);
dt1.roll!"months"(1);
assert(dt1 == DateTime(2010, 2, 1, 12, 33, 33));
Expand Down Expand Up @@ -26443,6 +26453,8 @@ static TP delegate(in TP) everyDuration(TP, Direction dir = Direction.fwd, D)
///
@system unittest
{
import std.typecons : Yes;

auto interval = Interval!Date(Date(2010, 9, 2), Date(2025, 9, 27));
auto func = everyDuration!Date(4, 1, Yes.allowDayOverflow, dur!"days"(2));
auto range = interval.fwdRange(func);
Expand Down Expand Up @@ -33120,6 +33132,8 @@ afterMon: stripAndCheckLen(value[3 .. value.length], "1200:00A".length);
///
@safe unittest
{
import std.exception : assertThrown;

auto tz = new immutable SimpleTimeZone(hours(-8));
assert(parseRFC822DateTime("Sat, 6 Jan 1990 12:14:19 -0800") ==
SysTime(DateTime(1990, 1, 6, 12, 14, 19), tz));
Expand Down
2 changes: 1 addition & 1 deletion std/digest/sha.d
Expand Up @@ -733,7 +733,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
if (inputLen - i)
(&buffer[index])[0 .. inputLen-i] = (&input[i])[0 .. inputLen-i];
}
///

unittest
{
typeof(this) dig;
Expand Down
7 changes: 4 additions & 3 deletions std/experimental/allocator/building_blocks/allocator_list.d
Expand Up @@ -536,10 +536,11 @@ version(Posix) unittest
{
import std.algorithm.comparison : max;
import std.experimental.allocator.building_blocks.region : Region;
import std.experimental.allocator.mmap_allocator : MmapAllocator;
import std.experimental.allocator.building_blocks.free_list : ContiguousFreeList;
import std.experimental.allocator.building_blocks.segregator : Segregator;
import std.experimental.allocator.building_blocks.free_list
: ContiguousFreeList;
import std.experimental.allocator.building_blocks.null_allocator : NullAllocator;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.mmap_allocator : MmapAllocator;

// Ouroboros allocator list based upon 4MB regions, fetched directly from
// mmap. All memory is released upon destruction.
Expand Down
15 changes: 13 additions & 2 deletions std/experimental/allocator/building_blocks/free_list.d
Expand Up @@ -117,6 +117,9 @@ struct FreeList(ParentAllocator,
///
unittest
{
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.common : chooseAtRuntime;

FreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
a.min = 64;
a.max = 128;
Expand Down Expand Up @@ -674,6 +677,8 @@ unittest
import std.experimental.allocator.building_blocks.allocator_list
: AllocatorList;

import std.experimental.allocator.common : unbounded;

alias ScalableFreeList = AllocatorList!((n) =>
ContiguousFreeList!(GCAllocator, 0, unbounded)(4096)
);
Expand Down Expand Up @@ -885,7 +890,10 @@ struct SharedFreeList(ParentAllocator,
///
unittest
{
SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.common : chooseAtRuntime;

shared SharedFreeList!(Mallocator, chooseAtRuntime, chooseAtRuntime) a;
// Set the maxSize first so setting the minSize doesn't throw
a.max = 128;
a.min = 64;
Expand All @@ -903,7 +911,10 @@ struct SharedFreeList(ParentAllocator,
///
unittest
{
SharedFreeList!(Mallocator, 50, 50, chooseAtRuntime) a;
import std.experimental.allocator.mallocator : Mallocator;
import std.experimental.allocator.common : chooseAtRuntime;

shared SharedFreeList!(Mallocator, 50, 50, chooseAtRuntime) a;
// Set the maxSize first so setting the minSize doesn't throw
a.approxMaxLength = 128;
assert(a.approxMaxLength == 128);
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/allocator/building_blocks/quantizer.d
Expand Up @@ -213,6 +213,8 @@ unittest
{
import std.experimental.allocator.building_blocks.free_tree : FreeTree;
import std.experimental.allocator.gc_allocator : GCAllocator;
import std.experimental.allocator.common : roundUpToMultipleOf;

// Quantize small allocations to a multiple of cache line, large ones to a
// multiple of page size
alias MyAlloc = Quantizer!(
Expand Down
1 change: 1 addition & 0 deletions std/experimental/logger/core.d
Expand Up @@ -1784,6 +1784,7 @@ functions.
/// Ditto
unittest
{
import std.experimental.logger.filelogger : FileLogger;
import std.file : deleteme, remove;
Logger l = stdThreadLocalLog;
stdThreadLocalLog = new FileLogger(deleteme ~ "-someFile.log");
Expand Down
2 changes: 2 additions & 0 deletions std/experimental/logger/nulllogger.d
Expand Up @@ -31,6 +31,8 @@ class NullLogger : Logger
///
@safe unittest
{
import std.experimental.logger.nulllogger : LogLevel;

auto nl1 = new NullLogger(LogLevel.all);
nl1.info("You will never read this.");
nl1.fatal("You will never read this, either and it will not throw");
Expand Down
3 changes: 2 additions & 1 deletion std/file.d
Expand Up @@ -53,7 +53,8 @@ else version (Posix)
else
static assert(0);

package @property string deleteme() @safe
// Purposefully not documented. Use at your own risk
@property string deleteme() @safe
{
import std.conv : to;
import std.path : buildPath;
Expand Down
46 changes: 7 additions & 39 deletions std/net/isemail.d
Expand Up @@ -61,7 +61,7 @@ EmailStatus isEmail (Char) (const(Char)[] email, CheckDns checkDNS = No.checkDns
EmailStatusCode errorLevel = EmailStatusCode.none) if (isSomeChar!(Char))
{
import std.algorithm.iteration : uniq;
import std.algorithm.searching : canFind;
import std.algorithm.searching : canFind, maxElement;
import std.exception : enforce;
import std.array : array, split;
import std.conv : to;
Expand Down Expand Up @@ -387,7 +387,7 @@ EmailStatus isEmail (Char) (const(Char)[] email, CheckDns checkDNS = No.checkDns
switch (token)
{
case Token.closeBracket:
if (returnStatus.max() < EmailStatusCode.deprecated_)
if (returnStatus.maxElement() < EmailStatusCode.deprecated_)
{
auto maxGroups = 8;
size_t index = -1;
Expand Down Expand Up @@ -687,11 +687,11 @@ EmailStatus isEmail (Char) (const(Char)[] email, CheckDns checkDNS = No.checkDns
throw new Exception("Unkown context: " ~ to!(string)(context));
}

if (returnStatus.max() > EmailStatusCode.rfc5322)
if (returnStatus.maxElement() > EmailStatusCode.rfc5322)
break;
}

if (returnStatus.max() < EmailStatusCode.rfc5322)
if (returnStatus.maxElement() < EmailStatusCode.rfc5322)
{
if (context == EmailPart.contextQuotedString)
returnStatus ~= EmailStatusCode.errorUnclosedQuotedString;
Expand Down Expand Up @@ -730,12 +730,12 @@ EmailStatus isEmail (Char) (const(Char)[] email, CheckDns checkDNS = No.checkDns

auto dnsChecked = false;

if (checkDNS == Yes.checkDns && returnStatus.max() < EmailStatusCode.dnsWarning)
if (checkDNS == Yes.checkDns && returnStatus.maxElement() < EmailStatusCode.dnsWarning)
{
assert(false, "DNS check is currently not implemented");
}

if (!dnsChecked && returnStatus.max() < EmailStatusCode.dnsWarning)
if (!dnsChecked && returnStatus.maxElement() < EmailStatusCode.dnsWarning)
{
if (elementCount == 0)
returnStatus ~= EmailStatusCode.rfc5321TopLevelDomain;
Expand All @@ -745,7 +745,7 @@ EmailStatus isEmail (Char) (const(Char)[] email, CheckDns checkDNS = No.checkDns
}

returnStatus = array(uniq(returnStatus));
auto finalStatus = returnStatus.max();
auto finalStatus = returnStatus.maxElement();

if (returnStatus.length != 1)
returnStatus.popFront();
Expand Down Expand Up @@ -1743,34 +1743,6 @@ enum AsciiToken
delete_ = 127
}

/*
* Returns the maximum of the values in the given array.
*
* Params:
* arr = the array containing the values to return the maximum of
*
* Returns: the maximum value
*/
T max (T) (T[] arr)
{
static import std.algorithm.comparison;

auto max = arr.front;

foreach (i ; 0 .. arr.length - 1)
max = std.algorithm.comparison.max(max, arr[i + 1]);

return max;
}

///
unittest
{
assert([1, 2, 3, 4].max() == 4);
assert([3, 5, 9, 2, 5].max() == 9);
assert([7, 13, 9, 12, 0].max() == 13);
}

/*
* Returns the portion of string specified by the $(D_PARAM start) and
* $(D_PARAM length) parameters.
Expand Down Expand Up @@ -1846,7 +1818,6 @@ T[] substr (T) (T[] str, ptrdiff_t start = 0, ptrdiff_t length = ptrdiff_t.min)
return str[start .. end];
}

///
unittest
{
assert("abcdef".substr(-1) == "f");
Expand Down Expand Up @@ -1898,7 +1869,6 @@ int compareFirstN (alias pred = "a < b", S1, S2) (S1 s1, S2 s2, size_t length, b
return caseInsensitive ? slice1.icmp(slice2) : slice1.cmp(slice2);
}

///
unittest
{
assert("abc".compareFirstN("abcdef", 3) == 0);
Expand Down Expand Up @@ -1929,7 +1899,6 @@ auto grep (Range, Regex) (Range input, Regex pattern, bool invert = false)
return filter!(dg)(input);
}

///
unittest
{
import std.algorithm.comparison : equal;
Expand All @@ -1953,7 +1922,6 @@ ElementType!(A) pop (A) (ref A a) if (isDynamicArray!(A) && !isNarrowString!(A)
return e;
}

///
unittest
{
auto array = [0, 1, 2, 3];
Expand Down

0 comments on commit 602b23e

Please sign in to comment.