/* * markdown_test.c - testa tinyblocks-markdown (-> HTML / XML / SVG). */ #include #include #include #include #include static int fails = 0; #define CHECK(c, m) do { if (c) printf("ok %s\n", m); else { printf("FAIL %s\n", m); fails++; } } while (0) static const char* MD = "# Titulo\n" "\n" "Um paragrafo com **negrito** e *italico* e `codigo`.\n" "\n" "- item um\n" "- item dois\n" "\n" "1. primeiro\n" "2. segundo\n" "\n" "> uma citacao\n" "\n" "```c\n" "int x = 1;\n" "```\n" "\n" "[link](http://exemplo.com)\n" "\n" "---\n"; int main(void) { char* h = tb_markdown_to_html(MD); CHECK(h && strstr(h, "

Titulo

"), "html h1"); CHECK(h && strstr(h, "negrito"), "html negrito"); CHECK(h && strstr(h, "italico"), "html italico"); CHECK(h && strstr(h, "codigo"), "html code inline"); CHECK(h && strstr(h, "
    ") && strstr(h, "
  • item um
  • "), "html lista nao ordenada"); CHECK(h && strstr(h, "
      ") && strstr(h, "
    1. primeiro
    2. "), "html lista ordenada"); CHECK(h && strstr(h, "
      uma citacao
      "), "html citacao"); CHECK(h && strstr(h, "
      ") && strstr(h, "int x = 1;"), "html bloco de codigo");
          CHECK(h && strstr(h, "link"), "html link");
          CHECK(h && strstr(h, "
      "), "html regra"); free(h); char* x = tb_markdown_to_xml(MD); CHECK(x && strstr(x, "") && strstr(x, ""), "xml raiz"); CHECK(x && strstr(x, "Titulo"), "xml heading"); CHECK(x && strstr(x, "") && strstr(x, "negrito"), "xml paragrafo/negrito"); CHECK(x && strstr(x, "") && strstr(x, "item um"), "xml lista"); CHECK(x && strstr(x, ""), "xml bloco de codigo"); CHECK(x && strstr(x, "link"), "xml link"); CHECK(x && strstr(x, ""), "xml regra"); free(x); char* s = tb_markdown_to_svg(MD); CHECK(s && strstr(s, "Titulo<"), "svg contem texto do titulo"); free(s); char* s2 = tb_markdown_to_svg_opts("# H", 320, 12); CHECK(s2 && strstr(s2, "width=\"320\""), "svg largura configuravel"); free(s2); /* escaping */ char* e = tb_markdown_to_html("a < b & c > d"); CHECK(e && strstr(e, "a < b & c > d"), "html escapa &,<,>"); free(e); TinyBlocks* rt; tinyblocks_init(&rt, NULL); TinyBlocks_LibraryBlock* lib = tb_library_register(rt, tb_markdown_get_library()); CHECK(tb_rt_find_type(rt, "Markdown.ToHtml") && tb_rt_find_type(rt, "Markdown.ToXml") && tb_rt_find_type(rt, "Markdown.ToSvg"), "blocos Markdown.* registrados"); const TinyBlocks_Category* cat = lib ? tb_library_category(lib) : NULL; CHECK(cat && !strcmp(cat->name, "Markdown"), "categoria 'Markdown'"); tinyblocks_deinit(&rt); if (fails) printf("\n%d FALHA(S)\n", fails); else printf("\nTUDO OK\n"); return fails != 0; }