testc_str.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "faux/str.h"
  5. int testc_faux_str_nextword(void)
  6. {
  7. const char* line = "asd\"\\\"\"mmm \"``\" `ll\"l\\p\\\\m```j`j`` ```kk``pp``` ll\\ l jj\\\"kk ll\\\\nn \"aaa\"bbb`ccc```ddd``eee ``lk\\\"";
  8. const char* etalon[] = {
  9. "asd\"mmm",
  10. "``",
  11. "ll\"l\\p\\\\mj`j",
  12. "kk``pp",
  13. "ll l",
  14. "jj\"kk",
  15. "ll\\nn",
  16. "aaabbbcccdddeee",
  17. "lk\\\"", // Unclosed quotes
  18. NULL
  19. };
  20. int retval = 0;
  21. int i = 0;
  22. const char *saveptr = line;
  23. bool_t closed_quotes = BOOL_FALSE;
  24. printf("Line : [%s]\n", line);
  25. for (i = 0; etalon[i]; i++) {
  26. int r = -1;
  27. char *res = NULL;
  28. printf("Etalon %d : [%s]\n", i, etalon[i]);
  29. res = faux_str_nextword(saveptr, &saveptr, "`", &closed_quotes);
  30. if (!res) {
  31. printf("The faux_str_nextword() return value is NULL\n");
  32. break;
  33. } else {
  34. printf("Result %d : [%s]\n", i, res);
  35. }
  36. r = strcmp(etalon[i], res);
  37. if (r < 0) {
  38. printf("Not equal %d\n", i);
  39. retval = -1;
  40. }
  41. faux_str_free(res);
  42. }
  43. // Last quote is unclosed
  44. if (closed_quotes) {
  45. printf("Closed quotes flag is wrong\n");
  46. retval = -1;
  47. } else {
  48. printf("Really unclosed quotes\n");
  49. }
  50. return retval;
  51. }