(** README documentation rendering. *) let contains text fragment = let text_length = String.length text in let fragment_length = String.length fragment in let rec loop index = if index > text_length - fragment_length then false else if String.sub text index fragment_length = fragment then true else loop (index + 1) in fragment_length <= text_length && loop 0 let count text fragment = let text_length = String.length text in let fragment_length = String.length fragment in let rec loop index acc = if index > text_length - fragment_length then acc else if String.sub text index fragment_length = fragment then loop (index + 1) (acc + 1) else loop (index + 1) acc in if fragment_length > text_length then 0 else loop 0 0 let render ~filename content = Prose.Render.render ~filename content |> Dream_html.to_string let test_markdown_document () = let html = render ~filename:"README.md" "# Project\n\nIntroduction.\n\n## Installation\n\n- Download\n- Run\n" in Alcotest.(check bool) "documentation container" true (contains html "readme-document readme-markdown"); Alcotest.(check bool) "h1 heading" true (contains html "
List.map")
let test_org_link_with_description () =
let html =
render ~filename:"README.org"
"* Links\n\nSee [[https://example.com][Example Site]] for details.\n"
in
Alcotest.(check bool)
"link href" true
(contains html "href=\"https://example.com\"");
Alcotest.(check bool) "link text" true (contains html ">Example Site")
let test_org_link_bare () =
let html =
render ~filename:"README.org"
"* Links\n\nVisit [[https://example.com]] today.\n"
in
Alcotest.(check bool)
"bare link href" true
(contains html "href=\"https://example.com\"");
Alcotest.(check bool)
"bare link text equals URL" true
(contains html ">https://example.com")
let test_org_unordered_list () =
let html =
render ~filename:"README.org"
"* Tasks\n\n- First item\n- Second item\n- Third item\n"
in
Alcotest.(check bool)
"unordered list" true
(contains html "code");
Alcotest.(check bool)
"verbatim in list item" true
(contains html "verbatim")
let test_org_multiline_unordered () =
let html =
render ~filename:"README.org"
"* Notes\n\n- First item\n continues here\n- Second item\n"
in
Alcotest.(check bool)
"continuation joined to first item" true
(contains html "First item continues here");
Alcotest.(check bool)
"second item separate" true
(contains html "Second item")
let test_org_multiline_ordered () =
let html =
render ~filename:"README.org"
"* Steps\n\n1. Download the\n archive first\n2. Install it\n"
in
Alcotest.(check bool)
"ordered continuation joined" true
(contains html "Download the archive first");
Alcotest.(check bool)
"second ordered item separate" true
(contains html "Install it")
let test_org_multiline_definition () =
let html =
render ~filename:"README.org"
"* Glossary\n\n\
- Term :: First line\n\
\ of the definition\n\
- Other :: Short\n"
in
Alcotest.(check bool)
"definition continuation joined" true
(contains html "First line of the definition");
Alcotest.(check bool)
"second definition separate" true (contains html "Short")
let suite =
( "readme",
[
Alcotest.test_case "Markdown document" `Quick test_markdown_document;
Alcotest.test_case "Org document" `Quick test_org_document;
Alcotest.test_case "README filename detection" `Quick
test_readme_filename_detection;
Alcotest.test_case "Markdown TOC" `Quick test_markdown_toc;
Alcotest.test_case "Org TOC" `Quick test_org_toc;
Alcotest.test_case "No TOC without headings" `Quick
test_no_toc_without_headings;
Alcotest.test_case "Org verbatim inline" `Quick test_org_inline_verbatim;
Alcotest.test_case "Org code inline" `Quick test_org_inline_code;
Alcotest.test_case "Org link with description" `Quick
test_org_link_with_description;
Alcotest.test_case "Org bare link" `Quick test_org_link_bare;
Alcotest.test_case "Org unordered list" `Quick test_org_unordered_list;
Alcotest.test_case "Org ordered list" `Quick test_org_ordered_list;
Alcotest.test_case "Org definition list" `Quick test_org_definition_list;
Alcotest.test_case "Org inline in list items" `Quick
test_org_inline_in_list;
Alcotest.test_case "Org multi-line unordered items" `Quick
test_org_multiline_unordered;
Alcotest.test_case "Org multi-line ordered items" `Quick
test_org_multiline_ordered;
Alcotest.test_case "Org multi-line definition items" `Quick
test_org_multiline_definition;
] )