Replace Option with Nullable
This commit is contained in:
@ -9,17 +9,17 @@ import tanya.range;
|
||||
// Rejects malformed addresses
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
assert(address4("256.0.0.1").isNothing);
|
||||
assert(address4(".0.0.1").isNothing);
|
||||
assert(address4("0..0.1").isNothing);
|
||||
assert(address4("0.0.0.").isNothing);
|
||||
assert(address4("0.0.").isNothing);
|
||||
assert(address4("").isNothing);
|
||||
assert(address4("256.0.0.1").isNull);
|
||||
assert(address4(".0.0.1").isNull);
|
||||
assert(address4("0..0.1").isNull);
|
||||
assert(address4("0.0.0.").isNull);
|
||||
assert(address4("0.0.").isNull);
|
||||
assert(address4("").isNull);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
assert(address4(cast(ubyte[]) []).isNothing);
|
||||
assert(address4(cast(ubyte[]) []).isNull);
|
||||
}
|
||||
|
||||
// Assignment and comparison works
|
||||
@ -106,12 +106,12 @@ import tanya.range;
|
||||
// Rejects malformed addresses
|
||||
@nogc nothrow @safe unittest
|
||||
{
|
||||
assert(address6("").isNothing);
|
||||
assert(address6(":").isNothing);
|
||||
assert(address6(":a").isNothing);
|
||||
assert(address6("a:").isNothing);
|
||||
assert(address6("1:2:3:4::6:").isNothing);
|
||||
assert(address6("fe80:2:3:4::6:7:8%").isNothing);
|
||||
assert(address6("").isNull);
|
||||
assert(address6(":").isNull);
|
||||
assert(address6(":a").isNull);
|
||||
assert(address6("a:").isNull);
|
||||
assert(address6("1:2:3:4::6:").isNull);
|
||||
assert(address6("fe80:2:3:4::6:7:8%").isNull);
|
||||
}
|
||||
|
||||
// Parses embedded IPv4 address
|
||||
@ -138,9 +138,9 @@ import tanya.range;
|
||||
|
||||
@nogc nothrow @safe unittest
|
||||
{
|
||||
assert(address6("0:0:0:0:0:0:1.2.3.").isNothing);
|
||||
assert(address6("0:0:0:0:0:0:1.2:3.4").isNothing);
|
||||
assert(address6("0:0:0:0:0:0:1.2.3.4.").isNothing);
|
||||
assert(address6("0:0:0:0:0:0:1.2.3.").isNull);
|
||||
assert(address6("0:0:0:0:0:0:1.2:3.4").isNull);
|
||||
assert(address6("0:0:0:0:0:0:1.2.3.4.").isNull);
|
||||
assert(address6("fe80:0:0:0:0:0:1.2.3.4%1").get.scopeID == 1);
|
||||
}
|
||||
|
||||
|
@ -22,120 +22,6 @@ import tanya.typecons;
|
||||
static assert(!is(Tuple!(int, "first", double, "second", char, "third")));
|
||||
}
|
||||
|
||||
// Assigns a new value
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Option!int option = 5;
|
||||
option = 8;
|
||||
assert(!option.isNothing);
|
||||
assert(option == 8);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Option!int option;
|
||||
const int newValue = 8;
|
||||
assert(option.isNothing);
|
||||
option = newValue;
|
||||
assert(!option.isNothing);
|
||||
assert(option == newValue);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Option!int option1;
|
||||
Option!int option2 = 5;
|
||||
assert(option1.isNothing);
|
||||
option1 = option2;
|
||||
assert(!option1.isNothing);
|
||||
assert(option1.get == 5);
|
||||
}
|
||||
|
||||
// Constructs with a value passed by reference
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
int i = 5;
|
||||
assert(Option!int(i).get == 5);
|
||||
}
|
||||
|
||||
// Moving
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
static assert(is(typeof(Option!NonCopyable(NonCopyable()))));
|
||||
// The value cannot be returned by reference because the default value
|
||||
// isn't passed by reference
|
||||
static assert(!is(typeof(Option!DisabledPostblit().or(NonCopyable()))));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
NonCopyable notCopyable;
|
||||
static assert(is(typeof(Option!NonCopyable().or(notCopyable))));
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Option!NonCopyable option;
|
||||
assert(option.isNothing);
|
||||
option = NonCopyable();
|
||||
assert(!option.isNothing);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Option!NonCopyable option;
|
||||
assert(option.isNothing);
|
||||
option = Option!NonCopyable(NonCopyable());
|
||||
assert(!option.isNothing);
|
||||
}
|
||||
|
||||
// Cast to bool is done before touching the encapsulated value
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
assert(Option!bool(false));
|
||||
}
|
||||
|
||||
// Option can be const
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
assert((const Option!int(5)).get == 5);
|
||||
assert((const Option!int()).or(5) == 5);
|
||||
}
|
||||
|
||||
// Equality
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
assert(Option!int() == Option!int());
|
||||
assert(Option!int(0) != Option!int());
|
||||
assert(Option!int(5) == Option!int(5));
|
||||
assert(Option!int(5) == 5);
|
||||
assert(Option!int(5) == cast(ubyte) 5);
|
||||
}
|
||||
|
||||
// Returns default value
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
int i = 5;
|
||||
assert(((ref e) => e)(Option!int().or(i)) == 5);
|
||||
}
|
||||
|
||||
// Implements toHash() for nothing
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
alias OptionT = Option!Hashable;
|
||||
assert(OptionT().toHash() == 0U);
|
||||
assert(OptionT(Hashable(1U)).toHash() == 1U);
|
||||
}
|
||||
|
||||
// Can assign Option that is nothing
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
auto option1 = Option!int(5);
|
||||
Option!int option2;
|
||||
option1 = option2;
|
||||
assert(option1.isNothing);
|
||||
}
|
||||
|
||||
@nogc nothrow pure @safe unittest
|
||||
{
|
||||
Variant!(int, double) variant;
|
||||
|
Reference in New Issue
Block a user