Skip to content

Commit 6f02738

Browse files
authored
Merge pull request markedjs#1210 from 8fold/gfm-test-bed
GitHub Flavored Markdown test bed
2 parents 9271a66 + dfe340b commit 6f02738

File tree

3 files changed

+250
-0
lines changed

3 files changed

+250
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"test": "jasmine --config=jasmine.json",
4444
"test:unit": "npm test -- test/unit/**/*-spec.js",
4545
"test:specs": "npm test -- test/specs/**/*-spec.js",
46+
"test:gfm": "npm test -- test/specs/gfm/**/*-spec.js",
4647
"test:integration": "npm test -- test/integration/**/*-spec.js",
4748
"test:old": "node test",
4849
"test:lint": "eslint bin/marked .",

test/specs/gfm/gfm-spec.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var marked = require('../../../lib/marked.js');
2+
var gfmSpec = require('./gfm.0.28.json')
3+
var HtmlDiffer = require('html-differ').HtmlDiffer,
4+
htmlDiffer = new HtmlDiffer();
5+
var since = require('jasmine2-custom-message');
6+
7+
var Messenger = function() {}
8+
9+
Messenger.prototype.message = function(spec, expected, actual) {
10+
return 'CommonMark (' + spec.section + '):\n' + spec.markdown + '\n------\n\nExpected:\n' + expected + '\n------\n\nMarked:\n' + actual;
11+
}
12+
13+
Messenger.prototype.test = function(spec, section, ignore) {
14+
if (spec.section === section && ignore.indexOf(spec.example) < 0) {
15+
var shouldFail = ~ignore.indexOf(spec.example);
16+
it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() {
17+
var expected = spec.html;
18+
var actual = marked(spec.markdown, { headerIds: false, xhtml: true });
19+
since(messenger.message(spec, expected, actual)).expect(
20+
htmlDiffer.isEqual(expected, actual)
21+
).toEqual(!shouldFail);
22+
});
23+
}
24+
}
25+
26+
var messenger = new Messenger();
27+
28+
describe('GFM 0.28 Tables', function() {
29+
var section = 'Tables';
30+
31+
// TODO: Verify exmaple 193 is valid and passing
32+
var shouldPassButFails = [192, 193, 195, 196, 197];
33+
34+
var willNotBeAttemptedByCoreTeam = [];
35+
36+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
37+
38+
gfmSpec.forEach(function(spec) {
39+
messenger.test(spec, section, ignore);
40+
});
41+
});
42+
43+
describe('GFM 0.28 Task list items', function() {
44+
var section = 'Task list items';
45+
46+
var shouldPassButFails = [272, 273];
47+
48+
var willNotBeAttemptedByCoreTeam = [];
49+
50+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
51+
52+
gfmSpec.forEach(function(spec) {
53+
messenger.test(spec, section, ignore);
54+
});
55+
});
56+
57+
describe('GFM 0.28 Strikethrough', function() {
58+
var section = 'Strikethrough';
59+
60+
var shouldPassButFails = [469, 470];
61+
62+
var willNotBeAttemptedByCoreTeam = [];
63+
64+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
65+
66+
gfmSpec.forEach(function(spec) {
67+
messenger.test(spec, section, ignore);
68+
});
69+
});
70+
71+
describe('GFM 0.28 Autolinks', function() {
72+
var section = 'Autolinks';
73+
74+
var shouldPassButFails = [607];
75+
76+
var willNotBeAttemptedByCoreTeam = [];
77+
78+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
79+
80+
gfmSpec.forEach(function(spec) {
81+
messenger.test(spec, section, ignore);
82+
});
83+
});
84+
85+
describe('GFM 0.28 Disallowed Raw HTML', function() {
86+
var section = 'Disallowed Raw HTML';
87+
88+
var shouldPassButFails = [629];
89+
90+
var willNotBeAttemptedByCoreTeam = [];
91+
92+
var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);
93+
94+
gfmSpec.forEach(function(spec) {
95+
messenger.test(spec, section, ignore);
96+
});
97+
});

test/specs/gfm/gfm.0.28.json

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
[
2+
{
3+
"section": "Tables",
4+
"html": "<table>\n<thead>\n<tr>\n<th>foo</th>\n<th>bar</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>baz</td>\n<td>bim</td>\n</tr></tbody></table>",
5+
"markdown": "| foo | bar |\n| --- | --- |\n| baz | bim |",
6+
"example": 191
7+
},
8+
{
9+
"section": "Tables",
10+
"html": "<table>\n<thead>\n<tr>\n<th align=\"center\">abc</th>\n<th align=\"right\">defghi</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"center\">bar</td>\n<td align=\"right\">baz</td>\n</tr></tbody></table>",
11+
"markdown": "| abc | defghi |\n:-: | -----------:\nbar | baz",
12+
"example": 192
13+
},
14+
{
15+
"section": "Tables",
16+
"html": "<table>\n<thead>\n<tr>\n<th>f|oo</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>b <code>|</code> az</td>\n</tr>\n<tr>\n<td>b <strong>|</strong> im</td>\n</tr></tbody></table>",
17+
"markdown": "| f\\|oo |\n| ------ |\n| b `\\|` az |\n| b **\\|** im |",
18+
"example": 193
19+
},
20+
{
21+
"section": "Tables",
22+
"html": "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>bar</td>\n<td>baz</td>\n</tr></tbody></table>\n<blockquote>\n<p>bar</p>\n</blockquote>",
23+
"markdown": "| abc | def |\n| --- | --- |\n| bar | baz |\n> bar",
24+
"example": 194
25+
},
26+
{
27+
"section": "Tables",
28+
"html": "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>bar</td>\n<td>baz</td>\n</tr>\n<tr>\n<td>bar</td>\n<td></td>\n</tr></tbody></table>\n<p>bar</p>",
29+
"markdown": "| abc | def |\n| --- | --- |\n| bar | baz |\nbar\n\nbar",
30+
"example": 195
31+
},
32+
{
33+
"section": "Tables",
34+
"html": "<p>| abc | def |\n| --- |\n| bar |</p>",
35+
"markdown": "| abc | def |\n| --- |\n| bar |",
36+
"example": 196
37+
},
38+
{
39+
"section": "Tables",
40+
"html": "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>bar</td>\n<td></td>\n</tr>\n<tr>\n<td>bar</td>\n<td>baz</td>\n</tr></tbody></table>",
41+
"markdown": "| abc | def |\n| --- | --- |\n| bar |\n| bar | baz | boo |",
42+
"example": 197
43+
},
44+
{
45+
"section": "Tables",
46+
"html": "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead></table>",
47+
"markdown": "| abc | def |\n| --- | --- |",
48+
"example": 197
49+
},
50+
{
51+
"section": "Task list items",
52+
"html": "<ul>\n<li><input disabled=\"\" type=\"checkbox\"> foo</li>\n<li><input checked=\"\" disabled=\"\" type=\"checkbox\"> bar</li>\n</ul>",
53+
"markdown": "- [ ] foo\n- [x] bar",
54+
"example": 272
55+
},
56+
{
57+
"section": "Task list items",
58+
"html": "<ul>\n<li><input checked=\"\" disabled=\"\" type=\"checkbox\"> foo\n<ul>\n<li><input disabled=\"\" type=\"checkbox\"> bar</li>\n<li><input checked=\"\" disabled=\"\" type=\"checkbox\"> baz</li>\n</ul>\n</li>\n<li><input disabled=\"\" type=\"checkbox\"> bim</li>\n</ul>",
59+
"markdown": "- [x] foo\n - [ ] bar\n - [x] baz\n- [ ] bim",
60+
"example": 273
61+
},
62+
{
63+
"section": "Strikethrough",
64+
"html": "<p><del>Hi</del> Hello, world!</p>",
65+
"markdown": "~Hi~ Hello, world!",
66+
"example": 469
67+
},
68+
{
69+
"section": "Strikethrough",
70+
"html": "<p>This <del>text</del> is <del>curious</del>.</p>",
71+
"markdown": "This ~text~~~~ is ~~~~curious~.",
72+
"example": 470
73+
},
74+
{
75+
"section": "Strikethrough",
76+
"html": "<p>This ~~has a</p>\n<p>new paragraph~~.</p>",
77+
"markdown": "This ~~has a\n\nnew paragraph~~.",
78+
"example": 471
79+
},
80+
{
81+
"section": "Autolinks",
82+
"html": "<p><a href=\"http://www.commonmark.org\">www.commonmark.org</a></p>",
83+
"markdown": "www.commonmark.org",
84+
"example": 597
85+
},
86+
{
87+
"section": "Autolinks",
88+
"html": "<p>Visit <a href=\"http://www.commonmark.org/help\">www.commonmark.org/help</a> for more information.</p>",
89+
"markdown": "Visit www.commonmark.org/help for more information.",
90+
"example": 598
91+
},
92+
{
93+
"section": "Autolinks",
94+
"html": "<p>Visit <a href=\"http://www.commonmark.org\">www.commonmark.org</a>.</p>\n<p>Visit <a href=\"http://www.commonmark.org/a.b\">www.commonmark.org/a.b</a>.</p>",
95+
"markdown": "Visit www.commonmark.org.\n\nVisit www.commonmark.org/a.b.",
96+
"example": 599
97+
},
98+
{
99+
"section": "Autolinks",
100+
"html": "<p><a href=\"http://www.google.com/search?q=Markup+(business)\">www.google.com/search?q=Markup+(business)</a></p>\n<p>(<a href=\"http://www.google.com/search?q=Markup+(business)\">www.google.com/search?q=Markup+(business)</a>)</p>",
101+
"markdown": "www.google.com/search?q=Markup+(business)\n\n(www.google.com/search?q=Markup+(business))",
102+
"example": 600
103+
},
104+
{
105+
"section": "Autolinks",
106+
"html": "<p><a href=\"http://www.google.com/search?q=(business))+ok\">www.google.com/search?q=(business))+ok</a></p>",
107+
"markdown": "www.google.com/search?q=(business))+ok",
108+
"example": 601
109+
},
110+
{
111+
"section": "Autolinks",
112+
"html": "<p><a href=\"http://www.google.com/search?q=commonmark&amp;hl=en\">www.google.com/search?q=commonmark&amp;hl=en</a></p>\n<p><a href=\"http://www.google.com/search?q=commonmark\">www.google.com/search?q=commonmark</a>&amp;hl;</p>",
113+
"markdown": "www.google.com/search?q=commonmark&hl=en\n\nwww.google.com/search?q=commonmark&hl;",
114+
"example": 602
115+
},
116+
{
117+
"section": "Autolinks",
118+
"html": "<p><a href=\"http://www.commonmark.org/he\">www.commonmark.org/he</a>&lt;lp</p>",
119+
"markdown": "www.commonmark.org/he<lp",
120+
"example": 603
121+
},
122+
{
123+
"section": "Autolinks",
124+
"html": "<p><a href=\"http://commonmark.org\">http://commonmark.org</a></p>\n<p>(Visit <a href=\"https://encrypted.google.com/search?q=Markup+(business)\">https://encrypted.google.com/search?q=Markup+(business)</a>)</p>\n<p>Anonymous FTP is available at <a href=\"ftp://foo.bar.baz\">ftp://foo.bar.baz</a>.</p>",
125+
"markdown": "http://commonmark.org\n\n(Visit https://encrypted.google.com/search?q=Markup+(business))\n\nAnonymous FTP is available at ftp://foo.bar.baz.",
126+
"example": 604
127+
},
128+
{
129+
"section": "Autolinks",
130+
"html": "<p><a href=\"mailto:[email protected]\">[email protected]</a></p>",
131+
"markdown": "[email protected]",
132+
"example": 605
133+
},
134+
{
135+
"section": "Autolinks",
136+
"html": "<p>hello@mail+xyz.example isn't valid, but <a href=\"mailto:[email protected]\">[email protected]</a> is.</p>",
137+
"markdown": "hello@mail+xyz.example isn't valid, but [email protected] is.",
138+
"example": 606
139+
},
140+
{
141+
"section": "Autolinks",
142+
"html": "<p><a href=\"mailto:[email protected]\">[email protected]</a></p>\n<p><a href=\"mailto:[email protected]\">[email protected]</a>.</p>\n<p>[email protected]</p>\n<p>[email protected]_</p>",
143+
144+
"example": 607
145+
},
146+
{
147+
"section": "Disallowed Raw HTML",
148+
"html": "<p><strong> &lt;title> &lt;style> <em></p>\n<blockquote>\n &lt;xmp> is disallowed. &lt;XMP> is also disallowed.\n</blockquote>",
149+
"markdown": "<strong> <title> <style> <em>\n\n<blockquote>\n <xmp> is disallowed. <XMP> is also disallowed.\n</blockquote>",
150+
"example": 629
151+
}
152+
]

0 commit comments

Comments
 (0)