1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
(* This file tests the conformity of the generated AST with Markdown. *)
open Printf
let success = ref 0
let failures = ref 0
let () =
let report () =
if !failures = 0 then
printf "Congratulation, all %d specification tests passed!\n" !success
else
printf "%d test%s passed, %d test%s failed.\n"
!success (if !success > 1 then "s" else "")
!failures (if !failures > 1 then "s" else "") in
at_exit report
let test name md_string desired_md =
try
let md = Omd.of_string md_string in
if md = desired_md then (
incr success;
(* printf "%s: SUCCESS\n" name *)
)
else (
incr failures;
printf "%s: FAILURE\n" name;
printf " input = %S\nexpected = %S\n result = %S\n"
md_string
(Omd_backend.sexpr_of_md desired_md)
(Omd_backend.sexpr_of_md md)
)
with e ->
incr failures;
printf "%s: EXCEPTION\n %s\n" name (Printexc.to_string e)
let () =
let open Omd in
(* Paragraphs and Line Breaks
***********************************************************************)
(* "A paragraph is simply one or more consecutive lines of text,
separated by one or more blank lines." Note that the final
newlines are not considered to be part of the paragraphs, just a
delimiter. *)
test "Paragraph, simple" "Paragraph1\nline2\n\nP2\n\n\nP3"
[Paragraph [Text "Paragraph1"; NL; Text "line2"];
Paragraph [Text "P2"]; Paragraph [Text "P3"]];
(* A blank line is any line that looks like a blank line — a line
containing nothing but spaces or tabs is considered blank. *)
test "Paragraph, blank line" "P1\n \nP2\n\t\nP3\n"
[Omd.Paragraph [Omd.Text "P1"];
Omd.Paragraph [Omd.Text "P2"];
Omd.Paragraph [Omd.Text "P3"]];
(* "When you do want to insert a <br />, you end a line with two or
more spaces." *)
test "Paragraph, <br>" "Paragraph1 \nline2\n\nParagraph2"
[Paragraph [Text "Paragraph1"; Br; Text "line2"];
Paragraph [Text "Paragraph2"]];
(* Normal paragraphs should not be indented with spaces or tabs. *)
(* Headers
***********************************************************************)
test "header, ===" "Title\n==" [Omd.H1 [Omd.Text "Title"]];
test "header, ---" "Title\n---" [Omd.H2 [Omd.Text "Title"]];
test "header, #" "# Title" [Omd.H1 [Omd.Text "Title"]];
test "header, ##" "## Title" [Omd.H2 [Omd.Text "Title"]];
test "header, ###" "### Title" [Omd.H3 [Omd.Text "Title"]];
test "header, ####" "#### Title" [Omd.H4 [Omd.Text "Title"]];
test "header, #####" "##### Title" [Omd.H5 [Omd.Text "Title"]];
test "header, ######" "###### Title" [Omd.H6 [Omd.Text "Title"]];
test "header, too deep" "######## Title\n"
[Omd.Paragraph[Omd.Text "######## Title"]];
test "header, # + space" "# Title " [Omd.H1 [Omd.Text "Title"]];
test "header, # #" "# Title ###" [Omd.H1 [Omd.Text "Title"]];
test "header, # #" "# Title # " [Omd.H1 [Omd.Text "Title"]];
test "header, ## + space" "## Title # " [Omd.H2 [Omd.Text "Title"]];
test "header, # + \\n" "# Title\n" [Omd.H1 [Omd.Text "Title"]];
test "header, # + space + \\n" "# Title \n" [Omd.H1 [Omd.Text "Title"]];
test "header, # + # + \\n" "# Title # \n" [Omd.H1 [Omd.Text "Title"]];
(* Blockquotes
***********************************************************************)
test "blockquote, simple" "> quoted"
[Blockquote [Paragraph [Text "quoted"]]];
test "blockquote, simple 2" "> quoted\n"
[Blockquote [Paragraph [Text "quoted"]]];
test "blockquote, 2 pars" "> quoted\n>\n> quoted2"
[Blockquote [Paragraph [Text "quoted"];
Paragraph [Text "quoted2"]]];
test "blockquote, 2 pars (blank line)" "> quoted\n\n> quoted2"
[Blockquote [Paragraph [Text "quoted"];
Paragraph [Text "quoted2"]]];
test "blockquote + header" "> ## header\n"
[Blockquote [H2 [Text "header"]]];
test "blockquote + header + par" "> ## header\nHello"
[Blockquote [H2 [Text "header"]; Paragraph [Text "Hello"]]];
test "blockquote + header + par" "> ## header\n> Hello"
[Blockquote [H2 [Text "header"]; Paragraph [Text "Hello"]]];
test "blockquote + list" "> 1. item1\n> 2. item2\n"
[Blockquote [Ol [[Text "item1"];
[Text "item2"]]]];
test "blockquote + code (4 spaces)" "> code"
[Blockquote [Code_block ("", "code")]];
test "blockquote + code (tab)" "> \tcode"
[Blockquote [Code_block ("", "code")]];
test "blockquote + code ```" "> ```\n> code\n> ```"
[Blockquote [Code_block ("", "code")]];
(* Lists
***********************************************************************)
test "list, simple" "8. Red\n1. Green\n3. Blue"
[Ol [[Text "Red"]; [Text "Green"]; [Text "Blue"]]];
test "list, simple2" "\n8. Red\n1. Green\n3. Blue"
[Ol [[Text "Red"]; [Text "Green"]; [Text "Blue"]]];
test "list, par" "8. Red\n\n1. Green\n\n3. Blue"
[Olp [[Paragraph[Text "Red"]]; [Paragraph[Text "Green"]];
[Paragraph[Text "Blue"]]]];
test "list, *" "* AA\n* VV"
[Ul [[Text "AA"]; [Text "VV"]]];
test "list, 2 levels" "* AA\n\n* VV"
[Ulp [[Paragraph [Text "AA"]]; [Paragraph [Text "VV"]]]];
test "list + code + space + header" "- A
- B
```
code
```
# header"
[Ulp [[Paragraph [Omd.Text "A"]];
[Paragraph [Omd.Text "B"]; Code_block ("", "code")]];
NL; NL; H1 [Text "header"]];
(* Code
***********************************************************************)
test "code dashes" "```\n--\n--\n--\n```"
[Omd.Code_block ("", "--\n--\n--")]
|