Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
check postblit for array of const struct
Browse files Browse the repository at this point in the history
  • Loading branch information
rainers authored and Orvid committed Dec 12, 2014
1 parent 391a491 commit ac403db
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -2543,44 +2543,49 @@ unittest
++x;
}
}
auto sarr = new S[1];
debug(SENTINEL) {} else
assert(sarr.capacity == 1);

// length extend
auto sarr2 = sarr;
assert(sarr[0].x == 0);
sarr2.length += 1;
assert(sarr2[0].x == 1);
assert(sarr[0].x == 0);

// append
S s;
sarr2 = sarr;
sarr2 ~= s;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr[0].x == 0);
assert(s.x == 0);

// concat
sarr2 = sarr ~ sarr;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr[0].x == 0);

// concat multiple (calls different method)
sarr2 = sarr ~ sarr ~ sarr;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr2[2].x == 1);
assert(sarr[0].x == 0);

// reserve capacity
sarr2 = sarr;
sarr2.reserve(2);
assert(sarr2[0].x == 1);
assert(sarr[0].x == 0);
void testPostBlit(T)()
{
auto sarr = new T[1];
debug(SENTINEL) {} else
assert(sarr.capacity == 1);

// length extend
auto sarr2 = sarr;
assert(sarr[0].x == 0);
sarr2.length += 1;
assert(sarr2[0].x == 1);
assert(sarr[0].x == 0);

// append
T s;
sarr2 = sarr;
sarr2 ~= s;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr[0].x == 0);
assert(s.x == 0);

// concat
sarr2 = sarr ~ sarr;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr[0].x == 0);

// concat multiple (calls different method)
sarr2 = sarr ~ sarr ~ sarr;
assert(sarr2[0].x == 1);
assert(sarr2[1].x == 1);
assert(sarr2[2].x == 1);
assert(sarr[0].x == 0);

// reserve capacity
sarr2 = sarr;
sarr2.reserve(2);
assert(sarr2[0].x == 1);
assert(sarr[0].x == 0);
}
testPostBlit!(S)();
testPostBlit!(const(S))();
}

// cannot define structs inside unit test block, or they become nested structs.
Expand Down

0 comments on commit ac403db

Please sign in to comment.