testc_str.c 925 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 \"aaa\"bbb`ccc```ddd``eee ``lk\\\"";
  8. const char* etalon[] = {
  9. "asd\"mmm",
  10. "ll\"l\\p\\\\mj`j",
  11. "kk``pp",
  12. "ll l",
  13. "aaabbbcccdddeee",
  14. "lk\\\"", // Unclosed quotes
  15. NULL
  16. };
  17. int retval = 0;
  18. int i = 0;
  19. const char *saveptr = line;
  20. printf("Line : [%s]\n", line);
  21. for (i = 0; etalon[i]; i++) {
  22. int r = -1;
  23. char *res = NULL;
  24. printf("Etalon %d : [%s]\n", i, etalon[i]);
  25. res = faux_str_nextword(saveptr, &saveptr, "`");
  26. if (!res) {
  27. printf("The faux_str_nextword() return value is NULL\n");
  28. break;
  29. } else {
  30. printf("Result %d : [%s]\n", i, res);
  31. }
  32. r = strcmp(etalon[i], res);
  33. if (r < 0) {
  34. printf("Not equal %d\n", i);
  35. retval = -1;
  36. }
  37. faux_str_free(res);
  38. }
  39. return retval;
  40. }