hl_tokenizer.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. int expr_inside_test() {
  20. hl_root *res;
  21. const char *str1 = "// void is not int comment";
  22. const char *str2 = "void stst () { //comment\n }";
  23. size_t slen1 = strlen(str1);
  24. size_t slen2 = strlen(str2);
  25. assert((res = hl_parser(str1, slen1, NULL)));
  26. assert(res->node->root->children->type == HL_NODE_COMMENT_START);
  27. assert(res->node->root->children->type == HL_NODE_COMMENT_START);
  28. assert(res->node->parent->type == HL_NODE_COMMENT_END);
  29. // void
  30. assert(res->node->root->children->children->children->children->text_len == 4);
  31. assert(res->node->root->children->children->children->children->type != HL_NODE_TYPE);
  32. hl_root_free(res);
  33. assert((res = hl_parser(str2, slen2, NULL)));
  34. assert(res->node->root->children->type == HL_NODE_TYPE);
  35. hl_root_free(res);
  36. return 0;
  37. }
  38. int main() {
  39. assert(!expr_inside_test());
  40. return 0;
  41. }