aboutsummaryrefslogtreecommitdiff
path: root/api_test/main.c
blob: 1ff606b6938b6d8cb956e766e67f2746483e361e (plain)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "cmark.h"
  5. #include "node.h"
  6. #include "harness.h"
  7. static void
  8. create_tree(test_batch_runner *runner)
  9. {
  10. cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
  11. cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
  12. OK(runner, cmark_node_append_child(doc, p), "append1");
  13. INT_EQ(runner, cmark_node_check(doc), 0, "append1 consistent");
  14. cmark_node *emph = cmark_node_new(CMARK_NODE_EMPH);
  15. OK(runner, cmark_node_prepend_child(p, emph), "prepend1");
  16. INT_EQ(runner, cmark_node_check(doc), 0, "prepend1 consistent");
  17. cmark_node *str1 = cmark_node_new(CMARK_NODE_STRING);
  18. cmark_node_set_content(str1, "Hello, ");
  19. OK(runner, cmark_node_prepend_child(p, str1), "prepend2");
  20. INT_EQ(runner, cmark_node_check(doc), 0, "prepend2 consistent");
  21. cmark_node *str3 = cmark_node_new(CMARK_NODE_STRING);
  22. cmark_node_set_content(str3, "!");
  23. OK(runner, cmark_node_append_child(p, str3), "append2");
  24. INT_EQ(runner, cmark_node_check(doc), 0, "append2 consistent");
  25. cmark_node *str2 = cmark_node_new(CMARK_NODE_STRING);
  26. cmark_node_set_content(str2, "world");
  27. OK(runner, cmark_node_append_child(emph, str2), "append3");
  28. INT_EQ(runner, cmark_node_check(doc), 0, "append3 consistent");
  29. char *html = (char *)cmark_render_html(doc);
  30. STR_EQ(runner, html, "<p>Hello, <em>world</em>!</p>\n",
  31. "render_html");
  32. free(html);
  33. cmark_node_destroy(doc);
  34. }
  35. int main() {
  36. int retval;
  37. test_batch_runner *runner = test_batch_runner_new();
  38. create_tree(runner);
  39. test_print_summary(runner);
  40. retval = test_ok(runner) ? 0 : 1;
  41. free(runner);
  42. return retval;
  43. }