-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathMarkdownHtmlTests.cs
More file actions
304 lines (251 loc) · 7.06 KB
/
MarkdownHtmlTests.cs
File metadata and controls
304 lines (251 loc) · 7.06 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Waher.Content.Emoji.Emoji1;
using Waher.Runtime.Console;
using Waher.Runtime.IO;
using Waher.Runtime.Text;
namespace Waher.Content.Markdown.Test
{
[TestClass]
public class MarkdownHtmlTests
{
private static async Task DoTest(string MarkdownFileName, string HtmlFileName)
{
string Markdown = await Files.ReadAllTextAsync("Markdown/Syntax/" + MarkdownFileName);
string ExpectedHtml = await Files.ReadAllTextAsync("HTML/" + HtmlFileName);
Emoji1LocalFiles Emoji1LocalFiles = new(Emoji1SourceFileType.Svg, 24, 24, "/emoji1/%FILENAME%", Path.Combine("Graphics", "Emoji1.zip"), "Graphics");
MarkdownSettings Settings = new(Emoji1LocalFiles, true, [])
{
HttpxProxy = "/HttpxProxy/%URL%"
};
Assert.IsTrue(Emoji1LocalFiles.WaitUntilInitialized(60000));
MarkdownDocument Doc = await MarkdownDocument.CreateAsync(Markdown, Settings);
string GeneratedHtml = await Doc.GenerateHTML();
ConsoleOut.WriteLine(GeneratedHtml);
ConsoleOut.WriteLine();
ConsoleOut.WriteLine();
ConsoleOut.WriteLine();
AssertEqual(ExpectedHtml, GeneratedHtml, "Generated HTML does not match expected HTML.");
}
public static void AssertEqual(string Expected, string Generated, string Message)
{
Generated = RemoveGuids(Generated);
Expected = RemoveGuids(Expected);
if (Generated != Expected)
{
StringBuilder sb = new();
sb.AppendLine(Message);
sb.AppendLine();
sb.AppendLine("Changes required:");
sb.AppendLine();
EditScript<string> Script = Difference.AnalyzeRows(Generated, Expected);
foreach (Step<string> Op in Script.Steps)
{
foreach (string Row in Op.Symbols)
{
switch (Op.Operation)
{
case EditOperation.Delete:
sb.Append("- ");
sb.AppendLine(Row);
break;
case EditOperation.Insert:
sb.Append("+ ");
sb.AppendLine(Row);
break;
}
}
}
throw new Exception(sb.ToString());
}
}
private static string RemoveGuids(string s)
{
string s2;
int i = 0;
s = s.Replace("\r\n", "\n").Replace('\r', '\n');
foreach (Match M in guids.Matches(s))
{
s2 = "GUID" + (++i).ToString();
s2 += new string('_', 36 - s2.Length);
s = s.Remove(M.Index, 36).Insert(M.Index, s2);
}
return s;
}
private readonly static Regex guids = new(@"[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){4}[0-9a-fA-F]{8}", RegexOptions.Multiline | RegexOptions.Compiled);
[TestMethod]
public async Task Test_01_Paragraphs()
{
await DoTest("Test_01_Paragraphs.md", "Test_01_Paragraphs.html");
}
[TestMethod]
public async Task Test_02_Links()
{
await DoTest("Test_02_Links.md", "Test_02_Links.html");
}
[TestMethod]
public async Task Test_03_TextFormatting()
{
await DoTest("Test_03_TextFormatting.md", "Test_03_TextFormatting.html");
}
[TestMethod]
public async Task Test_04_Multimedia()
{
await DoTest("Test_04_Multimedia.md", "Test_04_Multimedia.html");
}
[TestMethod]
public async Task Test_05_HTML()
{
await DoTest("Test_05_HTML.md", "Test_05_HTML.html");
}
[TestMethod]
public async Task Test_06_CodeBlocks()
{
await DoTest("Test_06_CodeBlocks.md", "Test_06_CodeBlocks.html");
}
[TestMethod]
public async Task Test_07_BlockQuotes()
{
await DoTest("Test_07_BlockQuotes.md", "Test_07_BlockQuotes.html");
}
[TestMethod]
public async Task Test_08_Headers()
{
await DoTest("Test_08_Headers.md", "Test_08_Headers.html");
}
[TestMethod]
public async Task Test_09_UnorderedLists()
{
await DoTest("Test_09_UnorderedLists.md", "Test_09_UnorderedLists.html");
}
[TestMethod]
public async Task Test_10_LazyOrderedLists()
{
await DoTest("Test_10_LazyOrderedLists.md", "Test_10_LazyOrderedLists.html");
}
[TestMethod]
public async Task Test_11_OrderedLists()
{
await DoTest("Test_11_OrderedLists.md", "Test_11_OrderedLists.html");
}
[TestMethod]
public async Task Test_12_Typography()
{
await DoTest("Test_12_Typography.md", "Test_12_Typography.html");
}
[TestMethod]
public async Task Test_13_Tables()
{
await DoTest("Test_13_Tables.md", "Test_13_Tables.html");
}
[TestMethod]
public async Task Test_14_HorizontalRules()
{
await DoTest("Test_14_HorizontalRules.md", "Test_14_HorizontalRules.html");
}
[TestMethod]
public async Task Test_15_DefinitionLists()
{
await DoTest("Test_15_DefinitionLists.md", "Test_15_DefinitionLists.html");
}
[TestMethod]
public async Task Test_16_MetaData()
{
await DoTest("Test_16_MetaData.md", "Test_16_MetaData.html");
}
[TestMethod]
public async Task Test_17_Footnotes()
{
await DoTest("Test_17_Footnotes.md", "Test_17_Footnotes.html");
}
[TestMethod]
public async Task Test_18_Emojis()
{
await DoTest("Test_18_Emojis.md", "Test_18_Emojis.html");
}
[TestMethod]
public async Task Test_19_Sections()
{
await DoTest("Test_19_Sections.md", "Test_19_Sections.html");
}
[TestMethod]
public async Task Test_20_Script()
{
await DoTest("Test_20_Script.md", "Test_20_Script.html");
}
[TestMethod]
public async Task Test_21_Httpx()
{
await DoTest("Test_21_Httpx.md", "Test_21_Httpx.html");
}
[TestMethod]
public async Task Test_22_TaskLists()
{
await DoTest("Test_22_TaskLists.md", "Test_22_TaskLists.html");
}
[TestMethod]
public async Task Test_23_Superscript()
{
await DoTest("Test_23_Superscript.md", "Test_23_Superscript.html");
}
[TestMethod]
public async Task Test_24_Subscript()
{
await DoTest("Test_24_Subscript.md", "Test_24_Subscript.html");
}
[TestMethod]
public async Task Test_25_HashTags()
{
await DoTest("Test_25_HashTags.md", "Test_25_HashTags.html");
}
[TestMethod]
public async Task Test_26_Comments()
{
await DoTest("Test_26_Comments.md", "Test_26_Comments.html");
}
[TestMethod]
public async Task Test_27_Contract()
{
await DoTest("Test_27_Contract.md", "Test_27_Contract.html");
}
[TestMethod]
public async Task Test_28_Nesting()
{
await DoTest("Test_28_Nesting.md", "Test_28_Nesting.html");
}
[TestMethod]
public async Task Test_29_Justification()
{
await DoTest("Test_29_Justification.md", "Test_29_Justification.html");
}
[TestMethod]
public async Task Test_30_Incomplete()
{
await DoTest("Test_30_Incomplete.md", "Test_30_Incomplete.html");
}
[TestMethod]
public async Task Test_31_Justification2()
{
await DoTest("Test_31_Justification2.md", "Test_31_Justification2.html");
}
[TestMethod]
public async Task Test_32_TablesAndNotes()
{
await DoTest("Test_32_TablesAndNotes.md", "Test_32_TablesAndNotes.html");
}
[TestMethod]
public async Task Test_33_SingleNoHeaderTable()
{
await DoTest("Test_33_SingleNoHeaderTable.md", "Test_33_SingleNoHeaderTable.html");
}
[TestMethod]
public async Task Test_34_SpecifiedViewportHeader()
{
await DoTest("Test_34_SpecifiedViewportHeader.md", "Test_34_SpecifiedViewportHeader.html");
}
}
}