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

Commit

Permalink
DRY up the unittest.
Browse files Browse the repository at this point in the history
  • Loading branch information
H. S. Teoh committed Aug 14, 2014
1 parent 36736e4 commit af3d9ec
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/object_.d
Expand Up @@ -2307,33 +2307,25 @@ pure nothrow unittest
// bug 11761: test forward range functionality
auto aa = ["a": 1];

void testFwdRange(R, T)(R fwdRange, T testValue)
{
auto keys = aa.byKey;
assert(!keys.empty);
assert(keys.front == "a");
static assert(is(typeof(keys.save) == typeof(keys)));
auto saved = keys.save;
keys.popFront();
assert(keys.empty);
assert(!saved.empty);
assert(saved.front == "a");
saved.popFront();
assert(saved.empty);
}
assert(!fwdRange.empty);
assert(fwdRange.front == testValue);
static assert(is(typeof(fwdRange.save) == typeof(fwdRange)));

auto saved = fwdRange.save;
fwdRange.popFront();
assert(fwdRange.empty);

{
auto values = aa.byValue;
assert(!values.empty);
assert(values.front == 1);
static assert(is(typeof(values.save) == typeof(values)));
auto saved = values.save;
values.popFront();
assert(values.empty);
assert(!saved.empty);
assert(saved.front == 1);
assert(saved.front == testValue);
saved.popFront();
assert(saved.empty);
}

testFwdRange(aa.byKey, "a");
testFwdRange(aa.byValue, 1);
//testFwdRange(aa.byPair, tuple("a", 1));
}

deprecated("Please use destroy instead of clear.")
Expand Down

0 comments on commit af3d9ec

Please sign in to comment.