This commit is contained in:
Eugen Wissner 2018-04-01 10:34:18 +02:00
parent 9b1f72472f
commit a0ac8355f9
5 changed files with 128 additions and 132 deletions

View File

@ -279,7 +279,7 @@ struct Array(T)
} }
/// ///
@trusted @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v1 = Array!int([1, 2, 3]); auto v1 = Array!int([1, 2, 3]);
auto v2 = Array!int(v1); auto v2 = Array!int(v1);
@ -291,19 +291,6 @@ struct Array(T)
assert(v3.capacity == 3); assert(v3.capacity == 3);
} }
private @trusted @nogc unittest // const constructor tests
{
auto v1 = const Array!int([1, 2, 3]);
auto v2 = Array!int(v1);
assert(v1.data !is v2.data);
assert(v1 == v2);
auto v3 = const Array!int(Array!int([1, 2, 3]));
assert(v1 == v3);
assert(v3.length == 3);
assert(v3.capacity == 3);
}
/** /**
* Creates a new $(D_PSYMBOL Array). * Creates a new $(D_PSYMBOL Array).
* *
@ -339,7 +326,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([3, 8, 2]); auto v = Array!int([3, 8, 2]);
@ -349,7 +336,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int(3, 5); auto v = Array!int(3, 5);
@ -358,11 +345,6 @@ struct Array(T)
assert(v[0] == 5 && v[1] == 5 && v[2] == 5); assert(v[0] == 5 && v[1] == 5 && v[2] == 5);
} }
@safe unittest
{
auto v1 = Array!int(defaultAllocator);
}
/** /**
* Destroys this $(D_PSYMBOL Array). * Destroys this $(D_PSYMBOL Array).
*/ */
@ -392,7 +374,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([18, 20, 15]); auto v = Array!int([18, 20, 15]);
v.clear(); v.clear();
@ -409,7 +391,7 @@ struct Array(T)
} }
/// ///
@safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int(4); auto v = Array!int(4);
assert(v.capacity == 4); assert(v.capacity == 4);
@ -461,7 +443,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
Array!int v; Array!int v;
@ -529,7 +511,7 @@ struct Array(T)
} }
/// ///
@nogc @safe unittest @nogc nothrow pure @safe unittest
{ {
Array!int v; Array!int v;
assert(v.capacity == 0); assert(v.capacity == 0);
@ -564,7 +546,7 @@ struct Array(T)
} }
/// ///
@nogc @safe unittest @nogc nothrow pure @safe unittest
{ {
Array!int v; Array!int v;
assert(v.capacity == 0); assert(v.capacity == 0);
@ -629,7 +611,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5, 18, 17]); auto v = Array!int([5, 18, 17]);
@ -674,7 +656,7 @@ struct Array(T)
} }
/// ///
@safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5, 18, 17, 2, 4, 6, 1]); auto v = Array!int([5, 18, 17, 2, 4, 6, 1]);
@ -759,7 +741,7 @@ struct Array(T)
alias insert = insertBack; alias insert = insertBack;
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
struct TestRange struct TestRange
{ {
@ -927,7 +909,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
Array!int v1; Array!int v1;
v1.insertAfter(v1[], [2, 8]); v1.insertAfter(v1[], [2, 8]);
@ -963,7 +945,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
Array!int v1; Array!int v1;
v1.insertBefore(v1[], [2, 8]); v1.insertBefore(v1[], [2, 8]);
@ -1022,7 +1004,7 @@ struct Array(T)
} }
/// ///
nothrow @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
Array!int a = Array!int(1); Array!int a = Array!int(1);
a[0] = 5; a[0] = 5;
@ -1052,7 +1034,7 @@ struct Array(T)
} }
/// ///
@nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v1 = Array!int([12, 1, 7]); auto v1 = Array!int([12, 1, 7]);
@ -1101,7 +1083,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
const v1 = Array!int([6, 123, 34, 5]); const v1 = Array!int([6, 123, 34, 5]);
@ -1156,7 +1138,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
Array!int v1, v2; Array!int v1, v2;
assert(v1 == v2); assert(v1 == v2);
@ -1191,7 +1173,7 @@ struct Array(T)
} }
/// ///
@safe unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5]); auto v = Array!int([5]);
@ -1218,7 +1200,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5]); auto v = Array!int([5]);
@ -1263,16 +1245,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{
Array!int v;
auto r = v[];
assert(r.length == 0);
assert(r.empty);
}
///
unittest
{ {
auto v = Array!int([1, 2, 3]); auto v = Array!int([1, 2, 3]);
auto r = v[]; auto r = v[];
@ -1290,7 +1263,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([1, 2, 3, 4]); auto v = Array!int([1, 2, 3, 4]);
auto r = v[1 .. 4]; auto r = v[1 .. 4];
@ -1363,7 +1336,7 @@ struct Array(T)
} }
/// ///
@nogc @safe unittest @nogc nothrow pure @safe unittest
{ {
auto v1 = Array!int([3, 3, 3]); auto v1 = Array!int([3, 3, 3]);
auto v2 = Array!int([1, 2]); auto v2 = Array!int([1, 2]);
@ -1397,7 +1370,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([1, 2, 4]); auto v = Array!int([1, 2, 4]);
auto data = v.get(); auto data = v.get();
@ -1464,7 +1437,7 @@ struct Array(T)
} }
/// ///
@safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v1 = const Array!int([5, 15, 8]); auto v1 = const Array!int([5, 15, 8]);
Array!int v2; Array!int v2;
@ -1472,22 +1445,6 @@ struct Array(T)
assert(v1 == v2); assert(v1 == v2);
} }
///
@safe @nogc unittest
{
auto v1 = const Array!int([5, 15, 8]);
Array!int v2;
v2 = v1[0 .. 2];
assert(equal(v1[0 .. 2], v2[]));
}
// Move assignment.
private @safe @nogc unittest
{
Array!int v1;
v1 = Array!int([5, 15, 8]);
}
/** /**
* Assigns a static array. * Assigns a static array.
* *
@ -1503,7 +1460,7 @@ struct Array(T)
} }
/// ///
@safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v1 = Array!int([5, 15, 8]); auto v1 = Array!int([5, 15, 8]);
Array!int v2; Array!int v2;
@ -1516,7 +1473,7 @@ struct Array(T)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5, 15, 8]); auto v = Array!int([5, 15, 8]);
@ -1530,7 +1487,7 @@ unittest
assert(r.front == v.front); assert(r.front == v.front);
} }
@nogc unittest @nogc nothrow pure @safe unittest
{ {
const v1 = Array!int(); const v1 = Array!int();
const Array!int v2; const Array!int v2;
@ -1538,7 +1495,7 @@ unittest
static assert(is(PointerTarget!(typeof(v3.data)) == const(int))); static assert(is(PointerTarget!(typeof(v3.data)) == const(int)));
} }
@nogc unittest @nogc nothrow pure @safe unittest
{ {
// Test that const arrays return usable ranges. // Test that const arrays return usable ranges.
auto v = const Array!int([1, 2, 4]); auto v = const Array!int([1, 2, 4]);
@ -1559,7 +1516,7 @@ unittest
static assert(is(typeof(r2[]))); static assert(is(typeof(r2[])));
} }
@nogc unittest @nogc nothrow pure @safe unittest
{ {
Array!int v1; Array!int v1;
const Array!int v2; const Array!int v2;
@ -1581,18 +1538,18 @@ unittest
assert(!v1[].equal(v2[])); assert(!v1[].equal(v2[]));
} }
@nogc unittest @nogc nothrow pure @safe unittest
{ {
struct MutableEqualsStruct struct MutableEqualsStruct
{ {
int opEquals(typeof(this) that) @nogc int opEquals(typeof(this) that) @nogc nothrow pure @safe
{ {
return true; return true;
} }
} }
struct ConstEqualsStruct struct ConstEqualsStruct
{ {
int opEquals(const typeof(this) that) const @nogc int opEquals(const typeof(this) that) const @nogc nothrow pure @safe
{ {
return true; return true;
} }
@ -1619,18 +1576,18 @@ unittest
assert(v7[].equal(v8[])); assert(v7[].equal(v8[]));
} }
@nogc unittest @nogc nothrow pure @safe unittest
{ {
struct SWithDtor struct SWithDtor
{ {
~this() @nogc ~this() @nogc nothrow pure @safe
{ {
} }
} }
auto v = Array!SWithDtor(); // Destructor can destroy empty arrays. auto v = Array!SWithDtor(); // Destructor can destroy empty arrays.
} }
private unittest @nogc nothrow pure @safe unittest
{ {
class A class A
{ {
@ -1642,7 +1599,7 @@ private unittest
static assert(is(Array!(A*))); static assert(is(Array!(A*)));
} }
private @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto v = Array!int([5, 15, 8]); auto v = Array!int([5, 15, 8]);
{ {
@ -1670,3 +1627,45 @@ private @safe @nogc unittest
assert(i == 0); assert(i == 0);
} }
} }
// const constructor tests
@nogc nothrow pure @safe unittest
{
auto v1 = const Array!int([1, 2, 3]);
auto v2 = Array!int(v1);
assert(v1.data !is v2.data);
assert(v1 == v2);
auto v3 = const Array!int(Array!int([1, 2, 3]));
assert(v1 == v3);
assert(v3.length == 3);
assert(v3.capacity == 3);
}
@nogc nothrow pure @safe unittest
{
auto v1 = Array!int(defaultAllocator);
}
@nogc nothrow pure @safe unittest
{
Array!int v;
auto r = v[];
assert(r.length == 0);
assert(r.empty);
}
@nogc nothrow pure @safe unittest
{
auto v1 = const Array!int([5, 15, 8]);
Array!int v2;
v2 = v1[0 .. 2];
assert(equal(v1[0 .. 2], v2[]));
}
// Move assignment
@nogc nothrow pure @safe unittest
{
Array!int v1;
v1 = Array!int([5, 15, 8]);
}

View File

@ -120,7 +120,7 @@ struct ReadBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure @safe unittest
{ {
ReadBuffer!ubyte b; ReadBuffer!ubyte b;
assert(b.capacity == 0); assert(b.capacity == 0);
@ -165,7 +165,7 @@ struct ReadBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
ReadBuffer!ubyte b; ReadBuffer!ubyte b;
size_t numberRead; size_t numberRead;
@ -197,7 +197,7 @@ struct ReadBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
ReadBuffer!ubyte b; ReadBuffer!ubyte b;
size_t numberRead; size_t numberRead;
@ -272,7 +272,7 @@ struct ReadBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
ReadBuffer!ubyte b; ReadBuffer!ubyte b;
size_t numberRead; size_t numberRead;
@ -293,7 +293,7 @@ struct ReadBuffer(T = ubyte)
mixin DefaultAllocator; mixin DefaultAllocator;
} }
private unittest @nogc nothrow pure @safe unittest
{ {
static assert(is(ReadBuffer!int)); static assert(is(ReadBuffer!int));
} }
@ -399,7 +399,7 @@ struct WriteBuffer(T = ubyte)
alias opDollar = length; alias opDollar = length;
/// ///
unittest @nogc nothrow pure unittest
{ {
auto b = WriteBuffer!ubyte(4); auto b = WriteBuffer!ubyte(4);
ubyte[3] buf = [48, 23, 255]; ubyte[3] buf = [48, 23, 255];
@ -498,42 +498,6 @@ struct WriteBuffer(T = ubyte)
return this; return this;
} }
///
unittest
{
auto b = WriteBuffer!ubyte(4);
ubyte[3] buf = [48, 23, 255];
b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 48 && b.buffer_[1] == 23 && b.buffer_[2] == 255);
b += 2;
b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
&& b.buffer_[2] == 255 && b.buffer_[3] == 48);
b += 2;
b ~= buf;
assert(b.capacity == 8);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
&& b.buffer_[2] == 48 && b.buffer_[3] == 23 && b.buffer_[4] == 255);
}
///
unittest
{
auto b = WriteBuffer!ubyte(2);
ubyte[3] buf = [48, 23, 255];
b ~= buf;
assert(b.start == 0);
assert(b.capacity == 4);
assert(b.ring == 3);
assert(b.position == 3);
}
/** /**
* Sets how many bytes were written. It will shrink the buffer * Sets how many bytes were written. It will shrink the buffer
* appropriately. Always call it after $(D_PSYMBOL opIndex). * appropriately. Always call it after $(D_PSYMBOL opIndex).
@ -607,7 +571,7 @@ struct WriteBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
auto b = WriteBuffer!ubyte(6); auto b = WriteBuffer!ubyte(6);
ubyte[6] buf = [23, 23, 255, 128, 127, 9]; ubyte[6] buf = [23, 23, 255, 128, 127, 9];
@ -648,7 +612,7 @@ struct WriteBuffer(T = ubyte)
} }
/// ///
unittest @nogc nothrow pure unittest
{ {
auto b = WriteBuffer!ubyte(6); auto b = WriteBuffer!ubyte(6);
ubyte[6] buf = [23, 23, 255, 128, 127, 9]; ubyte[6] buf = [23, 23, 255, 128, 127, 9];
@ -686,7 +650,41 @@ struct WriteBuffer(T = ubyte)
mixin DefaultAllocator; mixin DefaultAllocator;
} }
private unittest @nogc nothrow pure @safe unittest
{ {
static assert(is(typeof(WriteBuffer!int(5)))); static assert(is(typeof(WriteBuffer!int(5))));
} }
@nogc nothrow pure unittest
{
auto b = WriteBuffer!ubyte(4);
ubyte[3] buf = [48, 23, 255];
b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 48 && b.buffer_[1] == 23 && b.buffer_[2] == 255);
b += 2;
b ~= buf;
assert(b.capacity == 4);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
&& b.buffer_[2] == 255 && b.buffer_[3] == 48);
b += 2;
b ~= buf;
assert(b.capacity == 8);
assert(b.buffer_[0] == 23 && b.buffer_[1] == 255
&& b.buffer_[2] == 48 && b.buffer_[3] == 23 && b.buffer_[4] == 255);
}
@nogc nothrow pure unittest
{
auto b = WriteBuffer!ubyte(2);
ubyte[3] buf = [48, 23, 255];
b ~= buf;
assert(b.start == 0);
assert(b.capacity == 4);
assert(b.ring == 3);
assert(b.position == 3);
}

View File

@ -5,7 +5,7 @@
/** /**
* Internet utilities. * Internet utilities.
* *
* Copyright: Eugene Wissner 2016-2017. * Copyright: Eugene Wissner 2016-2018.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
@ -170,7 +170,7 @@ struct NetworkOrder(uint L)
} }
/// ///
pure nothrow @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
auto networkOrder = NetworkOrder!3(0xae34e2u); auto networkOrder = NetworkOrder!3(0xae34e2u);
assert(!networkOrder.empty); assert(!networkOrder.empty);
@ -190,8 +190,8 @@ pure nothrow @safe @nogc unittest
assert(networkOrder.empty); assert(networkOrder.empty);
} }
// Static. // Static tests
private unittest @nogc nothrow pure @safe unittest
{ {
static assert(isBidirectionalRange!(NetworkOrder!4)); static assert(isBidirectionalRange!(NetworkOrder!4));
static assert(isBidirectionalRange!(NetworkOrder!8)); static assert(isBidirectionalRange!(NetworkOrder!8));
@ -238,7 +238,7 @@ T toHostOrder(T = size_t, R)(R range)
} }
/// ///
pure nothrow @safe @nogc unittest @nogc nothrow pure @safe unittest
{ {
const value = 0xae34e2u; const value = 0xae34e2u;
auto networkOrder = NetworkOrder!4(value); auto networkOrder = NetworkOrder!4(value);

View File

@ -5,7 +5,7 @@
/** /**
* Network programming. * Network programming.
* *
* Copyright: Eugene Wissner 2017. * Copyright: Eugene Wissner 2017-2018.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)

View File

@ -5,7 +5,7 @@
/** /**
* URL parser. * URL parser.
* *
* Copyright: Eugene Wissner 2017. * Copyright: Eugene Wissner 2017-2018.
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/, * License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
* Mozilla Public License, v. 2.0). * Mozilla Public License, v. 2.0).
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner) * Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
@ -460,7 +460,6 @@ struct URL
assertThrown!URIException(() => URL("http://blah.com:66000")); assertThrown!URIException(() => URL("http://blah.com:66000"));
} }
// Issue 254: https://issues.caraus.io/issues/254.
@nogc pure @system unittest @nogc pure @system unittest
{ {
auto u = URL("ftp://"); auto u = URL("ftp://");