Skip to content

Commit

Permalink
Position unittests just after emplace they test
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-sh committed Oct 27, 2012
1 parent 77b3c44 commit 6147510
Showing 1 changed file with 60 additions and 56 deletions.
116 changes: 60 additions & 56 deletions std/conv.d
Expand Up @@ -3437,6 +3437,34 @@ T* emplace(T, Args...)(T* chunk, Args args)
return chunk;
}

unittest
{
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
int a;
int b = 42;
assert(*emplace!int(&a, b) == 42);
}

unittest
{
interface I {}
class K : I {}

K k = void;
emplace!K(&k);
assert(k is null);
K k2 = new K;
assert(k2 !is null);
emplace!K(&k, k2);
assert(k is k2);

I i = void;
emplace!I(&i);
assert(i is null);
emplace!I(&i, k);
assert(i is k);
}

// Specialization for struct
T* emplace(T, Args...)(T* chunk, Args args)
if (is(T == struct))
Expand Down Expand Up @@ -3472,6 +3500,38 @@ T* emplace(T, Args...)(T* chunk, Args args)
return result;
}

unittest
{
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
struct S
{
double x = 5, y = 6;
this(int a, int b)
{
assert(x == 5 && y == 6);
x = a;
y = b;
}
}

auto s1 = new void[S.sizeof];
auto s2 = S(42, 43);
assert(*emplace!S(cast(S*) s1.ptr, s2) == s2);
assert(*emplace!S(cast(S*) s1, 44, 45) == S(44, 45));
}

unittest
{
struct Foo
{
uint num;
}

Foo foo;
emplace!Foo(&foo, 2U);
assert(foo.num == 2);
}

/**
Given a raw memory area $(D chunk), constructs an object of $(D class)
type $(D T) at that address. The constructor is passed the arguments
Expand Down Expand Up @@ -3550,30 +3610,6 @@ unittest
assert(s1.a == 42 && s1.b == 43);
}

unittest
{
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
int a;
int b = 42;
assert(*emplace!int(&a, b) == 42);

struct S
{
double x = 5, y = 6;
this(int a, int b)
{
assert(x == 5 && y == 6);
x = a;
y = b;
}
}

auto s1 = new void[S.sizeof];
auto s2 = S(42, 43);
assert(*emplace!S(cast(S*) s1.ptr, s2) == s2);
assert(*emplace!S(cast(S*) s1, 44, 45) == S(44, 45));
}

unittest
{
debug(conv) scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " succeeded.");
Expand Down Expand Up @@ -3610,38 +3646,6 @@ unittest
assert(equal(map!(to!int)(["42", "34", "345"]), [42, 34, 345]));
}

unittest
{
struct Foo
{
uint num;
}

Foo foo;
emplace!Foo(&foo, 2U);
assert(foo.num == 2);
}

unittest
{
interface I {}
class K : I {}

K k = void;
emplace!K(&k);
assert(k is null);
K k2 = new K;
assert(k2 !is null);
emplace!K(&k, k2);
assert(k is k2);

I i = void;
emplace!I(&i);
assert(i is null);
emplace!I(&i, k);
assert(i is k);
}

// Undocumented for the time being
void toTextRange(T, W)(T value, W writer)
if (isIntegral!T && isOutputRange!(W, char))
Expand Down

0 comments on commit 6147510

Please sign in to comment.