basic: Use statement expressions more in list.h
Let's use statement expressions to return values instead of passing in return arguments to the LIST macros.
This commit is contained in:
+25
-26
@@ -19,7 +19,7 @@ int main(int argc, const char *argv[]) {
|
||||
for (i = 0; i < ELEMENTSOF(items); i++) {
|
||||
LIST_INIT(item_list, &items[i]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[i]));
|
||||
LIST_PREPEND(item_list, head, &items[i]);
|
||||
assert_se(LIST_PREPEND(item_list, head, &items[i]) == &items[i]);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
@@ -55,14 +55,13 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
list_item *cursor;
|
||||
LIST_FIND_HEAD(item_list, &items[0], cursor);
|
||||
list_item *cursor = LIST_FIND_HEAD(item_list, &items[0]);
|
||||
assert_se(cursor == &items[3]);
|
||||
|
||||
LIST_FIND_TAIL(item_list, &items[3], cursor);
|
||||
cursor = LIST_FIND_TAIL(item_list, &items[3]);
|
||||
assert_se(cursor == &items[0]);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[1]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[1]) == &items[1]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[1]));
|
||||
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
@@ -73,7 +72,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_INSERT_AFTER(item_list, head, &items[3], &items[1]);
|
||||
assert_se(LIST_INSERT_AFTER(item_list, head, &items[3], &items[1]) == &items[1]);
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
assert_se(items[2].item_list_next == &items[0]);
|
||||
assert_se(items[1].item_list_next == &items[2]);
|
||||
@@ -84,7 +83,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[1]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[1]) == &items[1]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[1]));
|
||||
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
@@ -95,7 +94,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_INSERT_BEFORE(item_list, head, &items[2], &items[1]);
|
||||
assert_se(LIST_INSERT_BEFORE(item_list, head, &items[2], &items[1]) == &items[1]);
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
assert_se(items[2].item_list_next == &items[0]);
|
||||
assert_se(items[1].item_list_next == &items[2]);
|
||||
@@ -106,7 +105,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[0]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[0]) == &items[0]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[0]));
|
||||
|
||||
assert_se(items[2].item_list_next == NULL);
|
||||
@@ -117,7 +116,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_INSERT_BEFORE(item_list, head, &items[3], &items[0]);
|
||||
assert_se(LIST_INSERT_BEFORE(item_list, head, &items[3], &items[0]) == &items[0]);
|
||||
assert_se(items[2].item_list_next == NULL);
|
||||
assert_se(items[1].item_list_next == &items[2]);
|
||||
assert_se(items[3].item_list_next == &items[1]);
|
||||
@@ -129,7 +128,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[0].item_list_prev == NULL);
|
||||
assert_se(head == &items[0]);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[0]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[0]) == &items[0]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[0]));
|
||||
|
||||
assert_se(items[2].item_list_next == NULL);
|
||||
@@ -140,7 +139,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_INSERT_BEFORE(item_list, head, NULL, &items[0]);
|
||||
assert_se(LIST_INSERT_BEFORE(item_list, head, NULL, &items[0]) == &items[0]);
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
assert_se(items[2].item_list_next == &items[0]);
|
||||
assert_se(items[1].item_list_next == &items[2]);
|
||||
@@ -151,7 +150,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[0]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[0]) == &items[0]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[0]));
|
||||
|
||||
assert_se(items[2].item_list_next == NULL);
|
||||
@@ -162,7 +161,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[1].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[1]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[1]) == &items[1]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[1]));
|
||||
|
||||
assert_se(items[2].item_list_next == NULL);
|
||||
@@ -171,18 +170,18 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[2]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[2]) == &items[2]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[2]));
|
||||
assert_se(LIST_JUST_US(item_list, head));
|
||||
|
||||
LIST_REMOVE(item_list, head, &items[3]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[3]) == &items[3]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[3]));
|
||||
|
||||
assert_se(head == NULL);
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(items); i++) {
|
||||
assert_se(LIST_JUST_US(item_list, &items[i]));
|
||||
LIST_APPEND(item_list, head, &items[i]);
|
||||
assert_se(LIST_APPEND(item_list, head, &items[i]) == &items[i]);
|
||||
}
|
||||
|
||||
assert_se(!LIST_JUST_US(item_list, head));
|
||||
@@ -198,20 +197,20 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[3].item_list_prev == &items[2]);
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(items); i++)
|
||||
LIST_REMOVE(item_list, head, &items[i]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[i]) == &items[i]);
|
||||
|
||||
assert_se(head == NULL);
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(items) / 2; i++) {
|
||||
LIST_INIT(item_list, &items[i]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[i]));
|
||||
LIST_PREPEND(item_list, head, &items[i]);
|
||||
assert_se(LIST_PREPEND(item_list, head, &items[i]) == &items[i]);
|
||||
}
|
||||
|
||||
for (i = ELEMENTSOF(items) / 2; i < ELEMENTSOF(items); i++) {
|
||||
LIST_INIT(item_list, &items[i]);
|
||||
assert_se(LIST_JUST_US(item_list, &items[i]));
|
||||
LIST_PREPEND(item_list, head2, &items[i]);
|
||||
assert_se(LIST_PREPEND(item_list, head2, &items[i]) == &items[i]);
|
||||
}
|
||||
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
@@ -224,7 +223,7 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_JOIN(item_list, head2, head);
|
||||
assert_se(LIST_JOIN(item_list, head2, head) == head2);
|
||||
assert_se(head == NULL);
|
||||
|
||||
assert_se(items[0].item_list_next == NULL);
|
||||
@@ -237,18 +236,18 @@ int main(int argc, const char *argv[]) {
|
||||
assert_se(items[2].item_list_prev == &items[3]);
|
||||
assert_se(items[3].item_list_prev == NULL);
|
||||
|
||||
LIST_JOIN(item_list, head, head2);
|
||||
assert_se(LIST_JOIN(item_list, head, head2) == head);
|
||||
assert_se(head2 == NULL);
|
||||
assert_se(head);
|
||||
|
||||
for (i = 0; i < ELEMENTSOF(items); i++)
|
||||
LIST_REMOVE(item_list, head, &items[i]);
|
||||
assert_se(LIST_REMOVE(item_list, head, &items[i]) == &items[i]);
|
||||
|
||||
assert_se(head == NULL);
|
||||
|
||||
LIST_PREPEND(item_list, head, items + 0);
|
||||
LIST_PREPEND(item_list, head, items + 1);
|
||||
LIST_PREPEND(item_list, head, items + 2);
|
||||
assert_se(LIST_PREPEND(item_list, head, items + 0) == items + 0);
|
||||
assert_se(LIST_PREPEND(item_list, head, items + 1) == items + 1);
|
||||
assert_se(LIST_PREPEND(item_list, head, items + 2) == items + 2);
|
||||
|
||||
assert_se(LIST_POP(item_list, head) == items + 2);
|
||||
assert_se(LIST_POP(item_list, head) == items + 1);
|
||||
|
||||
Reference in New Issue
Block a user