MCPcopy Create free account
hub / github.com/commonmark/cmark / utf8

Function utf8

api_test/main.c:741–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739}
740
741static void utf8(test_batch_runner *runner) {
742 // Ranges
743 test_char(runner, 1, "\x01", "valid utf8 01");
744 test_char(runner, 1, "\x7F", "valid utf8 7F");
745 test_char(runner, 0, "\x80", "invalid utf8 80");
746 test_char(runner, 0, "\xBF", "invalid utf8 BF");
747 test_char(runner, 0, "\xC0\x80", "invalid utf8 C080");
748 test_char(runner, 0, "\xC1\xBF", "invalid utf8 C1BF");
749 test_char(runner, 1, "\xC2\x80", "valid utf8 C280");
750 test_char(runner, 1, "\xDF\xBF", "valid utf8 DFBF");
751 test_char(runner, 0, "\xE0\x80\x80", "invalid utf8 E08080");
752 test_char(runner, 0, "\xE0\x9F\xBF", "invalid utf8 E09FBF");
753 test_char(runner, 1, "\xE0\xA0\x80", "valid utf8 E0A080");
754 test_char(runner, 1, "\xED\x9F\xBF", "valid utf8 ED9FBF");
755 test_char(runner, 0, "\xED\xA0\x80", "invalid utf8 EDA080");
756 test_char(runner, 0, "\xED\xBF\xBF", "invalid utf8 EDBFBF");
757 test_char(runner, 0, "\xF0\x80\x80\x80", "invalid utf8 F0808080");
758 test_char(runner, 0, "\xF0\x8F\xBF\xBF", "invalid utf8 F08FBFBF");
759 test_char(runner, 1, "\xF0\x90\x80\x80", "valid utf8 F0908080");
760 test_char(runner, 1, "\xF4\x8F\xBF\xBF", "valid utf8 F48FBFBF");
761 test_char(runner, 0, "\xF4\x90\x80\x80", "invalid utf8 F4908080");
762 test_char(runner, 0, "\xF7\xBF\xBF\xBF", "invalid utf8 F7BFBFBF");
763 test_char(runner, 0, "\xF8", "invalid utf8 F8");
764 test_char(runner, 0, "\xFF", "invalid utf8 FF");
765
766 // Incomplete byte sequences at end of input
767 test_incomplete_char(runner, "\xE0\xA0", "invalid utf8 E0A0");
768 test_incomplete_char(runner, "\xF0\x90\x80", "invalid utf8 F09080");
769
770 // Invalid continuation bytes
771 test_continuation_byte(runner, "\xC2\x80");
772 test_continuation_byte(runner, "\xE0\xA0\x80");
773 test_continuation_byte(runner, "\xF0\x90\x80\x80");
774
775 // Test string containing null character
776 static const char string_with_null[] = "((((\0))))";
777 char *html = cmark_markdown_to_html(
778 string_with_null, sizeof(string_with_null) - 1, CMARK_OPT_DEFAULT);
779 STR_EQ(runner, html, "<p>((((" UTF8_REPL "))))</p>\n", "utf8 with U+0000");
780 free(html);
781
782 // Test NUL followed by newline
783 static const char string_with_nul_lf[] = "```\n\0\n```\n";
784 html = cmark_markdown_to_html(
785 string_with_nul_lf, sizeof(string_with_nul_lf) - 1, CMARK_OPT_DEFAULT);
786 STR_EQ(runner, html, "<pre><code>\xef\xbf\xbd\n</code></pre>\n",
787 "utf8 with \\0\\n");
788 free(html);
789}
790
791static void test_char(test_batch_runner *runner, int valid, const char *utf8,
792 const char *msg) {

Callers 1

mainFunction · 0.85

Calls 5

test_charFunction · 0.85
test_incomplete_charFunction · 0.85
test_continuation_byteFunction · 0.85
cmark_markdown_to_htmlFunction · 0.85
STR_EQFunction · 0.85

Tested by

no test coverage detected