net: Add missing public imports, move tests
This commit is contained in:
@ -19,16 +19,6 @@ import tanya.memory.lifetime;
|
||||
import tanya.meta.trait;
|
||||
import tanya.range;
|
||||
|
||||
version (unittest)
|
||||
{
|
||||
static struct Container
|
||||
{
|
||||
void insertBack(const(char)[])
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private mixin template InserterCtor()
|
||||
{
|
||||
private Container* container;
|
||||
@ -92,22 +82,6 @@ if (hasMember!(Container, "insertBack"))
|
||||
assert(container.element == 5);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
auto func()()
|
||||
{
|
||||
Container container;
|
||||
return backInserter(container);
|
||||
}
|
||||
static assert(!is(typeof(func!())));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Container container;
|
||||
static assert(isOutputRange!(typeof(backInserter(container)), string));
|
||||
}
|
||||
|
||||
/**
|
||||
* If $(D_PARAM container) is a container with `insertFront`-support,
|
||||
* $(D_PSYMBOL frontInserter) returns an output range that puts the elements
|
||||
|
@ -31,7 +31,7 @@
|
||||
* (D_INLINECODE dchar[])) are treated as any other normal array, they aren't
|
||||
* auto-decoded.
|
||||
*
|
||||
* Copyright: Eugene Wissner 2017-2018.
|
||||
* Copyright: Eugene Wissner 2017-2019.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||
* Mozilla Public License, v. 2.0).
|
||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||
|
@ -6,7 +6,7 @@
|
||||
* This package contains generic functions and templates to be used with D
|
||||
* ranges.
|
||||
*
|
||||
* Copyright: Eugene Wissner 2017-2018.
|
||||
* Copyright: Eugene Wissner 2017-2019.
|
||||
* License: $(LINK2 https://www.mozilla.org/en-US/MPL/2.0/,
|
||||
* Mozilla Public License, v. 2.0).
|
||||
* Authors: $(LINK2 mailto:info@caraus.de, Eugene Wissner)
|
||||
|
@ -20,19 +20,6 @@ import tanya.meta.trait;
|
||||
import tanya.meta.transform;
|
||||
import tanya.range.array;
|
||||
|
||||
version (unittest)
|
||||
{
|
||||
import tanya.test.stub;
|
||||
|
||||
private struct AssertPostblit
|
||||
{
|
||||
this(this) @nogc nothrow pure @safe
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element type of the range $(D_PARAM R).
|
||||
*
|
||||
@ -391,72 +378,6 @@ template isInputRange(R)
|
||||
static assert(!isInputRange!(void[]));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct Range1(T)
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
T empty() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
static assert(!isInputRange!(Range1!int));
|
||||
static assert(!isInputRange!(Range1!(const bool)));
|
||||
|
||||
static struct Range2
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
int popFront() @nogc nothrow pure @safe
|
||||
{
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
static assert(isInputRange!Range2);
|
||||
|
||||
static struct Range3
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
void front() @nogc nothrow pure @safe
|
||||
{
|
||||
}
|
||||
}
|
||||
static assert(!isInputRange!Range3);
|
||||
|
||||
static struct Range4
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
enum bool empty = false;
|
||||
}
|
||||
static assert(isInputRange!Range4);
|
||||
}
|
||||
|
||||
// Ranges with non-copyable elements can be input ranges
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@WithLvalueElements
|
||||
static struct R
|
||||
{
|
||||
mixin InputRangeStub!NonCopyable;
|
||||
}
|
||||
static assert(isInputRange!R);
|
||||
}
|
||||
|
||||
// Ranges with const non-copyable elements can be input ranges
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@WithLvalueElements
|
||||
static struct R
|
||||
{
|
||||
mixin InputRangeStub!(const(NonCopyable));
|
||||
}
|
||||
static assert(isInputRange!R);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM R) is a forward range.
|
||||
*
|
||||
@ -515,34 +436,6 @@ template isForwardRange(R)
|
||||
static assert(!isForwardRange!(void[]));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct Range1
|
||||
{
|
||||
}
|
||||
static struct Range2
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
Range1 save() @nogc nothrow pure @safe
|
||||
{
|
||||
return Range1();
|
||||
}
|
||||
}
|
||||
static assert(!isForwardRange!Range2);
|
||||
|
||||
static struct Range3
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
const(typeof(this)) save() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
static assert(!isForwardRange!Range3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM R) is a bidirectional range.
|
||||
*
|
||||
@ -613,37 +506,6 @@ template isBidirectionalRange(R)
|
||||
static assert(!isBidirectionalRange!(void[]));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct Range(T, U)
|
||||
{
|
||||
mixin BidirectionalRangeStub;
|
||||
|
||||
@property T front() @nogc nothrow pure @safe
|
||||
{
|
||||
return T.init;
|
||||
}
|
||||
|
||||
@property U back() @nogc nothrow pure @safe
|
||||
{
|
||||
return U.init;
|
||||
}
|
||||
}
|
||||
static assert(!isBidirectionalRange!(Range!(int, uint)));
|
||||
static assert(!isBidirectionalRange!(Range!(int, const int)));
|
||||
}
|
||||
|
||||
// Ranges with non-copyable elements can be bidirectional ranges
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@WithLvalueElements
|
||||
static struct R
|
||||
{
|
||||
mixin BidirectionalRangeStub!NonCopyable;
|
||||
}
|
||||
static assert(isBidirectionalRange!R);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PARAM R) is a random-access range.
|
||||
*
|
||||
@ -735,66 +597,6 @@ template isRandomAccessRange(R)
|
||||
static assert(isRandomAccessRange!B);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct Range1
|
||||
{
|
||||
mixin BidirectionalRangeStub;
|
||||
mixin RandomAccessRangeStub;
|
||||
}
|
||||
static assert(!isRandomAccessRange!Range1);
|
||||
|
||||
@Length
|
||||
static struct Range2(Args...)
|
||||
{
|
||||
mixin BidirectionalRangeStub;
|
||||
|
||||
int opIndex(Args) @nogc nothrow pure @safe
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static assert(isRandomAccessRange!(Range2!size_t));
|
||||
static assert(!isRandomAccessRange!(Range2!()));
|
||||
static assert(!isRandomAccessRange!(Range2!(size_t, size_t)));
|
||||
|
||||
@Length
|
||||
static struct Range3
|
||||
{
|
||||
mixin BidirectionalRangeStub;
|
||||
|
||||
int opIndex(const size_t pos1, const size_t pos2 = 0)
|
||||
@nogc nothrow pure @safe
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static assert(isRandomAccessRange!Range3);
|
||||
|
||||
static struct Range4
|
||||
{
|
||||
mixin BidirectionalRangeStub;
|
||||
mixin RandomAccessRangeStub;
|
||||
|
||||
size_t opDollar() const @nogc nothrow pure @safe
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static assert(!isRandomAccessRange!Range4);
|
||||
}
|
||||
|
||||
// Ranges with non-copyable elements can be random-access ranges
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@WithLvalueElements @Infinite
|
||||
static struct R
|
||||
{
|
||||
mixin RandomAccessRangeStub!NonCopyable;
|
||||
}
|
||||
static assert(isRandomAccessRange!R);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts $(D_PARAM e) into the $(D_PARAM range).
|
||||
*
|
||||
@ -1052,27 +854,6 @@ template isInfinite(R)
|
||||
static assert(!isInfinite!InputRange);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@Infinite
|
||||
static struct StaticConstRange
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
static bool empty = false;
|
||||
}
|
||||
static assert(!isInfinite!StaticConstRange);
|
||||
|
||||
@Infinite
|
||||
static struct TrueRange
|
||||
{
|
||||
mixin InputRangeStub;
|
||||
|
||||
static const bool empty = true;
|
||||
}
|
||||
static assert(!isInfinite!TrueRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes exactly $(D_PARAM count) first elements from the input range
|
||||
* $(D_PARAM range).
|
||||
@ -1295,109 +1076,6 @@ if (isBidirectionalRange!R)
|
||||
assert(slice.length == 0);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
@Infinite
|
||||
static struct InfiniteRange
|
||||
{
|
||||
mixin ForwardRangeStub;
|
||||
private int i;
|
||||
|
||||
void popFront() @nogc nothrow pure @safe
|
||||
{
|
||||
++this.i;
|
||||
}
|
||||
|
||||
void popBack() @nogc nothrow pure @safe
|
||||
{
|
||||
--this.i;
|
||||
}
|
||||
|
||||
@property int front() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this.i;
|
||||
}
|
||||
|
||||
@property int back() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this.i;
|
||||
}
|
||||
}
|
||||
{
|
||||
InfiniteRange range;
|
||||
popFrontExactly(range, 2);
|
||||
assert(range.front == 2);
|
||||
popFrontN(range, 2);
|
||||
assert(range.front == 4);
|
||||
}
|
||||
{
|
||||
InfiniteRange range;
|
||||
popBackExactly(range, 2);
|
||||
assert(range.back == -2);
|
||||
popBackN(range, 2);
|
||||
assert(range.back == -4);
|
||||
}
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static struct Range
|
||||
{
|
||||
private int[5] a = [1, 2, 3, 4, 5];
|
||||
private size_t begin = 0, end = 5;
|
||||
|
||||
Range save() @nogc nothrow pure @safe
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void popFront() @nogc nothrow pure @safe
|
||||
{
|
||||
++this.begin;
|
||||
}
|
||||
|
||||
void popBack() @nogc nothrow pure @safe
|
||||
{
|
||||
--this.end;
|
||||
}
|
||||
|
||||
@property int front() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this.a[this.begin];
|
||||
}
|
||||
|
||||
@property int back() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this.a[this.end - 1];
|
||||
}
|
||||
|
||||
@property bool empty() const @nogc nothrow pure @safe
|
||||
{
|
||||
return this.begin >= this.end;
|
||||
}
|
||||
}
|
||||
{
|
||||
Range range;
|
||||
|
||||
popFrontN(range, 3);
|
||||
assert(range.front == 4);
|
||||
assert(range.back == 5);
|
||||
|
||||
popFrontN(range, 20);
|
||||
assert(range.empty);
|
||||
}
|
||||
{
|
||||
Range range;
|
||||
|
||||
popBackN(range, 3);
|
||||
assert(range.front == 1);
|
||||
assert(range.back == 2);
|
||||
|
||||
popBackN(range, 20);
|
||||
assert(range.empty);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the front element of an input range.
|
||||
*
|
||||
@ -1439,25 +1117,6 @@ if (isInputRange!R)
|
||||
assert(moveFront(a[]) == 5);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
// Returns its elements by reference.
|
||||
@Infinite @WithLvalueElements
|
||||
static struct R1
|
||||
{
|
||||
mixin InputRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(is(typeof(moveFront(R1()))));
|
||||
|
||||
// Returns elements with a postblit constructor by value. moveFront fails.
|
||||
@Infinite
|
||||
static struct R2
|
||||
{
|
||||
mixin InputRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(!is(typeof(moveFront(R2()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the back element of a bidirectional range.
|
||||
*
|
||||
@ -1499,25 +1158,6 @@ if (isBidirectionalRange!R)
|
||||
assert(moveBack(a[]) == 5);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
// Returns its elements by reference.
|
||||
@Infinite @WithLvalueElements
|
||||
static struct R1
|
||||
{
|
||||
mixin BidirectionalRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(is(typeof(moveBack(R1()))));
|
||||
|
||||
// Returns elements with a postblit constructor by value. moveBack fails.
|
||||
@Infinite
|
||||
static struct R2
|
||||
{
|
||||
mixin BidirectionalRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(!is(typeof(moveBack(R2()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the element at the position $(D_PARAM n) out of the range.
|
||||
*
|
||||
@ -1558,25 +1198,6 @@ if (isRandomAccessRange!R)
|
||||
assert(moveAt(a[], 1) == 5);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
// Returns its elements by reference.
|
||||
@Infinite @WithLvalueElements
|
||||
static struct R1
|
||||
{
|
||||
mixin RandomAccessRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(is(typeof(moveAt(R1(), 0))));
|
||||
|
||||
// Returns elements with a postblit constructor by value. moveAt fails.
|
||||
@Infinite
|
||||
static struct R2
|
||||
{
|
||||
mixin RandomAccessRangeStub!AssertPostblit;
|
||||
}
|
||||
static assert(!is(typeof(moveAt(R2(), 0))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether $(D_PSYMBOL R) is a range containing mobile elements,
|
||||
* i.e. elements that can be moved out of the range.
|
||||
@ -1731,12 +1352,6 @@ template hasLvalueElements(R)
|
||||
static assert(hasLvalueElements!R2);
|
||||
}
|
||||
|
||||
// Works with non-copyable elements
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(hasLvalueElements!(NonCopyable[]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the elements of $(D_PARAM R) are assignable.
|
||||
*
|
||||
|
Reference in New Issue
Block a user