From 23b66bf33da134272ba5131919a384ac24706029 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 10 Jul 2020 13:44:58 +0200 Subject: [PATCH] Rollback trailing change with a bugfix, add test for non-delimited trailing --- src/uirc.c | 4 +++- tests/parsing.c | 50 +++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/uirc.c b/src/uirc.c index ff7dcb1..d8cf55e 100644 --- a/src/uirc.c +++ b/src/uirc.c @@ -116,7 +116,9 @@ signed int Tok_mesg(char* str, IRC_Message* out) } out->args[i] = NULL; if (*progr == ':') - out->trailing = ++progr; + ++progr; + if (*progr != '\0') + out->trailing = progr; return 1; } signed int Assm_mesg(char* buf, IRC_Message* in) diff --git a/tests/parsing.c b/tests/parsing.c index 93ede3d..b8b39e7 100644 --- a/tests/parsing.c +++ b/tests/parsing.c @@ -8,11 +8,13 @@ int main(void) IRC_Message results[] = { {.name.nick = "user", .cmd = NOTICE, .trailing = "ok"}, {.cmd = QUIT}, - {.name = {.nick = "nick", .user = "user", .host = "host"}, .cmd = PRIVMSG, .args[0] = "friend", .trailing = "hello there"}}; + {.name = {.nick = "nick", .user = "user", .host = "host"}, .cmd = PRIVMSG, .args[0] = "friend", .trailing = "hello there"}, + {.cmd = QUIT, .args = {"one", "two", "three", "four", "5", "6", "seven", "8", "nein", "10", "11", "12", "13", "14"}, .trailing = "i'm trailing"}}; char mesg[][513] = { ":user NOTICE :ok", "QUIT", - ":nick!user@host PRIVMSG friend :hello there"}; + ":nick!user@host PRIVMSG friend :hello there", + "QUIT one two three four 5 6 seven 8 nein 10 11 12 13 14 i'm trailing"}; IRC_Message parseout; int res = 0; for (unsigned long i = 0; i < sizeof(results) / sizeof(IRC_Message); i++) { @@ -40,27 +42,6 @@ int main(void) {parseout.tags.reply.value, results[i].tags.reply.value} // 12 }; printf("Validation:\n"); - printf("\tStrings:\n"); - for (unsigned long j = 0; j < sizeof(strings) / sizeof(char* [2]); j++) { - if (strings[j][0] != NULL && *strings[j][0] != '\0') { - printf("\t\t[%lu]: ", j); - if (strings[j][1] == NULL || *strings[j][1] == '\0') { - printf("Matching argument is a NULL pointer or zero-lenght: --> %lu\n", i); - return EXIT_FAILURE; - } - if (strcmp(strings[j][0], strings[j][1])) { - printf("Arguments didn't match at iteration %lu: expected %s but got %s", i, strings[j][1], strings[j][0]); - return EXIT_FAILURE; - } - printf("OK\n"); - } - } - printf("\tCommand: "); - if (parseout.cmd == 0 || parseout.cmd != results[i].cmd) { - printf("Command is not parsed or non-matching. Got %s (%i)\n", uirc_ircmd[parseout.cmd], parseout.cmd); - return EXIT_FAILURE; - } - printf("OK\n"); printf("\tArguments:\n"); for (int k = 0; i < 14 && results[i].args[k] != NULL; k++) { printf("\t\t[%i]: ", k); @@ -72,8 +53,29 @@ int main(void) printf("Argument %i does not match expected value. Expected %s, got %s instead\n", k, results[i].args[k], parseout.args[k]); return EXIT_FAILURE; } - printf("OK\n"); + printf("OK %s\n", parseout.args[k]); } + printf("\tStrings:\n"); + for (unsigned long j = 0; j < sizeof(strings) / sizeof(char* [2]); j++) { + if (strings[j][1] != NULL && *strings[j][1] != '\0') { + printf("\t\t[%lu]: ", j); + if (strings[j][0] == NULL || *strings[j][0] == '\0') { + printf("Matching argument is a NULL pointer or zero-lenght --> %s\n", strings[j][0]); + return EXIT_FAILURE; + } + if (strcmp(strings[j][0], strings[j][1])) { + printf("Arguments didn't match at iteration %lu: expected %s but got %s", i, strings[j][1], strings[j][0]); + return EXIT_FAILURE; + } + printf("OK %s\n", strings[j][0]); + } + } + printf("\tCommand: "); + if (parseout.cmd == 0 || parseout.cmd != results[i].cmd) { + printf("Command is not parsed or non-matching. Got %s (%i) and expected %s\n", uirc_ircmd[parseout.cmd], parseout.cmd, uirc_ircmd[results[i].cmd]); + return EXIT_FAILURE; + } + printf("OK\n"); } return EXIT_SUCCESS; }