[iter] fix forward implementation in hb_concat().

Add test coverage for forward.
This commit is contained in:
Garret Rieger 2021-11-30 16:02:05 -08:00 committed by Behdad Esfahbod
parent 39e76af19e
commit 2e935514d9
2 changed files with 26 additions and 2 deletions

View File

@ -627,10 +627,12 @@ struct hb_concat_iter_t :
void __forward__ (unsigned n)
{
if (n > a.len ()) {
a.__forward__ (a.len ());
n -= a.len ();
a.__forward__ (a.len ());
b.__forward__ (n);
} else {
a.__forward__ (n);
}
b.__forward (n);
}
hb_concat_iter_t __end__ () const { return hb_concat_iter_t (a.end (), b.end ()); }

View File

@ -132,8 +132,11 @@ static void test_concat ()
hb_vector_t<int> d = {1, 2, 3, 4, 5};
auto it1 = hb_concat (a, b);
assert (it1.len () == 5);
auto it2 = hb_concat (c, d);
assert (it2.len () == 5);
auto it3 = hb_concat (d, c);
assert (it3.len () == 5);
for (int i = 0; i < 5; i++) {
assert(it1[i] == i + 1);
assert(it2[i] == i + 1);
@ -143,6 +146,25 @@ static void test_concat ()
check_sequential (it1);
check_sequential (it2);
check_sequential (it3);
auto it4 = +it1;
it4 += 2;
assert (*it4 == 3);
assert (it4);
assert (it4.len () == 3);
it4 += 2;
assert (*it4 == 5);
assert (it4);
assert (it4.len () == 1);
it4++;
assert (!it4);
assert (it4.len () == 0);
auto it5 = +it1;
it5 += 3;
assert (*it5 == 4);
}
int