|
|
@@ -7,6 +7,10 @@
|
|
7
|
7
|
<style type="text/css">
|
|
8
|
8
|
:root {
|
|
9
|
9
|
font-family: sans-serif;
|
|
|
10
|
+ --color-passed: #090;
|
|
|
11
|
+ --color-failed: #a00;
|
|
|
12
|
+ --color-errored: #a80;
|
|
|
13
|
+ --color-untested: #888;
|
|
10
|
14
|
}
|
|
11
|
15
|
.testclass {
|
|
12
|
16
|
border: 1px solid black;
|
|
|
@@ -19,7 +23,15 @@
|
|
19
|
23
|
font-size: 1.25rem;
|
|
20
|
24
|
padding-bottom: 0.25em;
|
|
21
|
25
|
}
|
|
|
26
|
+ .testclassstatus {
|
|
|
27
|
+
|
|
|
28
|
+ }
|
|
|
29
|
+ .testclassstatus.passed { color: var(--color-passed); }
|
|
|
30
|
+ .testclassstatus.failed { color: var(--color-failed); }
|
|
|
31
|
+ .testclassstatus.errored { color: var(--color-errored); }
|
|
|
32
|
+ .testclassstatus.untested { color: var(--color-untested); }
|
|
22
|
33
|
.testcase {
|
|
|
34
|
+ clear: both;
|
|
23
|
35
|
padding: 0.2em 0;
|
|
24
|
36
|
margin-left: 2em;
|
|
25
|
37
|
}
|
|
|
@@ -27,11 +39,23 @@
|
|
27
|
39
|
border-top: 1px solid #888;
|
|
28
|
40
|
}
|
|
29
|
41
|
.testcasename {
|
|
30
|
|
- font-size: 115%;
|
|
31
|
|
- font-weight: bold;
|
|
|
42
|
+ font-family: monospace;
|
|
32
|
43
|
}
|
|
33
|
44
|
.testcasestatus {
|
|
34
|
45
|
font-weight: bold;
|
|
|
46
|
+ font-size: 80%;
|
|
|
47
|
+ float: left;
|
|
|
48
|
+ }
|
|
|
49
|
+ .testcasetiming {
|
|
|
50
|
+ float: right;
|
|
|
51
|
+ color: #888;
|
|
|
52
|
+ font-size: 80%;
|
|
|
53
|
+ }
|
|
|
54
|
+ .testcaseresult {
|
|
|
55
|
+ height: 1em;
|
|
|
56
|
+ }
|
|
|
57
|
+ .testcasemessage {
|
|
|
58
|
+ clear: both;
|
|
35
|
59
|
}
|
|
36
|
60
|
.result-untested {
|
|
37
|
61
|
color: #888;
|
|
|
@@ -99,7 +123,7 @@
|
|
99
|
123
|
if (test) this.fail(failMessage || `expected false, got ${test}`);
|
|
100
|
124
|
}
|
|
101
|
125
|
assertEqual(a, b, failMessage=null) {
|
|
102
|
|
- if (a == b) return;
|
|
|
126
|
+ if (MDUtils.equal(a, b)) return;
|
|
103
|
127
|
const aVal = `${a}`;
|
|
104
|
128
|
const bVal = `${b}`;
|
|
105
|
129
|
if (aVal.length > 20 || bVal.length > 20) {
|
|
|
@@ -145,6 +169,7 @@
|
|
145
|
169
|
/** @var {String|null} */
|
|
146
|
170
|
message = null;
|
|
147
|
171
|
expectedError = null;
|
|
|
172
|
+ duration = null;
|
|
148
|
173
|
/** @var {String} */
|
|
149
|
174
|
get className() { return this.#objectUnderTest.constructor.name; }
|
|
150
|
175
|
/** @var {String} */
|
|
|
@@ -159,14 +184,25 @@
|
|
159
|
184
|
this.uniqueId = TestCaseRunner.#nextUniqueId++;
|
|
160
|
185
|
}
|
|
161
|
186
|
run() {
|
|
|
187
|
+ var start;
|
|
|
188
|
+ this.expectedError = null;
|
|
|
189
|
+ this.#objectUnderTest.currentRunner = this;
|
|
162
|
190
|
try {
|
|
163
|
|
- this.expectedError = null;
|
|
164
|
|
- this.#objectUnderTest.currentRunner = this;
|
|
165
|
191
|
this.#objectUnderTest.setUp();
|
|
|
192
|
+ } catch (e) {
|
|
|
193
|
+ console.error(`Failed to run ${this.className}.setUp() - ${e.message}`);
|
|
|
194
|
+ this.result = ResultType.errored;
|
|
|
195
|
+ this.message = e.message;
|
|
|
196
|
+ return;
|
|
|
197
|
+ }
|
|
|
198
|
+ try {
|
|
|
199
|
+ start = performance.now();
|
|
166
|
200
|
this.#method.bind(this.#objectUnderTest)();
|
|
|
201
|
+ this.duration = performance.now() - start;
|
|
167
|
202
|
this.result = ResultType.passed;
|
|
168
|
203
|
this.message = null;
|
|
169
|
204
|
} catch (e) {
|
|
|
205
|
+ this.duration = performance.now() - start;
|
|
170
|
206
|
if (e instanceof FailureError) {
|
|
171
|
207
|
this.result = ResultType.failed;
|
|
172
|
208
|
this.message = e.message;
|
|
|
@@ -202,25 +238,31 @@
|
|
202
|
238
|
toHTML() {
|
|
203
|
239
|
var html = `<div class="testcase" id="${this.#cssId}">`;
|
|
204
|
240
|
html += `<div class="testcasename"><span class="testcasemethod">${this.methodName}</span></div>`;
|
|
|
241
|
+ html += '<div class="testcaseresult">';
|
|
205
|
242
|
switch (this.result) {
|
|
206
|
243
|
case ResultType.untested:
|
|
207
|
244
|
html += '<div class="testcasestatus result-untested">Waiting to test</div>';
|
|
208
|
245
|
break;
|
|
209
|
246
|
case ResultType.testing:
|
|
210
|
|
- html += '<div class="testcasestatus result-tesitng">Testing...</div>';
|
|
|
247
|
+ html += '<div class="testcasestatus result-testing">Testing...</div>';
|
|
211
|
248
|
break;
|
|
212
|
249
|
case ResultType.passed:
|
|
213
|
250
|
html += '<div class="testcasestatus result-passed">Passed</div>';
|
|
214
|
251
|
break;
|
|
215
|
252
|
case ResultType.failed:
|
|
216
|
253
|
html += '<div class="testcasestatus result-failed">Failed</div>';
|
|
217
|
|
- html += `<div class="testcasemessage">${escapeHTML(this.message)}</div>`;
|
|
218
|
254
|
break;
|
|
219
|
255
|
case ResultType.errored:
|
|
220
|
256
|
html += '<div class="testcasestatus result-errored">Errored</div>';
|
|
221
|
|
- html += `<div class="testcasemessage">${escapeHTML(this.message)}</div>`;
|
|
222
|
257
|
break;
|
|
223
|
258
|
}
|
|
|
259
|
+ if (this.duration !== null) {
|
|
|
260
|
+ html += `<div class="testcasetiming">${Number(this.duration / 1000.0).toFixed(3)}s</div>`;
|
|
|
261
|
+ }
|
|
|
262
|
+ html += '</div>';
|
|
|
263
|
+ if (this.message !== null) {
|
|
|
264
|
+ html += `<div class="testcasemessage">${escapeHTML(this.message)}</div>`;
|
|
|
265
|
+ }
|
|
224
|
266
|
html += `</div>`;
|
|
225
|
267
|
return html;
|
|
226
|
268
|
}
|
|
|
@@ -273,20 +315,77 @@
|
|
273
|
315
|
this.#uniqueId = TestClassRunner.#nextUniqueId++;
|
|
274
|
316
|
}
|
|
275
|
317
|
get #cssId() { return `testclass${this.#uniqueId}`; }
|
|
|
318
|
+ #summaryHTML() {
|
|
|
319
|
+ var anyTesting = false;
|
|
|
320
|
+ var anyFailed = false;
|
|
|
321
|
+ var anyErrored = false;
|
|
|
322
|
+ var anyUntested = false;
|
|
|
323
|
+ var anyPassed = false;
|
|
|
324
|
+ var allPassed = true;
|
|
|
325
|
+ for (const test of this.testCases) {
|
|
|
326
|
+ switch (test.result) {
|
|
|
327
|
+ case ResultType.untested:
|
|
|
328
|
+ anyUntested = true;
|
|
|
329
|
+ allPassed = false;
|
|
|
330
|
+ break;
|
|
|
331
|
+ case ResultType.testing:
|
|
|
332
|
+ anyTesting = true;
|
|
|
333
|
+ allPassed = false;
|
|
|
334
|
+ break;
|
|
|
335
|
+ case ResultType.passed:
|
|
|
336
|
+ anyPassed = true;
|
|
|
337
|
+ break;
|
|
|
338
|
+ case ResultType.failed:
|
|
|
339
|
+ anyFailed = true;
|
|
|
340
|
+ allPassed = false;
|
|
|
341
|
+ break;
|
|
|
342
|
+ case ResultType.errored:
|
|
|
343
|
+ anyErrored = true;
|
|
|
344
|
+ allPassed = false;
|
|
|
345
|
+ break;
|
|
|
346
|
+ }
|
|
|
347
|
+ }
|
|
|
348
|
+ var html = '';
|
|
|
349
|
+ html += `<summary class="testclasssummary" id="${this.#cssId}summary">`;
|
|
|
350
|
+ html += `<span class="testclassname">${this.#theClass.name}</span> `;
|
|
|
351
|
+ if (anyTesting || (anyUntested && (anyPassed || anyFailed || anyErrored))) {
|
|
|
352
|
+ html += '<span class="testclassstatus testing">Testing...</span>';
|
|
|
353
|
+ } else if (anyErrored) {
|
|
|
354
|
+ html += '<span class="testclassstatus errored">Errored</span>';
|
|
|
355
|
+ } else if (anyFailed) {
|
|
|
356
|
+ html += '<span class="testclassstatus failed">Failed</span>';
|
|
|
357
|
+ } else if (allPassed) {
|
|
|
358
|
+ html += '<span class="testclassstatus passed">Passed</span>';
|
|
|
359
|
+ }
|
|
|
360
|
+ html += '</summary>';
|
|
|
361
|
+ return html;
|
|
|
362
|
+ }
|
|
276
|
363
|
toHTML() {
|
|
277
|
364
|
var html = '';
|
|
278
|
365
|
html += `<div class="testclass" id="${this.#cssId}">`;
|
|
279
|
|
- html += `<div class="testclassname">${this.#theClass.name}</div>`;
|
|
|
366
|
+ html += `<details id="${this.#cssId}details">`;
|
|
|
367
|
+ html += this.#summaryHTML();
|
|
280
|
368
|
for (const testCase of this.#testCases) {
|
|
281
|
369
|
html += testCase.toHTML();
|
|
282
|
370
|
}
|
|
|
371
|
+ html += '</details>';
|
|
283
|
372
|
html += '</div>';
|
|
284
|
373
|
return html;
|
|
285
|
374
|
}
|
|
286
|
375
|
updateHTML() {
|
|
287
|
|
- var existing = document.getElementById(this.#cssId);
|
|
|
376
|
+ var existing = document.getElementById(`${this.#cssId}summary`);
|
|
288
|
377
|
if (!existing) {
|
|
289
|
378
|
document.getElementById('results').innerHTML += this.toHTML();
|
|
|
379
|
+ } else {
|
|
|
380
|
+ existing.outerHTML = this.#summaryHTML();
|
|
|
381
|
+ var allPassed = true;
|
|
|
382
|
+ for (const test of this.testCases) {
|
|
|
383
|
+ if (test.result != ResultType.passed) {
|
|
|
384
|
+ allPassed = false;
|
|
|
385
|
+ break;
|
|
|
386
|
+ }
|
|
|
387
|
+ }
|
|
|
388
|
+ document.getElementById(`${this.#cssId}details`).open = !allPassed;
|
|
290
|
389
|
}
|
|
291
|
390
|
}
|
|
292
|
391
|
|
|
|
@@ -325,6 +424,7 @@
|
|
325
|
424
|
function onLoad() {
|
|
326
|
425
|
let testClasses = [
|
|
327
|
426
|
TokenTests,
|
|
|
427
|
+ UtilsTests,
|
|
328
|
428
|
InlineTests,
|
|
329
|
429
|
BlockTests,
|
|
330
|
430
|
];
|
|
|
@@ -358,7 +458,52 @@
|
|
358
|
458
|
tokens: [ tokens[2] ],
|
|
359
|
459
|
index: 2,
|
|
360
|
460
|
};
|
|
361
|
|
- this.assertEqual(JSON.stringify(result), JSON.stringify(expected));
|
|
|
461
|
+ this.assertEqual(result, expected);
|
|
|
462
|
+ }
|
|
|
463
|
+
|
|
|
464
|
+ test_findFirstTokens_optionalWhitespace1() {
|
|
|
465
|
+ const tokens = [
|
|
|
466
|
+ new MDToken('Lorem', MDTokenType.Text),
|
|
|
467
|
+ new MDToken(' ', MDTokenType.Whitespace),
|
|
|
468
|
+ new MDToken('[ipsum]', MDTokenType.Label, 'ipsum'),
|
|
|
469
|
+ new MDToken('(link.html)', MDTokenType.URL, 'link.html'),
|
|
|
470
|
+ new MDToken(' ', MDTokenType.Whitespace),
|
|
|
471
|
+ new MDToken('dolor', MDTokenType.Text),
|
|
|
472
|
+ ];
|
|
|
473
|
+ const pattern = [
|
|
|
474
|
+ MDTokenType.Label,
|
|
|
475
|
+ MDTokenType.META_OptionalWhitespace,
|
|
|
476
|
+ MDTokenType.URL,
|
|
|
477
|
+ ];
|
|
|
478
|
+ const result = MDToken.findFirstTokens(tokens, pattern);
|
|
|
479
|
+ const expected = {
|
|
|
480
|
+ tokens: [ tokens[2], tokens[3] ],
|
|
|
481
|
+ index: 2,
|
|
|
482
|
+ };
|
|
|
483
|
+ this.assertEqual(result, expected);
|
|
|
484
|
+ }
|
|
|
485
|
+
|
|
|
486
|
+ test_findFirstTokens_optionalWhitespace2() {
|
|
|
487
|
+ const tokens = [
|
|
|
488
|
+ new MDToken('Lorem', MDTokenType.Text),
|
|
|
489
|
+ new MDToken(' ', MDTokenType.Whitespace),
|
|
|
490
|
+ new MDToken('[ipsum]', MDTokenType.Label, 'ipsum'),
|
|
|
491
|
+ new MDToken(' ', MDTokenType.Whitespace),
|
|
|
492
|
+ new MDToken('(link.html)', MDTokenType.URL, 'link.html'),
|
|
|
493
|
+ new MDToken(' ', MDTokenType.Whitespace),
|
|
|
494
|
+ new MDToken('dolor', MDTokenType.Text),
|
|
|
495
|
+ ];
|
|
|
496
|
+ const pattern = [
|
|
|
497
|
+ MDTokenType.Label,
|
|
|
498
|
+ MDTokenType.META_OptionalWhitespace,
|
|
|
499
|
+ MDTokenType.URL,
|
|
|
500
|
+ ];
|
|
|
501
|
+ const result = MDToken.findFirstTokens(tokens, pattern);
|
|
|
502
|
+ const expected = {
|
|
|
503
|
+ tokens: [ tokens[2], tokens[3], tokens[4] ],
|
|
|
504
|
+ index: 2,
|
|
|
505
|
+ };
|
|
|
506
|
+ this.assertEqual(result, expected);
|
|
362
|
507
|
}
|
|
363
|
508
|
|
|
364
|
509
|
test_findPairedTokens() {
|
|
|
@@ -387,7 +532,92 @@
|
|
387
|
532
|
endIndex: 4,
|
|
388
|
533
|
totalLength: 3,
|
|
389
|
534
|
}
|
|
390
|
|
- this.assertEqual(JSON.stringify(result), JSON.stringify(expected));
|
|
|
535
|
+ this.assertEqual(result, expected);
|
|
|
536
|
+ }
|
|
|
537
|
+ }
|
|
|
538
|
+
|
|
|
539
|
+ class UtilsTests extends BaseTest {
|
|
|
540
|
+ test_stripIndent() {
|
|
|
541
|
+ this.assertEqual(MDUtils.stripIndent(''), '');
|
|
|
542
|
+ this.assertEqual(MDUtils.stripIndent(' '), '');
|
|
|
543
|
+ this.assertEqual(MDUtils.stripIndent('foo'), 'foo');
|
|
|
544
|
+ this.assertEqual(MDUtils.stripIndent(' foo'), 'foo');
|
|
|
545
|
+ this.assertEqual(MDUtils.stripIndent(' foo'), 'foo');
|
|
|
546
|
+ this.assertEqual(MDUtils.stripIndent(' foo'), 'foo');
|
|
|
547
|
+ this.assertEqual(MDUtils.stripIndent(' foo'), 'foo');
|
|
|
548
|
+ this.assertEqual(MDUtils.stripIndent(' foo'), ' foo');
|
|
|
549
|
+ this.assertEqual(MDUtils.stripIndent('\tfoo'), 'foo');
|
|
|
550
|
+ this.assertEqual(MDUtils.stripIndent('\t\tfoo'), '\tfoo');
|
|
|
551
|
+ this.assertEqual(MDUtils.stripIndent('\t\tfoo', 2), 'foo');
|
|
|
552
|
+ this.assertEqual(MDUtils.stripIndent(' foo', 2), 'foo');
|
|
|
553
|
+ }
|
|
|
554
|
+
|
|
|
555
|
+ test_countIndents() {
|
|
|
556
|
+ this.assertEqual(MDUtils.countIndents(''), 0);
|
|
|
557
|
+ this.assertEqual(MDUtils.countIndents(' '), 1);
|
|
|
558
|
+ this.assertEqual(MDUtils.countIndents(' '), 1);
|
|
|
559
|
+ this.assertEqual(MDUtils.countIndents('foo'), 0);
|
|
|
560
|
+ this.assertEqual(MDUtils.countIndents('foo'), 0);
|
|
|
561
|
+ this.assertEqual(MDUtils.countIndents(' foo'), 1);
|
|
|
562
|
+ this.assertEqual(MDUtils.countIndents(' foo'), 1);
|
|
|
563
|
+ this.assertEqual(MDUtils.countIndents(' foo'), 1);
|
|
|
564
|
+ this.assertEqual(MDUtils.countIndents(' foo'), 1);
|
|
|
565
|
+ this.assertEqual(MDUtils.countIndents(' foo'), 2);
|
|
|
566
|
+ this.assertEqual(MDUtils.countIndents('\tfoo'), 1);
|
|
|
567
|
+ this.assertEqual(MDUtils.countIndents('\t\tfoo'), 2);
|
|
|
568
|
+
|
|
|
569
|
+ this.assertEqual(MDUtils.countIndents('', true), 0);
|
|
|
570
|
+ this.assertEqual(MDUtils.countIndents(' ', true), 0);
|
|
|
571
|
+ this.assertEqual(MDUtils.countIndents(' ', true), 1);
|
|
|
572
|
+ this.assertEqual(MDUtils.countIndents('foo', true), 0);
|
|
|
573
|
+ this.assertEqual(MDUtils.countIndents(' foo', true), 0);
|
|
|
574
|
+ this.assertEqual(MDUtils.countIndents(' foo', true), 0);
|
|
|
575
|
+ this.assertEqual(MDUtils.countIndents(' foo', true), 0);
|
|
|
576
|
+ this.assertEqual(MDUtils.countIndents(' foo', true), 1);
|
|
|
577
|
+ this.assertEqual(MDUtils.countIndents(' foo', true), 1);
|
|
|
578
|
+ this.assertEqual(MDUtils.countIndents('\tfoo', true), 1);
|
|
|
579
|
+ this.assertEqual(MDUtils.countIndents('\t\tfoo', true), 2);
|
|
|
580
|
+ }
|
|
|
581
|
+
|
|
|
582
|
+ test_tokenizeLabel() {
|
|
|
583
|
+ // Escapes are preserved
|
|
|
584
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo] bar'), [ '[foo]', 'foo' ]);
|
|
|
585
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo\\[] bar'), [ '[foo\\[]', 'foo\\[' ]);
|
|
|
586
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo\\]] bar'), [ '[foo\\]]', 'foo\\]' ]);
|
|
|
587
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo[]] bar'), [ '[foo[]]', 'foo[]' ]);
|
|
|
588
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo\\(] bar'), [ '[foo\\(]', 'foo\\(' ]);
|
|
|
589
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo\\)] bar'), [ '[foo\\)]', 'foo\\)' ]);
|
|
|
590
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo()] bar'), [ '[foo()]', 'foo()' ]);
|
|
|
591
|
+
|
|
|
592
|
+ this.assertEqual(MDUtils.tokenizeLabel('foo bar'), null);
|
|
|
593
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo\\] bar'), null);
|
|
|
594
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo bar'), null);
|
|
|
595
|
+ this.assertEqual(MDUtils.tokenizeLabel('[foo[] bar'), null);
|
|
|
596
|
+ }
|
|
|
597
|
+
|
|
|
598
|
+ test_tokenizeURL() {
|
|
|
599
|
+ this.assertEqual(MDUtils.tokenizeURL('(page.html) foo'), [ '(page.html)', 'page.html', null ]);
|
|
|
600
|
+ this.assertEqual(MDUtils.tokenizeURL('(page.html "link title") foo'), [ '(page.html "link title")', 'page.html', 'link title' ]);
|
|
|
601
|
+ this.assertEqual(MDUtils.tokenizeURL('(https://example.com/path/page.html?query=foo&bar=baz#fragment) foo'), [ '(https://example.com/path/page.html?query=foo&bar=baz#fragment)', 'https://example.com/path/page.html?query=foo&bar=baz#fragment', null ]);
|
|
|
602
|
+
|
|
|
603
|
+ this.assertEqual(MDUtils.tokenizeURL('page.html foo'), null);
|
|
|
604
|
+ this.assertEqual(MDUtils.tokenizeURL('(page.html foo'), null);
|
|
|
605
|
+ this.assertEqual(MDUtils.tokenizeURL('page.html) foo'), null);
|
|
|
606
|
+ this.assertEqual(MDUtils.tokenizeURL('(page.html "title) foo'), null);
|
|
|
607
|
+ this.assertEqual(MDUtils.tokenizeURL('(page .html) foo'), null);
|
|
|
608
|
+ this.assertEqual(MDUtils.tokenizeURL('(user@example.com) foo'), null);
|
|
|
609
|
+ this.assertEqual(MDUtils.tokenizeURL('(user@example.com "title") foo'), null);
|
|
|
610
|
+ }
|
|
|
611
|
+
|
|
|
612
|
+ test_tokenizeEmail() {
|
|
|
613
|
+ this.assertEqual(MDUtils.tokenizeEmail('(user@example.com)'), [ '(user@example.com)', 'user@example.com', null ]);
|
|
|
614
|
+ this.assertEqual(MDUtils.tokenizeEmail('(user@example.com "link title")'), [ '(user@example.com "link title")', 'user@example.com', 'link title' ]);
|
|
|
615
|
+
|
|
|
616
|
+ this.assertEqual(MDUtils.tokenizeEmail('(https://example.com) foo'), null);
|
|
|
617
|
+ this.assertEqual(MDUtils.tokenizeEmail('(https://example.com "link title") foo'), null);
|
|
|
618
|
+ this.assertEqual(MDUtils.tokenizeEmail('(user@example.com "link title) foo'), null);
|
|
|
619
|
+ this.assertEqual(MDUtils.tokenizeEmail('(user@example.com foo'), null);
|
|
|
620
|
+ this.assertEqual(MDUtils.tokenizeEmail('user@example.com) foo'), null);
|
|
391
|
621
|
}
|
|
392
|
622
|
}
|
|
393
|
623
|
|
|
|
@@ -402,129 +632,129 @@
|
|
402
|
632
|
this.parser = Markdown.completeParser;
|
|
403
|
633
|
}
|
|
404
|
634
|
|
|
405
|
|
- test_simpleSingleParagraph() {
|
|
|
635
|
+ test_simpleText() {
|
|
406
|
636
|
let markdown = 'Lorem ipsum';
|
|
407
|
|
- let expected = '<p>Lorem ipsum</p>';
|
|
|
637
|
+ let expected = 'Lorem ipsum';
|
|
408
|
638
|
let actual = this.md(markdown);
|
|
409
|
639
|
this.assertEqual(actual, expected);
|
|
410
|
640
|
}
|
|
411
|
641
|
|
|
412
|
642
|
test_strong() {
|
|
413
|
643
|
let markdown = 'Lorem **ipsum** dolor **sit**';
|
|
414
|
|
- let expected = '<p>Lorem <strong>ipsum</strong> dolor <strong>sit</strong></p>';
|
|
|
644
|
+ let expected = 'Lorem <strong>ipsum</strong> dolor <strong>sit</strong>';
|
|
415
|
645
|
let actual = this.md(markdown);
|
|
416
|
646
|
this.assertEqual(actual, expected);
|
|
417
|
647
|
}
|
|
418
|
648
|
|
|
419
|
649
|
test_emphasis() {
|
|
420
|
650
|
let markdown = 'Lorem _ipsum_ dolor _sit_';
|
|
421
|
|
- let expected = '<p>Lorem <em>ipsum</em> dolor <em>sit</em></p>';
|
|
|
651
|
+ let expected = 'Lorem <em>ipsum</em> dolor <em>sit</em>';
|
|
422
|
652
|
let actual = this.md(markdown);
|
|
423
|
653
|
this.assertEqual(actual, expected);
|
|
424
|
654
|
}
|
|
425
|
655
|
|
|
426
|
656
|
test_strongEmphasis_cleanNesting1() {
|
|
427
|
657
|
let markdown = 'Lorem **ipsum *dolor* sit** amet';
|
|
428
|
|
- let expected = '<p>Lorem <strong>ipsum <em>dolor</em> sit</strong> amet</p>';
|
|
|
658
|
+ let expected = 'Lorem <strong>ipsum <em>dolor</em> sit</strong> amet';
|
|
429
|
659
|
let actual = this.md(markdown);
|
|
430
|
660
|
this.assertEqual(actual, expected);
|
|
431
|
661
|
}
|
|
432
|
662
|
|
|
433
|
663
|
test_strongEmphasis_cleanNesting2() {
|
|
434
|
664
|
let markdown = 'Lorem *ipsum **dolor** sit* amet';
|
|
435
|
|
- let expected = '<p>Lorem <em>ipsum <strong>dolor</strong> sit</em> amet</p>';
|
|
|
665
|
+ let expected = 'Lorem <em>ipsum <strong>dolor</strong> sit</em> amet';
|
|
436
|
666
|
let actual = this.md(markdown);
|
|
437
|
667
|
this.assertEqual(actual, expected);
|
|
438
|
668
|
}
|
|
439
|
669
|
|
|
440
|
670
|
test_strongEmphasis_tightNesting() {
|
|
441
|
671
|
let markdown = 'Lorem ***ipsum*** dolor';
|
|
442
|
|
- let expected1 = '<p>Lorem <strong><em>ipsum</em></strong> dolor</p>';
|
|
443
|
|
- let expected2 = '<p>Lorem <em><strong>ipsum</strong></em> dolor</p>';
|
|
|
672
|
+ let expected1 = 'Lorem <strong><em>ipsum</em></strong> dolor';
|
|
|
673
|
+ let expected2 = 'Lorem <em><strong>ipsum</strong></em> dolor';
|
|
444
|
674
|
let actual = this.md(markdown);
|
|
445
|
675
|
this.assertTrue(actual == expected1 || actual == expected2);
|
|
446
|
676
|
}
|
|
447
|
677
|
|
|
448
|
678
|
test_strongEmphasis_lopsidedNesting1() {
|
|
449
|
679
|
let markdown = 'Lorem ***ipsum* dolor** sit';
|
|
450
|
|
- let expected = '<p>Lorem <strong><em>ipsum</em> dolor</strong> sit</p>';
|
|
|
680
|
+ let expected = 'Lorem <strong><em>ipsum</em> dolor</strong> sit';
|
|
451
|
681
|
let actual = this.md(markdown);
|
|
452
|
682
|
this.assertEqual(actual, expected);
|
|
453
|
683
|
}
|
|
454
|
684
|
|
|
455
|
685
|
test_strongEmphasis_lopsidedNesting2() {
|
|
456
|
686
|
let markdown = 'Lorem ***ipsum** dolor* sit';
|
|
457
|
|
- let expected = '<p>Lorem <em><strong>ipsum</strong> dolor</em> sit</p>';
|
|
|
687
|
+ let expected = 'Lorem <em><strong>ipsum</strong> dolor</em> sit';
|
|
458
|
688
|
let actual = this.md(markdown);
|
|
459
|
689
|
this.assertEqual(actual, expected);
|
|
460
|
690
|
}
|
|
461
|
691
|
|
|
462
|
692
|
test_strongEmphasis_lopsidedNesting3() {
|
|
463
|
693
|
let markdown = 'Lorem **ipsum *dolor*** sit';
|
|
464
|
|
- let expected = '<p>Lorem <strong>ipsum <em>dolor</em></strong> sit</p>';
|
|
|
694
|
+ let expected = 'Lorem <strong>ipsum <em>dolor</em></strong> sit';
|
|
465
|
695
|
let actual = this.md(markdown);
|
|
466
|
696
|
this.assertEqual(actual, expected);
|
|
467
|
697
|
}
|
|
468
|
698
|
|
|
469
|
699
|
test_strongEmphasis_lopsidedNesting4() {
|
|
470
|
700
|
let markdown = 'Lorem *ipsum **dolor*** sit';
|
|
471
|
|
- let expected = '<p>Lorem <em>ipsum <strong>dolor</strong></em> sit</p>';
|
|
|
701
|
+ let expected = 'Lorem <em>ipsum <strong>dolor</strong></em> sit';
|
|
472
|
702
|
let actual = this.md(markdown);
|
|
473
|
703
|
this.assertEqual(actual, expected);
|
|
474
|
704
|
}
|
|
475
|
705
|
|
|
476
|
706
|
test_inlineCode() {
|
|
477
|
707
|
let markdown = 'Lorem `ipsum` dolor';
|
|
478
|
|
- let expected = '<p>Lorem <code>ipsum</code> dolor</p>';
|
|
|
708
|
+ let expected = 'Lorem <code>ipsum</code> dolor';
|
|
479
|
709
|
let actual = this.md(markdown);
|
|
480
|
710
|
this.assertEqual(actual, expected);
|
|
481
|
711
|
}
|
|
482
|
712
|
|
|
483
|
713
|
test_inlineCode_withInnerBacktick() {
|
|
484
|
714
|
let markdown = 'Lorem ``ip`su`m`` dolor';
|
|
485
|
|
- let expected = '<p>Lorem <code>ip`su`m</code> dolor</p>';
|
|
|
715
|
+ let expected = 'Lorem <code>ip`su`m</code> dolor';
|
|
486
|
716
|
let actual = this.md(markdown);
|
|
487
|
717
|
this.assertEqual(actual, expected);
|
|
488
|
718
|
}
|
|
489
|
719
|
|
|
490
|
720
|
test_strikethrough_single() {
|
|
491
|
721
|
let markdown = 'Lorem ~ipsum~ dolor';
|
|
492
|
|
- let expected = '<p>Lorem <strike>ipsum</strike> dolor</p>';
|
|
|
722
|
+ let expected = 'Lorem <strike>ipsum</strike> dolor';
|
|
493
|
723
|
let actual = this.md(markdown);
|
|
494
|
724
|
this.assertEqual(actual, expected);
|
|
495
|
725
|
}
|
|
496
|
726
|
|
|
497
|
727
|
test_strikethrough_double() {
|
|
498
|
728
|
let markdown = 'Lorem ~~ipsum~~ dolor';
|
|
499
|
|
- let expected = '<p>Lorem <strike>ipsum</strike> dolor</p>';
|
|
|
729
|
+ let expected = 'Lorem <strike>ipsum</strike> dolor';
|
|
500
|
730
|
let actual = this.md(markdown);
|
|
501
|
731
|
this.assertEqual(actual, expected);
|
|
502
|
732
|
}
|
|
503
|
733
|
|
|
504
|
734
|
test_link_fullyQualified() {
|
|
505
|
735
|
let markdown = 'Lorem [ipsum](https://example.com/path/page.html) dolor';
|
|
506
|
|
- let expected = '<p>Lorem <a href="https://example.com/path/page.html">ipsum</a> dolor</p>';
|
|
|
736
|
+ let expected = 'Lorem <a href="https://example.com/path/page.html">ipsum</a> dolor';
|
|
507
|
737
|
let actual = this.md(markdown);
|
|
508
|
738
|
this.assertEqual(actual, expected);
|
|
509
|
739
|
}
|
|
510
|
740
|
|
|
511
|
741
|
test_link_relative() {
|
|
512
|
742
|
let markdown = 'Lorem [ipsum](page.html) dolor';
|
|
513
|
|
- let expected = '<p>Lorem <a href="page.html">ipsum</a> dolor</p>';
|
|
|
743
|
+ let expected = 'Lorem <a href="page.html">ipsum</a> dolor';
|
|
514
|
744
|
let actual = this.md(markdown);
|
|
515
|
745
|
this.assertEqual(actual, expected);
|
|
516
|
746
|
}
|
|
517
|
747
|
|
|
518
|
748
|
test_link_title() {
|
|
519
|
749
|
let markdown = 'Lorem [ipsum](page.html "link title") dolor';
|
|
520
|
|
- let expected = '<p>Lorem <a href="page.html" title="link title">ipsum</a> dolor</p>';
|
|
|
750
|
+ let expected = 'Lorem <a href="page.html" title="link title">ipsum</a> dolor';
|
|
521
|
751
|
let actual = this.md(markdown);
|
|
522
|
752
|
this.assertEqual(actual, expected);
|
|
523
|
753
|
}
|
|
524
|
754
|
|
|
525
|
755
|
test_link_literal() {
|
|
526
|
756
|
let markdown = 'Lorem <https://example.com> dolor';
|
|
527
|
|
- let expected = '<p>Lorem <a href="https://example.com">https://example.com</a> dolor</p>';
|
|
|
757
|
+ let expected = 'Lorem <a href="https://example.com">https://example.com</a> dolor';
|
|
528
|
758
|
let actual = this.md(markdown);
|
|
529
|
759
|
this.assertEqual(actual, expected);
|
|
530
|
760
|
}
|
|
|
@@ -538,45 +768,74 @@
|
|
538
|
768
|
|
|
539
|
769
|
test_link_email() {
|
|
540
|
770
|
let markdown = 'Lorem [ipsum](user@example.com) dolor';
|
|
541
|
|
- let expected = '<p>Lorem <a href="mailto:user@example.com">ipsum</a> dolor</p>';
|
|
|
771
|
+ let expected = 'Lorem <a href="mailto:user@example.com">ipsum</a> dolor';
|
|
542
|
772
|
let actual = this.md(markdown);
|
|
543
|
773
|
this.assertEqual(actual, expected);
|
|
544
|
774
|
}
|
|
545
|
775
|
|
|
546
|
776
|
test_link_email_withTitle() {
|
|
547
|
777
|
let markdown = 'Lorem [ipsum](user@example.com "title") dolor';
|
|
548
|
|
- let expected = '<p>Lorem <a href="mailto:user@example.com" title="title">ipsum</a> dolor</p>';
|
|
|
778
|
+ let expected = 'Lorem <a href="mailto:user@example.com" title="title">ipsum</a> dolor';
|
|
549
|
779
|
let actual = this.md(markdown);
|
|
550
|
780
|
this.assertEqual(actual, expected);
|
|
551
|
781
|
}
|
|
552
|
782
|
|
|
553
|
783
|
test_link_literalEmail() {
|
|
554
|
784
|
let markdown = 'Lorem <user@example.com> dolor';
|
|
555
|
|
- let expected = '<p>Lorem <a href="mailto:user@example.com">user@example.com</a> dolor</p>';
|
|
|
785
|
+ let expected = 'Lorem <a href="mailto:user@example.com">user@example.com</a> dolor';
|
|
|
786
|
+ let actual = this.md(markdown);
|
|
|
787
|
+ this.assertEqual(actual, expected);
|
|
|
788
|
+ }
|
|
|
789
|
+
|
|
|
790
|
+ test_link_image() {
|
|
|
791
|
+ let markdown = 'Lorem [](page.html) ipsum';
|
|
|
792
|
+ let expected = 'Lorem <a href="page.html"><img src="image.jpg" alt="alt"></a> ipsum';
|
|
|
793
|
+ let actual = this.md(markdown);
|
|
|
794
|
+ this.assertEqual(actual, expected);
|
|
|
795
|
+ }
|
|
|
796
|
+
|
|
|
797
|
+ test_link_image_complex() {
|
|
|
798
|
+ let markdown = 'Lorem [![alt] (image.jpg "image title")] (page.html "link title") ipsum';
|
|
|
799
|
+ let expected = 'Lorem <a href="page.html" title="link title"><img src="image.jpg" alt="alt" title="image title"></a> ipsum';
|
|
556
|
800
|
let actual = this.md(markdown);
|
|
557
|
801
|
this.assertEqual(actual, expected);
|
|
558
|
802
|
}
|
|
559
|
803
|
|
|
560
|
804
|
test_image() {
|
|
561
|
805
|
let markdown = 'Lorem  dolor';
|
|
562
|
|
- let expected = '<p>Lorem <img src="image.jpg" alt="alt text"> dolor</p>';
|
|
|
806
|
+ let expected = 'Lorem <img src="image.jpg" alt="alt text"> dolor';
|
|
563
|
807
|
let actual = this.md(markdown);
|
|
564
|
808
|
this.assertEqual(actual, expected);
|
|
565
|
809
|
}
|
|
566
|
810
|
|
|
567
|
811
|
test_image_noAlt() {
|
|
568
|
812
|
let markdown = 'Lorem  dolor';
|
|
569
|
|
- let expected = '<p>Lorem <img src="image.jpg"> dolor</p>';
|
|
|
813
|
+ let expected = 'Lorem <img src="image.jpg"> dolor';
|
|
570
|
814
|
let actual = this.md(markdown);
|
|
571
|
815
|
this.assertEqual(actual, expected);
|
|
572
|
816
|
}
|
|
573
|
817
|
|
|
574
|
818
|
test_image_withTitle() {
|
|
575
|
819
|
let markdown = 'Lorem  dolor';
|
|
|
820
|
+ let expected = 'Lorem <img src="image.jpg" alt="alt text" title="image title"> dolor';
|
|
|
821
|
+ let actual = this.md(markdown);
|
|
|
822
|
+ this.assertEqual(actual, expected);
|
|
|
823
|
+ }
|
|
|
824
|
+
|
|
|
825
|
+ test_image_ref() {
|
|
|
826
|
+ let markdown = 'Lorem ![alt text][ref] dolor\n\n' +
|
|
|
827
|
+ '[ref]: image.jpg "image title"';
|
|
576
|
828
|
let expected = '<p>Lorem <img src="image.jpg" alt="alt text" title="image title"> dolor</p>';
|
|
577
|
829
|
let actual = this.md(markdown);
|
|
578
|
830
|
this.assertEqual(actual, expected);
|
|
579
|
831
|
}
|
|
|
832
|
+
|
|
|
833
|
+ test_htmlTags() {
|
|
|
834
|
+ let markdown = 'Lorem <strong title="value" foo=\'with " quote\' bar="with \' apostrophe" attr=unquoted checked>ipsum</strong> dolor';
|
|
|
835
|
+ let expected = markdown;
|
|
|
836
|
+ let actual = this.md(markdown);
|
|
|
837
|
+ this.assertEqual(actual, expected);
|
|
|
838
|
+ }
|
|
580
|
839
|
}
|
|
581
|
840
|
|
|
582
|
841
|
class BlockTests extends BaseTest {
|
|
|
@@ -599,7 +858,35 @@
|
|
599
|
858
|
|
|
600
|
859
|
test_paragraph_lineGrouping() {
|
|
601
|
860
|
let markdown = "Lorem ipsum\ndolor sit amet";
|
|
602
|
|
- let expected = "<p>Lorem ipsum dolor sit amet</p>";
|
|
|
861
|
+ let expected = "Lorem ipsum dolor sit amet";
|
|
|
862
|
+ let actual = this.md(markdown);
|
|
|
863
|
+ this.assertEqual(actual, expected);
|
|
|
864
|
+ }
|
|
|
865
|
+
|
|
|
866
|
+ test_header_underlineH1() {
|
|
|
867
|
+ let markdown = "Header 1\n===\n\nLorem ipsum";
|
|
|
868
|
+ let expected = "<h1>Header 1</h1> <p>Lorem ipsum</p>";
|
|
|
869
|
+ let actual = this.md(markdown);
|
|
|
870
|
+ this.assertEqual(actual, expected);
|
|
|
871
|
+ }
|
|
|
872
|
+
|
|
|
873
|
+ test_header_underlineH2() {
|
|
|
874
|
+ let markdown = "Header 2\n---\n\nLorem ipsum";
|
|
|
875
|
+ let expected = "<h2>Header 2</h2> <p>Lorem ipsum</p>";
|
|
|
876
|
+ let actual = this.md(markdown);
|
|
|
877
|
+ this.assertEqual(actual, expected);
|
|
|
878
|
+ }
|
|
|
879
|
+
|
|
|
880
|
+ test_header_hash() {
|
|
|
881
|
+ let markdown = "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6\n";
|
|
|
882
|
+ let expected = '<h1>Header 1</h1> <h2>Header 2</h2> <h3>Header 3</h3> <h4>Header 4</h4> <h5>Header 5</h5> <h6>Header 6</h6>';
|
|
|
883
|
+ let actual = this.md(markdown);
|
|
|
884
|
+ this.assertEqual(actual, expected);
|
|
|
885
|
+ }
|
|
|
886
|
+
|
|
|
887
|
+ test_header_hash_trailing() {
|
|
|
888
|
+ let markdown = "# Header 1 #\n## Header 2 ##\n### Header 3 ######";
|
|
|
889
|
+ let expected = '<h1>Header 1</h1> <h2>Header 2</h2> <h3>Header 3</h3>';
|
|
603
|
890
|
let actual = this.md(markdown);
|
|
604
|
891
|
this.assertEqual(actual, expected);
|
|
605
|
892
|
}
|
|
|
@@ -611,9 +898,16 @@
|
|
611
|
898
|
this.assertEqual(actual, expected);
|
|
612
|
899
|
}
|
|
613
|
900
|
|
|
|
901
|
+ test_unorderedList_nested() {
|
|
|
902
|
+ let markdown = "* Lorem\n + Ipsum\n* Dolor";
|
|
|
903
|
+ let expected = '<ul> <li>Lorem <ul> <li>Ipsum</li> </ul></li> <li>Dolor</li> </ul>';
|
|
|
904
|
+ let actual = this.md(markdown);
|
|
|
905
|
+ this.assertEqual(actual, expected);
|
|
|
906
|
+ }
|
|
|
907
|
+
|
|
614
|
908
|
test_orderedList() {
|
|
615
|
909
|
let markdown = "1. Lorem\n1. Ipsum\n5. Dolor";
|
|
616
|
|
- let expected = '<ol start="1"> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
|
|
|
910
|
+ let expected = '<ol> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
|
|
617
|
911
|
let actual = this.md(markdown);
|
|
618
|
912
|
this.assertEqual(actual, expected);
|
|
619
|
913
|
}
|
|
|
@@ -625,9 +919,182 @@
|
|
625
|
919
|
this.assertEqual(actual, expected);
|
|
626
|
920
|
}
|
|
627
|
921
|
|
|
|
922
|
+ test_orderedList_nested1() {
|
|
|
923
|
+ let markdown = "1. Lorem\n 1. Ipsum\n1. Dolor";
|
|
|
924
|
+ let expected = '<ol> <li>Lorem <ol> <li>Ipsum</li> </ol></li> <li>Dolor</li> </ol>';
|
|
|
925
|
+ let actual = this.md(markdown);
|
|
|
926
|
+ this.assertEqual(actual, expected);
|
|
|
927
|
+ }
|
|
|
928
|
+
|
|
|
929
|
+ test_orderedList_nested2() {
|
|
|
930
|
+ let markdown = "1. Lorem\n 1. Ipsum\n 1. Dolor\n 1. Sit\n1. Amet";
|
|
|
931
|
+ let expected = '<ol> <li>Lorem <ol> <li>Ipsum <ol> <li>Dolor</li> </ol></li> <li>Sit</li> </ol></li> <li>Amet</li> </ol>';
|
|
|
932
|
+ let actual = this.md(markdown);
|
|
|
933
|
+ this.assertEqual(actual, expected);
|
|
|
934
|
+ }
|
|
|
935
|
+
|
|
628
|
936
|
test_blockquote() {
|
|
629
|
937
|
let markdown = '> Lorem ipsum dolor';
|
|
630
|
|
- let expected = '<blockquote> <p>Lorem ipsum dolor</p> </blockquote>';
|
|
|
938
|
+ let expected = '<blockquote> Lorem ipsum dolor </blockquote>';
|
|
|
939
|
+ let actual = this.md(markdown);
|
|
|
940
|
+ this.assertEqual(actual, expected);
|
|
|
941
|
+ }
|
|
|
942
|
+
|
|
|
943
|
+ test_blockquote_paragraphs() {
|
|
|
944
|
+ let markdown = '> Lorem ipsum dolor\n>\n>Sit amet';
|
|
|
945
|
+ let expected = '<blockquote> <p>Lorem ipsum dolor</p> <p>Sit amet</p> </blockquote>';
|
|
|
946
|
+ let actual = this.md(markdown);
|
|
|
947
|
+ this.assertEqual(actual, expected);
|
|
|
948
|
+ }
|
|
|
949
|
+
|
|
|
950
|
+ test_blockquote_list() {
|
|
|
951
|
+ let markdown = '> 1. Lorem\n> 2. Ipsum';
|
|
|
952
|
+ let expected = '<blockquote> <ol> <li>Lorem</li> <li>Ipsum</li> </ol> </blockquote>';
|
|
|
953
|
+ let actual = this.md(markdown);
|
|
|
954
|
+ this.assertEqual(actual, expected);
|
|
|
955
|
+ }
|
|
|
956
|
+
|
|
|
957
|
+ test_codeBlock_indented() {
|
|
|
958
|
+ let markdown = "Code\n\n function foo() {\n return 'bar';\n }\n\nend";
|
|
|
959
|
+ let expected = "<p>Code</p>\n\n<pre><code>function foo() {\n return 'bar';\n}</code></pre>\n<p>end</p>\n";
|
|
|
960
|
+ let actual = this.parser.toHTML(markdown); // don't normalize whitespace
|
|
|
961
|
+ this.assertEqual(actual.replace(/ /g, '⎵'), expected.replace(/ /g, '⎵'));
|
|
|
962
|
+ }
|
|
|
963
|
+
|
|
|
964
|
+ test_codeBlock_fenced() {
|
|
|
965
|
+ let markdown = "Code\n\n```\nfunction foo() {\n return 'bar';\n}\n```\n\nend";
|
|
|
966
|
+ let expected = "<p>Code</p>\n\n<pre><code>function foo() {\n return 'bar';\n}</code></pre>\n<p>end</p>\n";
|
|
|
967
|
+ let actual = this.parser.toHTML(markdown); // don't normalize whitespace
|
|
|
968
|
+ this.assertEqual(actual.replace(/ /g, '⎵'), expected.replace(/ /g, '⎵'));
|
|
|
969
|
+ }
|
|
|
970
|
+
|
|
|
971
|
+ test_horizontalRule() {
|
|
|
972
|
+ let markdown = "Before\n\n---\n\n- - -\n\n***\n\n* * * * * * *\n\nafter";
|
|
|
973
|
+ let expected = "<p>Before</p> <hr> <hr> <hr> <hr> <p>after</p>";
|
|
|
974
|
+ let actual = this.md(markdown);
|
|
|
975
|
+ this.assertEqual(actual, expected);
|
|
|
976
|
+ }
|
|
|
977
|
+
|
|
|
978
|
+ test_table_unfenced() {
|
|
|
979
|
+ let markdown = "Column A | Column B | Column C\n--- | --- | ---\n1 | 2 | 3\n4 | 5 | 6";
|
|
|
980
|
+ let expected = "<table> <thead> <tr> <th>Column A</th> <th>Column B</th> <th>Column C</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> </tbody> </table>";
|
|
|
981
|
+ let actual = this.md(markdown);
|
|
|
982
|
+ this.assertEqual(actual, expected);
|
|
|
983
|
+ }
|
|
|
984
|
+
|
|
|
985
|
+ test_table_fenced() {
|
|
|
986
|
+ let markdown = "| Column A | Column B | Column C |\n| --- | --- | --- |\n| 1 | 2 | 3\n4 | 5 | 6 |";
|
|
|
987
|
+ let expected = "<table> <thead> <tr> <th>Column A</th> <th>Column B</th> <th>Column C</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> </tbody> </table>";
|
|
|
988
|
+ let actual = this.md(markdown);
|
|
|
989
|
+ this.assertEqual(actual, expected);
|
|
|
990
|
+ }
|
|
|
991
|
+
|
|
|
992
|
+ test_table_alignment() {
|
|
|
993
|
+ let markdown = 'Column A | Column B | Column C\n' +
|
|
|
994
|
+ ':--- | :---: | ---:\n' +
|
|
|
995
|
+ '1 | 2 | 3\n' +
|
|
|
996
|
+ '4 | 5 | 6';
|
|
|
997
|
+ let expected = '<table> ' +
|
|
|
998
|
+ '<thead> ' +
|
|
|
999
|
+ '<tr> ' +
|
|
|
1000
|
+ '<th align="left">Column A</th> ' +
|
|
|
1001
|
+ '<th align="center">Column B</th> ' +
|
|
|
1002
|
+ '<th align="right">Column C</th> ' +
|
|
|
1003
|
+ '</tr> ' +
|
|
|
1004
|
+ '</thead> ' +
|
|
|
1005
|
+ '<tbody> ' +
|
|
|
1006
|
+ '<tr> ' +
|
|
|
1007
|
+ '<td align="left">1</td> ' +
|
|
|
1008
|
+ '<td align="center">2</td> ' +
|
|
|
1009
|
+ '<td align="right">3</td> ' +
|
|
|
1010
|
+ '</tr> ' +
|
|
|
1011
|
+ '<tr> ' +
|
|
|
1012
|
+ '<td align="left">4</td> ' +
|
|
|
1013
|
+ '<td align="center">5</td> ' +
|
|
|
1014
|
+ '<td align="right">6</td> ' +
|
|
|
1015
|
+ '</tr> ' +
|
|
|
1016
|
+ '</tbody> ' +
|
|
|
1017
|
+ '</table>';
|
|
|
1018
|
+ let actual = this.md(markdown);
|
|
|
1019
|
+ this.assertEqual(actual, expected);
|
|
|
1020
|
+ }
|
|
|
1021
|
+
|
|
|
1022
|
+ test_table_holes() {
|
|
|
1023
|
+ let markdown = 'Column A||Column C\n' +
|
|
|
1024
|
+ '---|---|---\n' +
|
|
|
1025
|
+ '|1|2||\n' +
|
|
|
1026
|
+ '|4||6|\n' +
|
|
|
1027
|
+ '||8|9|';
|
|
|
1028
|
+ let expected = '<table> ' +
|
|
|
1029
|
+ '<thead> ' +
|
|
|
1030
|
+ '<tr> ' +
|
|
|
1031
|
+ '<th>Column A</th> ' +
|
|
|
1032
|
+ '<th></th> ' +
|
|
|
1033
|
+ '<th>Column C</th> ' +
|
|
|
1034
|
+ '</tr> ' +
|
|
|
1035
|
+ '</thead> ' +
|
|
|
1036
|
+ '<tbody> ' +
|
|
|
1037
|
+ '<tr> ' +
|
|
|
1038
|
+ '<td>1</td> ' +
|
|
|
1039
|
+ '<td>2</td> ' +
|
|
|
1040
|
+ '<td></td> ' +
|
|
|
1041
|
+ '</tr> ' +
|
|
|
1042
|
+ '<tr> ' +
|
|
|
1043
|
+ '<td>4</td> ' +
|
|
|
1044
|
+ '<td></td> ' +
|
|
|
1045
|
+ '<td>6</td> ' +
|
|
|
1046
|
+ '</tr> ' +
|
|
|
1047
|
+ '<tr> ' +
|
|
|
1048
|
+ '<td></td> ' +
|
|
|
1049
|
+ '<td>8</td> ' +
|
|
|
1050
|
+ '<td>9</td> ' +
|
|
|
1051
|
+ '</tr> ' +
|
|
|
1052
|
+ '</tbody> ' +
|
|
|
1053
|
+ '</table>';
|
|
|
1054
|
+ let actual = this.md(markdown);
|
|
|
1055
|
+ this.assertEqual(actual, expected);
|
|
|
1056
|
+ }
|
|
|
1057
|
+
|
|
|
1058
|
+ test_definitionList() {
|
|
|
1059
|
+ let markdown = 'term\n' +
|
|
|
1060
|
+ ': definition\n' +
|
|
|
1061
|
+ 'another' +
|
|
|
1062
|
+ ' term\n' +
|
|
|
1063
|
+ ': def 1\n' +
|
|
|
1064
|
+ ' broken on next line\n' +
|
|
|
1065
|
+ ': def 2';
|
|
|
1066
|
+ let expected = '<dl> ' +
|
|
|
1067
|
+ '<dt>term</dt> ' +
|
|
|
1068
|
+ '<dd>definition</dd> ' +
|
|
|
1069
|
+ '<dt>another term</dt> ' +
|
|
|
1070
|
+ '<dd>def 1 broken on next line</dd> ' +
|
|
|
1071
|
+ '<dd>def 2</dd> ' +
|
|
|
1072
|
+ '</dl>';
|
|
|
1073
|
+ let actual = this.md(markdown);
|
|
|
1074
|
+ this.assertEqual(actual, expected);
|
|
|
1075
|
+ }
|
|
|
1076
|
+
|
|
|
1077
|
+ test_footnotes() {
|
|
|
1078
|
+ let markdown = 'Lorem ipsum[^1] dolor[^2] sit[^1] amet\n\n[^1]: A footnote\n[^2]: Another footnote';
|
|
|
1079
|
+ let expected = '<p>Lorem ipsum<sup id="footnoteref_1"><a href="#footnote_1">1</a></sup> ' +
|
|
|
1080
|
+ 'dolor<sup id="footnoteref_2"><a href="#footnote_2">2</a></sup> ' +
|
|
|
1081
|
+ 'sit<sup id="footnoteref_3"><a href="#footnote_1">1</a></sup> amet</p> ' +
|
|
|
1082
|
+ '<div class="footnotes">' +
|
|
|
1083
|
+ '<hr/>' +
|
|
|
1084
|
+ '<ol>' +
|
|
|
1085
|
+ '<li value="1" id="footnote_1">A footnote <a href="#footnoteref_1" class="footnote-backref">↩︎</a> <a href="#footnoteref_3" class="footnote-backref">↩︎</a></li> ' +
|
|
|
1086
|
+ '<li value="2" id="footnote_2">Another footnote <a href="#footnoteref_2" class="footnote-backref">↩︎</a></li> ' +
|
|
|
1087
|
+ '</ol>' +
|
|
|
1088
|
+ '</div>';
|
|
|
1089
|
+ let actual = this.md(markdown);
|
|
|
1090
|
+ this.assertEqual(actual, expected);
|
|
|
1091
|
+ }
|
|
|
1092
|
+
|
|
|
1093
|
+ test_abbreviations() {
|
|
|
1094
|
+ let markdown = 'Lorem ipsum HTML dolor HTML sit\n' +
|
|
|
1095
|
+ '\n' +
|
|
|
1096
|
+ '*[HTML]: Hypertext Markup Language';
|
|
|
1097
|
+ let expected = '<p>Lorem ipsum <abbr title="Hypertext Markup Language">HTML</abbr> dolor <abbr title="Hypertext Markup Language">HTML</abbr> sit</p>';
|
|
631
|
1098
|
let actual = this.md(markdown);
|
|
632
|
1099
|
this.assertEqual(actual, expected);
|
|
633
|
1100
|
}
|