vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 5e95d1184b395faa46884b28567fcf62baf9ae5c
parent 4650c731b7fec09b3bbfbc12137fdf9549077018
Author: Marc André Tanner <mat@brain-dump.org>
Date: Fri, 23 Oct 2020 11:16:51 +0200
test/core: add basic array_{peek,pop} test
Diffstat:
| M | core/array-test.c | | | 9 | +++++++-- |
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/core/array-test.c b/core/array-test.c @@ -26,6 +26,8 @@ static void test_small_objects(void) { ok(array_length(&arr) == 0, "Initialization"); ok(!array_set(&arr, 0, NULL) && errno == EINVAL, "Set with invalid index"); ok(array_get(&arr, 0) == NULL && errno == EINVAL, "Get with invalid index"); + ok(array_peek(&arr) == NULL && array_length(&arr) == 0, "Peek empty array"); + ok(array_pop(&arr) == NULL && array_length(&arr) == 0, "Pop empty array"); for (size_t i = 0; i < len; i++) { int *v; @@ -46,6 +48,11 @@ static void test_small_objects(void) { "Get array element: %zu = %d", i, *v); } + int *v; + ok((v = array_peek(&arr)) && *v == values[0] && array_length(&arr) == len, "Peek populated array"); + ok((v = array_pop(&arr)) && *v == values[0] && array_length(&arr) == len-1, "Pop populated array"); + ok((v = array_peek(&arr)) && *v == values[1] && array_length(&arr) == len-1, "Peek after pop"); + array_clear(&arr); ok(array_length(&arr) == 0 && array_get(&arr, 0) == NULL && errno == EINVAL, "Clear"); @@ -63,8 +70,6 @@ static void test_small_objects(void) { ok(!array_remove(&arr, array_length(&arr)) && errno == EINVAL, "Remove past end of array"); - int *v; - size_t len_before = array_length(&arr); ok(array_remove(&arr, 2) && array_length(&arr) == len_before-1 && (v = array_get(&arr, 0)) && *v == values[0] &&