/
marked-spec.js
103 lines (74 loc) · 2.82 KB
/
marked-spec.js
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
/**
* Marked does not have a custom markdown specification. However, there are times
* when we come across use cases that are not defined in a given specification.
* Therefore, we will put use cases together to illustrate those instances to
* consumers of marked.
*
*/
var marked = require('../../../lib/marked.js');
var markedSpec = require('./marked.json');
var HtmlDiffer = require('@markedjs/html-differ').HtmlDiffer,
htmlDiffer = new HtmlDiffer({ignoreSelfClosingSlash: true});
var since = require('jasmine2-custom-message');
var Messenger = function() {};
Messenger.prototype.message = function(spec, expected, actual) {
return 'CommonMark (' + spec.section + '):\n' + spec.markdown + '\n------\n\nExpected:\n' + expected + '\n------\n\nMarked:\n' + actual;
};
Messenger.prototype.test = function(spec, section, ignore) {
if (spec.section === section) {
var shouldFail = ~ignore.indexOf(spec.example);
it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() {
var expected = spec.html;
var actual = marked(spec.markdown, { headerIds: false, xhtml: true });
since(messenger.message(spec, expected, actual)).expect(
htmlDiffer.isEqual(expected, actual)
).toEqual(!shouldFail);
});
}
};
var messenger = new Messenger();
describe('Marked Autolinks', function() {
var section = 'Autolinks';
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
describe('Marked Code spans', function() {
var section = 'Code spans';
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
describe('Marked Links', function() {
var section = 'Links';
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
describe('Marked Table cells', function() {
var section = 'Table cells';
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
describe('Emphasis extra tests', function() {
var section = 'Emphasis extra tests';
var shouldPassButFails = [];
var willNotBeAttemptedByCoreTeam = [];
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});