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

Commit

Permalink
simpler unittest with basic usage
Browse files Browse the repository at this point in the history
  • Loading branch information
monarchdodra committed Jul 8, 2013
1 parent 0e41c43 commit 8429e65
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/object_.d
Expand Up @@ -2616,11 +2616,17 @@ T[] assumeSafeAppend(T)(T[] arr)
unittest
{
int[] a = [1, 2, 3, 4];
int[] b = a[1 .. $ - 1];
assert(a.capacity >= 4);
assert(b.capacity == 0);
b.assumeSafeAppend();
assert(b.capacity >= 3);

//Without assumeSafeAppend. Appending relocates.
int[] b = a [0 .. 3];
b ~= 5;
assert(a.ptr != b.ptr);

//With assumeSafeAppend. Appending overwrites.
int[] c = a [0 .. 3];
c.assumeSafeAppend();
c ~= 5;
assert(a.ptr == c.ptr);
}

unittest
Expand Down

0 comments on commit 8429e65

Please sign in to comment.