hl_parser.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. "hello\n",
  21. "char *p = \"this is a quoted string\";",
  22. "char p = 'h';",
  23. "// a single line comment\n",
  24. "# single line definition/comment\n",
  25. "/*\n * mutiline\n comment \n */\n"
  26. };
  27. int ts_len = 6;
  28. int changeme = 0;
  29. void simple_next_word(char *word, int len, hl_node *root, hl_ctx *ctx) {
  30. changeme = 1;
  31. }
  32. int main() {
  33. size_t rlen;
  34. hl_root *res;
  35. for (int i = 0; i < ts_len; i++) {
  36. changeme = 0;
  37. rlen = strlen(test_str[i]);
  38. res = hl_parser(test_str[i], rlen, simple_next_word);
  39. /* printf("rlen: %d, res: %d\n", rlen, res->text_size);*/
  40. assert(changeme == 1);
  41. assert(res != NULL);
  42. assert(res->text_size == rlen);
  43. hl_root_free(res);
  44. }
  45. for (int i = 0; i < ts_len; i++) {
  46. changeme = 0;
  47. rlen = strlen(test_str[i]);
  48. res = hl_parser(test_str[i], rlen, NULL);
  49. /* printf("rlen: %d, res: %d\n", rlen, res->text_size);*/
  50. assert(res != NULL);
  51. assert(res->text_size == rlen);
  52. hl_root_free(res);
  53. }
  54. return 0;
  55. }