Changeset 2bc6ad35 for tester.c


Ignore:
Timestamp:
Jan 2, 2011, 3:35:15 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
d222c44
Parents:
d275eb2
git-author:
David Benjamin <davidben@mit.edu> (12/14/10 23:52:42)
git-committer:
David Benjamin <davidben@mit.edu> (01/02/11 15:35:15)
Message:
Add owl_quote_arg and owl_string_append_quoted_arg

Also add unit tests. We don't appear to have an equivalent of
BarnOwl::quote in C that actually works.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    re45d9f4 r2bc6ad35  
    175175  FAIL_UNLESS("skiptokens 5",
    176176              !strcmp("c d e", skiptokens("a \"'\" c d e", 2)));
     177
     178#define CHECK_QUOTING(desc, unquoted, quoted)           \
     179  do {                                                  \
     180      int __argc;                                       \
     181      char *__quoted = owl_arg_quote(unquoted);         \
     182      char **__argv;                                    \
     183      FAIL_UNLESS(desc, !strcmp(quoted, __quoted));     \
     184      __argv = owl_parseline(__quoted, &__argc);        \
     185      FAIL_UNLESS(desc " - arg count", __argc == 1);    \
     186      FAIL_UNLESS(desc " - parsed",                     \
     187                  !strcmp(__argv[0], unquoted));        \
     188      owl_parse_delete(__argv, __argc);                 \
     189      owl_free(__quoted);                               \
     190    } while (0)
     191
     192  CHECK_QUOTING("boring text", "mango", "mango");
     193  CHECK_QUOTING("spaces", "mangos are tasty", "'mangos are tasty'");
     194  CHECK_QUOTING("single quotes", "mango's", "\"mango's\"");
     195  CHECK_QUOTING("double quotes", "he said \"mangos are tasty\"",
     196                "'he said \"mangos are tasty\"'");
     197  CHECK_QUOTING("both quotes",
     198                "he said \"mango's are tasty even when you put in "
     199                "a random apostrophe\"",
     200                "\"he said \"'\"'\"mango's are tasty even when you put in "
     201                "a random apostrophe\"'\"'\"\"");
     202  CHECK_QUOTING("quote monster", "'\"\"'\"'''\"",
     203                "\""
     204                "'"
     205                "\"'\"'\""
     206                "\"'\"'\""
     207                "'"
     208                "\"'\"'\""
     209                "'"
     210                "'"
     211                "'"
     212                "\"'\"'\""
     213                "\"");
    177214
    178215  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
Note: See TracChangeset for help on using the changeset viewer.