diff options
author | James Booth <boothj5@gmail.com> | 2012-11-18 00:07:00 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2012-11-18 00:07:00 +0000 |
commit | 824eaa1678043afd8e31e4de529aaf61165295d7 (patch) | |
tree | 8ac7e1ed7f9a06940606ad0dc09ff108a24652bd /tests | |
parent | 2fe5e7bd5914c3062e8f914492e4e745ab6b9a15 (diff) | |
download | profani-tty-824eaa1678043afd8e31e4de529aaf61165295d7.tar.gz |
Added parser module
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_parser.c | 127 | ||||
-rw-r--r-- | tests/testsuite.c | 1 | ||||
-rw-r--r-- | tests/testsuite.h | 1 |
3 files changed, 129 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); +} diff --git a/tests/testsuite.c b/tests/testsuite.c index e7a23005..7c1b81dc 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -7,6 +7,7 @@ int main(void) register_contact_list_tests(); register_common_tests(); register_prof_autocomplete_tests(); + register_parser_tests(); run_suite(); return 0; } diff --git a/tests/testsuite.h b/tests/testsuite.h index 45145c9b..029cd48c 100644 --- a/tests/testsuite.h +++ b/tests/testsuite.h @@ -5,5 +5,6 @@ void register_prof_history_tests(void); void register_contact_list_tests(void); void register_common_tests(void); void register_prof_autocomplete_tests(void); +void register_parser_tests(void); #endif |