git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Add test-string-list.c

From
Thiago Farina <tfransosi@gmail.com>
Date
Sep 5, 2010, 02:34 UTC
Message-ID
<4f798daaf4631e00927b455b77919d5bb8fade03.1283653854.git.tfransosi@gmail.com>

Add a simple test that demonstrates how to create and manipulate a list of strings using the string-list.h API.

To see the test, call it by: ./bin-wrappers/test-string-list.c

Signed-off-by: Thiago Farina <tfransosi@gmail.com>
---
 Makefile           |    1 +
 test-string-list.c |   29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
 create mode 100644 test-string-list.c
diff --git a/Makefile b/Makefile
index 40fbcae..287bc2c 100644
--- a/Makefile
+++ b/Makefile
@@ -422,6 +422,7 @@ TEST_PROGRAMS_NEED_X += test-string-pool
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-treap
 TEST_PROGRAMS_NEED_X += test-index-version
+TEST_PROGRAMS_NEED_X += test-string-list
 
 TEST_PROGRAMS = $(patsubst %,%$X,$(TEST_PROGRAMS_NEED_X))
 
diff --git a/test-string-list.c b/test-string-list.c
new file mode 100644
index 0000000..11b8a7f
--- /dev/null
+++ b/test-string-list.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <string.h>
+#include "string-list.h"
+
+int main(int argc, const char **argv)
+{
+	struct string_list list;
+	int i;
+
+	memset(&list, 0, sizeof(struct string_list));
+
+	string_list_append(&list, "foo");
+	string_list_append(&list, "bar");
+
+	for (i = 0; i < list.nr; i++)
+		printf("%s\n", list.items[i].string);
+
+	print_string_list(&list, "");
+
+        int has_foo = string_list_has_string(&list, "foo");
+	if (has_foo != 1)
+		error("List doesn't have foo.");
+
+	string_list_clear(&list, 0);
+	if (list.nr > 0)
+		error("List is not clear.");
+
+	return 0;
+}
-- 
1.7.2.3.313.gcd15
Next: Jonathan Nieder
Message 1 of 6 in “Add test-string-list.c”
  1. Add test-string-list.cThiago Farina, Sep 5, 2010
  2. Jonathan NiederSep 5, 2010
  3. Junio C HamanoSep 6, 2010
  4. Thiago FarinaSep 6, 2010
  5. Jonathan NiederSep 7, 2010
  6. Thiago FarinaSep 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.