Add one more test and improve parsing
This commit is contained in:
parent
daf09dedd3
commit
91ca9b44bc
|
@ -24,7 +24,7 @@
|
|||
#ifndef UIRC_GUARD_UIRC
|
||||
#define UIRC_GUARD_UIRC
|
||||
|
||||
#define UIRC_VERSION 20201216
|
||||
#define UIRC_VERSION 20201220
|
||||
|
||||
#endif /* UIRC_GUARD_UIRC */
|
||||
|
||||
|
|
|
@ -43,12 +43,15 @@ Tok_mesg(char* str, IRC_Message* out)
|
|||
|
||||
skip_spaces(&progr);
|
||||
|
||||
if ((command = strtok_mr(&progr, " ")) != NULL) {
|
||||
if (isalnum(*progr) && (command = strtok_mr(&progr, " ")) != NULL) {
|
||||
signed short temp;
|
||||
if (isalpha(*command)) {
|
||||
if ((temp = Ircmd_stoi(command)) < UIRC_FCMD || temp > UIRC_LCMD) return ERR_UIRC_UNKNOWN_TOKEN;
|
||||
out->cmd = (IRC_Command) temp;
|
||||
} else {
|
||||
for (size_t l = 0; command[l]; l++) {
|
||||
if (!isdigit(command[l])) return ERR_UIRC_INVALID_FORMAT;
|
||||
}
|
||||
out->cmd = (IRC_Command) atoi(command);
|
||||
}
|
||||
} else
|
||||
|
|
|
@ -14,6 +14,7 @@ buildtest(NumericCmds numericmds)
|
|||
buildtest(IncorrectTrailing notrail)
|
||||
buildtest(SpacedArguments spacedargs)
|
||||
buildtest(StrTokMoveSave strtokmr)
|
||||
buildtest(Junk junk)
|
||||
|
||||
if ( BUILD_IRCV3 )
|
||||
buildtest(TagParser tagtok)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#include "../include/uirc.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char mesg[][513] = {
|
||||
"", "NO ", "CM:", "@:", "@ ", "@ N", "@ N:", "\n", "\r", "AA x :\r", "9A x :\r", "XA x :\r",
|
||||
};
|
||||
IRC_Message out = { 0 };
|
||||
for (unsigned long i = 0; i < sizeof(mesg) / sizeof(*mesg); i++) {
|
||||
if (Tok_mesg(mesg[i], &out) == 1) {
|
||||
printf("Message was parsed successfuly when it was junk.\nTest failed: #%lu %s\n", i, mesg[i]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue