Changeset 269580c for tests/check_util.c


Ignore:
Timestamp:
2014-07-24T03:51:07Z (10 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
59e66ff
Parents:
1783ab6
Message:

Add limit param to split_command_parts(), fix twitter quotes bug

Only took me a few months to write. I even added a test case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/check_util.c

    r1783ab6 r269580c  
    167167        http_encode( s );
    168168        fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 );
     169END_TEST
     170
     171struct {
     172        int limit;
     173        char *command;
     174        char *expected[IRC_MAX_ARGS+1];
     175} split_tests[] = {
     176        {
     177                0, "account add etc \"user name with spaces\" 'pass\\ word'",
     178                {"account", "add", "etc", "user name with spaces", "pass\\ word", NULL},
     179        },
     180        {
     181                0, "channel set group Close\\ friends",
     182                {"channel", "set", "group", "Close friends", NULL},
     183        },
     184        {
     185                2, "reply wilmer \"testing in C is a PITA\", you said.",
     186                {"reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL},
     187        },
     188        {
     189                4, "one space  two  spaces  limit  limit",
     190                {"one", "space", "two", "spaces", "limit  limit", NULL},
     191        },
     192        {
     193                0, NULL,
     194                {NULL}
     195        },
     196};
     197
     198START_TEST(test_split_command_parts)
     199        int i;
     200        for (i = 0; split_tests[i].command; i++) {
     201                char *cmd = g_strdup(split_tests[i].command);
     202                char **split = split_command_parts(cmd, split_tests[i].limit);
     203                char **expected = split_tests[i].expected;
     204
     205                int j;
     206                for (j = 0; split[j] && expected[j]; j++) {
     207                        fail_unless (strcmp(split[j], expected[j]) == 0,
     208                                "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)",
     209                                i, split_tests[i].command, j, split[j], expected[j]);
     210                }
     211                g_free(cmd);
     212        }
    169213END_TEST
    170214
     
    183227        tcase_add_test (tc_core, test_word_wrap);
    184228        tcase_add_test (tc_core, test_http_encode);
     229        tcase_add_test (tc_core, test_split_command_parts);
    185230        return s;
    186231}
Note: See TracChangeset for help on using the changeset viewer.