mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Handle commands with min 0 args
This commit is contained in:
parent
191ab83c9b
commit
312d362eaa
12
src/parser.c
12
src/parser.c
@ -75,6 +75,12 @@ parse_args(const char * const inp, int min, int max, int *num)
|
||||
*num = 0;
|
||||
return NULL;
|
||||
|
||||
// if min allowed is 0 and 0 found, return empty char* array
|
||||
} else if (min == 0 && *num == 0) {
|
||||
gchar **args = malloc((*num + 1) * sizeof(*args));
|
||||
args[0] = NULL;
|
||||
return args;
|
||||
|
||||
// otherwise return args array
|
||||
} else {
|
||||
gchar **args = malloc((*num + 1) * sizeof(*args));
|
||||
@ -151,6 +157,12 @@ parse_args_with_freetext(const char * const inp, int min, int max, int *num)
|
||||
*num = 0;
|
||||
return NULL;
|
||||
|
||||
// if min allowed is 0 and 0 found, return empty char* array
|
||||
} else if (min == 0 && *num == 0) {
|
||||
gchar **args = malloc((*num + 1) * sizeof(*args));
|
||||
args[0] = NULL;
|
||||
return args;
|
||||
|
||||
// otherwise return args array
|
||||
} else {
|
||||
gchar **args = malloc((*num + 1) * sizeof(*args));
|
||||
|
@ -26,5 +26,6 @@
|
||||
#include <glib.h>
|
||||
|
||||
gchar** parse_args(const char * const inp, int min, int max, int *num);
|
||||
gchar** parse_args_with_freetext(const char * const inp, int min, int max, int *num);
|
||||
|
||||
#endif
|
||||
|
@ -172,6 +172,30 @@ parse_cmd_two_args_with_freetext(void)
|
||||
g_strfreev(result);
|
||||
}
|
||||
|
||||
void
|
||||
parse_cmd_min_zero(void)
|
||||
{
|
||||
char *inp = "/cmd";
|
||||
int num = 0;
|
||||
gchar **result = parse_args(inp, 0, 2, &num);
|
||||
|
||||
assert_int_equals(0, num);
|
||||
assert_is_null(result[0]);
|
||||
g_strfreev(result);
|
||||
}
|
||||
|
||||
void
|
||||
parse_cmd_min_zero_with_freetext(void)
|
||||
{
|
||||
char *inp = "/cmd";
|
||||
int num = 0;
|
||||
gchar **result = parse_args_with_freetext(inp, 0, 2, &num);
|
||||
|
||||
assert_int_equals(0, num);
|
||||
assert_is_null(result[0]);
|
||||
g_strfreev(result);
|
||||
}
|
||||
|
||||
void
|
||||
register_parser_tests(void)
|
||||
{
|
||||
@ -190,4 +214,6 @@ register_parser_tests(void)
|
||||
TEST(parse_cmd_two_args_with_freetext);
|
||||
TEST(parse_cmd_with_too_few_returns_null);
|
||||
TEST(parse_cmd_with_too_many_returns_null);
|
||||
TEST(parse_cmd_min_zero);
|
||||
TEST(parse_cmd_min_zero_with_freetext);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user