[PATCH 1/3] stailq: add stailq_insert function

Vladimir Davydov vdavydov.dev at gmail.com
Sun Jul 15 16:17:11 MSK 2018


On Sun, Jul 15, 2018 at 10:02:44AM +0300, Konstantin Osipov wrote:
> * Vladimir Davydov <vdavydov.dev at gmail.com> [18/07/13 17:22]:
> > The new function inserts a new item into the list at the specified
> > postion.
> > ---
> >  src/lib/salad/stailq.h | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> > 
> 
> Please add a unit test.

Done (amended the commit on the branch). The diff is below.

diff --git a/test/unit/stailq.c b/test/unit/stailq.c
index 12f05a0c..600f71a5 100644
--- a/test/unit/stailq.c
+++ b/test/unit/stailq.c
@@ -3,7 +3,7 @@
 #include <stdarg.h>
 #include "unit.h"
 
-#define PLAN		68
+#define PLAN		75
 
 #define ITEMS		7
 
@@ -111,5 +111,19 @@ main(void)
 		is(it, items + i, "head element after concat %d", i);
 		i++;
 	}
+
+	stailq_create(&head);
+	stailq_add_entry(&head, &items[0], next);
+	stailq_insert(&head, &items[2].next, &items[0].next);
+	stailq_insert(&head, &items[1].next, &items[0].next);
+	stailq_insert_entry(&head, &items[4], &items[2], next);
+	stailq_insert_entry(&head, &items[3], &items[2], next);
+	i = 0;
+	stailq_foreach_entry(it, &head, next) {
+		is(it, items + i, "element %d (insert)", i);
+		i++;
+	}
+	is(stailq_first(&head), &items[0].next, "first item (insert)");
+	is(stailq_last(&head), &items[4].next, "last item (insert)");
 	return check_plan();
 }
diff --git a/test/unit/stailq.result b/test/unit/stailq.result
index 78d3e721..04154500 100644
--- a/test/unit/stailq.result
+++ b/test/unit/stailq.result
@@ -1,4 +1,4 @@
-1..68
+1..75
 ok 1 - list is empty
 ok 2 - list is empty after reverse
 ok 3 - first item
@@ -67,3 +67,10 @@ ok 65 - head element after concat 3
 ok 66 - head element after concat 4
 ok 67 - head element after concat 5
 ok 68 - head element after concat 6
+ok 69 - element 0 (insert)
+ok 70 - element 1 (insert)
+ok 71 - element 2 (insert)
+ok 72 - element 3 (insert)
+ok 73 - element 4 (insert)
+ok 74 - first item (insert)
+ok 75 - last item (insert)



More information about the Tarantool-patches mailing list