about summary refs log tree commit diff stats
path: root/tests/test_parser.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-18 00:07:00 +0000
committerJames Booth <boothj5@gmail.com>2012-11-18 00:07:00 +0000
commit824eaa1678043afd8e31e4de529aaf61165295d7 (patch)
tree8ac7e1ed7f9a06940606ad0dc09ff108a24652bd /tests/test_parser.c
parent2fe5e7bd5914c3062e8f914492e4e745ab6b9a15 (diff)
downloadprofani-tty-824eaa1678043afd8e31e4de529aaf61165295d7.tar.gz
Added parser module
Diffstat (limited to 'tests/test_parser.c')
-rw-r--r--tests/test_parser.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/test_parser.c b/tests/test_parser.c
new file mode 100644
index 00000000..40d4fc28
--- /dev/null
+++ b/tests/test_parser.c
@@ -0,0 +1,127 @@
+#include <stdlib.h>
+#include <string.h>
+#include <head-unit.h>
+#include "parser.h"
+
+void
+parse_null_returns_null(void)
+{
+    char *inp = NULL;
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_empty_returns_null(void)
+{
+    char *inp = "";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_space_returns_null(void)
+{
+    char *inp = "   ";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_no_args_returns_null(void)
+{
+    char *inp = "/cmd";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_with_space_returns_null(void)
+{
+    char *inp = "/cmd   ";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_one_arg(void)
+{
+    char *inp = "/cmd arg1";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_int_equals(1, num);
+    assert_string_equals("arg1", result[0]);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_two_args(void)
+{
+    char *inp = "/cmd arg1 arg2";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 2, &num);
+
+    assert_int_equals(2, num);
+    assert_string_equals("arg1", result[0]);
+    assert_string_equals("arg2", result[1]);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_three_args(void)
+{
+    char *inp = "/cmd arg1 arg2 arg3";
+    int num = 0;
+    gchar **result = parse_args(inp, 3, 3, &num);
+
+    assert_int_equals(3, num);
+    assert_string_equals("arg1", result[0]);
+    assert_string_equals("arg2", result[1]);
+    assert_string_equals("arg3", result[2]);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_three_args_with_spaces(void)
+{
+    char *inp = "  /cmd    arg1  arg2     arg3 ";
+    int num = 0;
+    gchar **result = parse_args(inp, 3, 3, &num);
+
+    assert_int_equals(3, num);
+    assert_string_equals("arg1", result[0]);
+    assert_string_equals("arg2", result[1]);
+    assert_string_equals("arg3", result[2]);
+    g_strfreev(result);
+}
+
+void
+register_parser_tests(void)
+{
+    TEST_MODULE("parser tests");
+    TEST(parse_null_returns_null);
+    TEST(parse_empty_returns_null);
+    TEST(parse_space_returns_null);
+    TEST(parse_cmd_no_args_returns_null);
+    TEST(parse_cmd_with_space_returns_null);
+    TEST(parse_cmd_one_arg);
+    TEST(parse_cmd_two_args);
+    TEST(parse_cmd_three_args);
+    TEST(parse_cmd_three_args_with_spaces);
+}