about summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-18 00:25:08 +0000
committerJames Booth <boothj5@gmail.com>2012-11-18 00:25:08 +0000
commit191ab83c9b888ebd5f60afc256833c8062629e05 (patch)
tree95bac495ec8fbc769f459786f0316418ff58299c /tests
parent430c9ad06034551f3b9663682c65c93132eb6420 (diff)
downloadprofani-tty-191ab83c9b888ebd5f60afc256833c8062629e05.tar.gz
Added command parser for commands accepting free text
e.g. /msg user@host here is a message
Diffstat (limited to 'tests')
-rw-r--r--tests/test_parser.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_parser.c b/tests/test_parser.c
index 40d4fc28..a3e31ed6 100644
--- a/tests/test_parser.c
+++ b/tests/test_parser.c
@@ -59,6 +59,28 @@ parse_cmd_with_space_returns_null(void)
 }
 
 void
+parse_cmd_with_too_few_returns_null(void)
+{
+    char *inp = "/cmd arg1";
+    int num = 0;
+    gchar **result = parse_args(inp, 2, 3, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_with_too_many_returns_null(void)
+{
+    char *inp = "/cmd arg1 arg2 arg3 arg4";
+    int num = 0;
+    gchar **result = parse_args(inp, 1, 3, &num);
+
+    assert_is_null(result);
+    g_strfreev(result);
+}
+
+void
 parse_cmd_one_arg(void)
 {
     char *inp = "/cmd arg1";
@@ -112,6 +134,45 @@ parse_cmd_three_args_with_spaces(void)
 }
 
 void
+parse_cmd_with_freetext(void)
+{
+    char *inp = "/cmd this is some free text";
+    int num = 0;
+    gchar **result = parse_args_with_freetext(inp, 1, 1, &num);
+
+    assert_int_equals(1, num);
+    assert_string_equals("this is some free text", result[0]);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_one_arg_with_freetext(void)
+{
+    char *inp = "/cmd arg1 this is some free text";
+    int num = 0;
+    gchar **result = parse_args_with_freetext(inp, 1, 2, &num);
+
+    assert_int_equals(2, num);
+    assert_string_equals("arg1", result[0]);
+    assert_string_equals("this is some free text", result[1]);
+    g_strfreev(result);
+}
+
+void
+parse_cmd_two_args_with_freetext(void)
+{
+    char *inp = "/cmd arg1 arg2 this is some free text";
+    int num = 0;
+    gchar **result = parse_args_with_freetext(inp, 1, 3, &num);
+
+    assert_int_equals(3, num);
+    assert_string_equals("arg1", result[0]);
+    assert_string_equals("arg2", result[1]);
+    assert_string_equals("this is some free text", result[2]);
+    g_strfreev(result);
+}
+
+void
 register_parser_tests(void)
 {
     TEST_MODULE("parser tests");
@@ -124,4 +185,9 @@ register_parser_tests(void)
     TEST(parse_cmd_two_args);
     TEST(parse_cmd_three_args);
     TEST(parse_cmd_three_args_with_spaces);
+    TEST(parse_cmd_with_freetext);
+    TEST(parse_cmd_one_arg_with_freetext);
+    TEST(parse_cmd_two_args_with_freetext);
+    TEST(parse_cmd_with_too_few_returns_null);
+    TEST(parse_cmd_with_too_many_returns_null);
 }