Mercurial
view markdown_converter/tests/markdown_to_html_test.c @ 247:70f2a3dafc1c
[build] Bundle offline Tectonic runtime
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 03 Aug 2026 20:20:06 -0700 |
| parents | ce7f4400c2de |
| children |
line wrap: on
line source
#include "markdown_converter/markdown_to_html.h" #include <stdio.h> #include <string.h> static int failures = 0; static void expect_equal(const char *name, const char *markdown, const char *expected) { char *actual = markdown_to_html(markdown); if (!actual || strcmp(actual, expected) != 0) { fprintf(stderr, "%s\nexpected: %s\nactual: %s\n", name, expected, actual ? actual : "(null)"); failures++; } markdown_free(actual); } int main(void) { expect_equal("normal link", "[link](https://example.com)", "<p><a href=\"https://example.com\">link</a></p>"); expect_equal("escape paragraph", "a & <b>", "<p>a & <b></p>"); expect_equal("escape raw script", "<script>alert('x')</script>", "<p><script>alert('x')</script></p>"); expect_equal("reject script link", "[open](javascript:alert)", "<p>open</p>"); expect_equal("reject data image", "", "<p>preview</p>"); expect_equal("escape link attribute", "[link](https://example.com/\"x)", "<p><a href=\"https://example.com/"x\">link</a></p>"); expect_equal("escape inline code", "`<script>`", "<p><code><script></code></p>"); return failures == 0 ? 0 : 1; }