]> git.ozlabs.org Git - ccan/blobdiff - ccan/foreach/test/run-single-arg.c
foreach: allow a single argument to foreach_int() and foreach_ptr().
[ccan] / ccan / foreach / test / run-single-arg.c
diff --git a/ccan/foreach/test/run-single-arg.c b/ccan/foreach/test/run-single-arg.c
new file mode 100644 (file)
index 0000000..2541318
--- /dev/null
@@ -0,0 +1,31 @@
+#include <ccan/foreach/foreach.h>
+#include <ccan/tap/tap.h>
+#include <stdio.h>
+#include <string.h>
+#include <ccan/foreach/foreach.c>
+
+int main(void)
+{
+       int i, num;
+       const char *p;
+
+       plan_tests(5);
+
+       num = 0;
+       foreach_int(i, 0) {
+               ok1(i == 0);
+               num++;
+       }
+       ok1(num == 1);
+
+       num = 0;
+       foreach_ptr(p, "hello") {
+               ok1(strcmp("hello", p) == 0);
+               num++;
+       }
+       ok1(p == NULL);
+       ok1(num == 1);
+
+       return exit_status();
+}
+