hl_pp.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version 2
  5. * of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. * Author: g0tsu
  12. * Email: g0tsu at dnmx.0rg
  13. */
  14. #include <libhighlight.h>
  15. #include <assert.h>
  16. #include <unistd.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. char *test_str[] = {
  20. "// this is a single line comment",
  21. "void hello (int world, char *p) {\n if ( a==3) { printf(\"hello\"); } \n}\n",
  22. "#include <stdio.h>\nint main(int ac, char **av) { \n int a = 1; return 0; \n}\n",
  23. "char *a = \"hello \\\"world\\\"\n 'and bye'\";\n",
  24. "t",
  25. "tc",
  26. "int hello; //world",
  27. "/* \n * multiline \n comment */"
  28. };
  29. int ts_len = 8;
  30. int main() {
  31. size_t rlen;
  32. hl_root *res;
  33. for (int i = 0; i < ts_len; i++) {
  34. rlen = strlen(test_str[i]);
  35. res = hl_parser(test_str[i], rlen, NULL);
  36. hl_compile_pp(res->node);
  37. printf("\n");
  38. assert(res != NULL);
  39. assert(res->text_size == rlen);
  40. hl_root_free(res);
  41. }
  42. return 0;
  43. }