aboutsummaryrefslogtreecommitdiffstats
path: root/FMark/src/Common/MarkdownGen/MarkdownGenTester.fs
blob: 69ae19ea05851da52a4d714621352ccc4c580717 (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
module MarkdownGenTester

open Types
open MarkdownGen
open Expecto

let id x = x
let makeExpectoTestList inputTransform outputTransform testFunc name listOfIOPairs =
    let makeOneTest i (inn, out, msg) = testCase (sprintf "test markdown: %d" i) <| fun () ->
        Expect.equal (inn |> inputTransform |> testFunc) (outputTransform out) msg
    listOfIOPairs
    |> List.indexed
    |> List.map (fun (i, triple) -> makeOneTest i triple )
    |> Expecto.Tests.testList name

let catStr strList =
    String.concat "" strList

//////////////////////////////////
// tests
//////////////////////////////////

[<Tests>]
let mdInlineElementsTests =
    makeExpectoTestList id id mdInlineElements "mdInlineElementsTests" [
        (
            [FrmtedString(Strong([FrmtedString(Literal "Go go go!")]))],
            "**Go go go!**", "strong tag"
        );
        (
            [FrmtedString(Emphasis([FrmtedString(Literal "Go go go!")]))],
            "*Go go go!*", "em tag"
        );
        (
            [Link(Emphasis([FrmtedString(Literal "Go go go!")]), "www.google.co.uk")],
            "[*Go go go!*](www.google.co.uk)", "a tag"
        );
        (
            [Picture("404 not found", "www.google.co.uk/img.jpg")],
            "![404 not found](www.google.co.uk/img.jpg)", "picture tag"
        );
    ]

[<Tests>]
let paragraphTests =
    makeExpectoTestList id id mdParagraph "paragraph tests" [
        (
            [[FrmtedString(Strong([FrmtedString(Literal "Go go go!")]))]],
            "**Go go go!**\n\n", "strong tag"
        );
        (
            [[FrmtedString(Strong([FrmtedString(Literal "Go go go!")])); Link(Literal "broken link", "brokenURL")]],
            "**Go go go!**[broken link](brokenURL)\n\n", "strong and link tag"
        );
        (
            [[FrmtedString((Literal "Go go go!")); Link(Literal "broken link", "brokenURL")]; [FrmtedString(Literal "Come!")]],
            "Go go go![broken link](brokenURL)Come!\n\n", "indent test"
        );
    ]

[<Tests>]
let bodyTests =
    makeExpectoTestList id id mdBody "body tests" [
        (
            [Paragraph[[FrmtedString(Strong([FrmtedString(Literal "Go go go!")]))]]],
            "**Go go go!**\n\n", "strong tag"
        );
        (
            [Paragraph[[FrmtedString(Strong([FrmtedString(Literal "Go go go!")])); Link(Literal "broken link", "brokenURL")]]],
            "**Go go go!**[broken link](brokenURL)\n\n", "strong and link tag"
        );
        (
            [CodeBlock("fsharp is cool", FSharp)],
            "```fsharp\nfsharp is cool\n```", "codeblock, noninline"
        );
        (*
        (
            [Quote([FrmtedString(Literal "fsharp is cool")])],
            "\`fsharp is cool\`", "quote"
        );
        *)
    ]

[<Tests>]
let bodyTableTests =
    makeExpectoTestList id id mdTable "body table tests" [
        (
            [PCells([CellLine([FrmtedString(Literal "head")], true, NoAlign)], true)],
            "|head|\n|---|\n\n", "one thead only"
        );
        (
            [PCells([CellLine([FrmtedString(Literal "head")], true, Left);CellLine([FrmtedString(Literal "head")], true, Right)], true)],
            "|head|head|\n|:---|---:|\n\n", "two theads with different align"
        );
    ]


[<Tests>]
let listTests =
    makeExpectoTestList id id mdList "list tests" [
        (
            {ListType=OL 1;ListItem=[StringItem[FrmtedString(Literal "first")]];Depth=1},
            "1. first\n", "ol, 1 li"
        );
        (
            {ListType=UL;ListItem=[StringItem[FrmtedString(Literal "first")]];Depth=1},
            "- first\n", "ul, 1 li"
        );
        (
            {ListType=UL;ListItem=
            [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")] ];Depth=1;},
            "- first\n- second\n", "ul, 2 li"
        );
        (
            {ListType=OL 1;ListItem=
            [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")] ];Depth=1;},
            "1. first\n2. second\n", "ol, 2 li"
        );
        (
            {ListType=OL 1;ListItem=
            [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")];NestedList{ListType=UL;ListItem=
                [StringItem[FrmtedString(Literal "third")]; StringItem[FrmtedString(Literal "fourth")] ];Depth=2}  ];Depth=1},
            "1. first\n2. second\n\t- third\n\t- fourth\n", "ol, 2 li, nested 1 ul"
        );
        (
            {ListType=UL;ListItem=
            [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")];
                NestedList{ListType=OL 1;ListItem=
                [StringItem[FrmtedString(Literal "third")]; StringItem[FrmtedString(Literal "fourth")] ];Depth=2} ];
            Depth=1},
            "- first\n- second\n\t1. third\n\t2. fourth\n", "ol inside ul"
        );
    ]

[<Tests>]
let headerTests =
    makeExpectoTestList id id mdHeader "header tests" [
        (
            {HeaderName=[FrmtedString(Literal "header")]; Level=1},
            "# header\n", "h1"
        );
        (
            {HeaderName=[FrmtedString(Literal "header")]; Level=2},
            "## header\n", "h2"
        );
    ]

(*
[<Tests>]
let inlineFootnoteTests =
    makeExpectoTestList id id mdInlineFootnote "inline footnote tests" [
        (
            3,
            "<sup><a href=\"#footnote3\">3</a></sup>", "footer3"
        );
    ]
*)
[<Tests>]
let fullBodyTests =
    makeExpectoTestList id catStr mdBody "full body tests" [
        (
            [
                Header({HeaderName=[FrmtedString(Literal "header")]; Level=1},"HEADER STRING NOT IMPLEMENTED");
                List{ListType=UL;ListItem=
                    [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")];
                        NestedList{ListType=OL 1;ListItem=
                        [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")] ];
                        Depth=2} ];
                    Depth=1};
                Table[PCells([CellLine([FrmtedString(Literal "head")], true, Left);CellLine([FrmtedString(Literal "head")], true, Right)], true)];
                Paragraph[[FrmtedString((Literal "Go go go!")); Link(Literal "broken link", "brokenURL")]; [FrmtedString(Literal "Come!")]]
            ],
            ["# header\n";
            "- first\n- second\n\t1. first\n\t2. second\n\n";
            "|head|head|\n|:---|---:|\n\n";
            "Go go go![broken link](brokenURL)Come!\n\n"]
            , "the bodyshop"
        );
    ]