Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Flavored Markdown test bed #1210

Merged
merged 4 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"test": "jasmine --config=jasmine.json",
"test:unit": "npm test -- test/unit/**/*-spec.js",
"test:specs": "npm test -- test/specs/**/*-spec.js",
"test:gfm": "npm test -- test/specs/gfm/**/*-spec.js",
"test:integration": "npm test -- test/integration/**/*-spec.js",
"test:old": "node test",
"test:lint": "eslint bin/marked .",
Expand Down
97 changes: 97 additions & 0 deletions test/specs/gfm/gfm-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
var marked = require('../../../lib/marked.js');
var gfmSpec = require('./gfm.0.28.json')
var HtmlDiffer = require('html-differ').HtmlDiffer,
htmlDiffer = new HtmlDiffer();
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 && ignore.indexOf(spec.example) < 0) {
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('GFM 0.28 Tables', function() {
var section = 'Tables';

// TODO: Verify exmaple 193 is valid and passing
var shouldPassButFails = [192, 193, 195, 196, 197];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

gfmSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});

describe('GFM 0.28 Task list items', function() {
var section = 'Task list items';

var shouldPassButFails = [272, 273];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

gfmSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});

describe('GFM 0.28 Strikethrough', function() {
var section = 'Strikethrough';

var shouldPassButFails = [469, 470];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

gfmSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});

describe('GFM 0.28 Autolinks', function() {
var section = 'Autolinks';

var shouldPassButFails = [607];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

gfmSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});

describe('GFM 0.28 Disallowed Raw HTML', function() {
var section = 'Disallowed Raw HTML';

var shouldPassButFails = [629];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

gfmSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
152 changes: 152 additions & 0 deletions test/specs/gfm/gfm.0.28.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
{
"section": "Tables",
"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>",
"markdown": "| foo | bar |\n| --- | --- |\n| baz | bim |",
"example": 191
},
{
"section": "Tables",
"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>",
"markdown": "| abc | defghi |\n:-: | -----------:\nbar | baz",
"example": 192
},
{
"section": "Tables",
"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>",
"markdown": "| f\\|oo |\n| ------ |\n| b `\\|` az |\n| b **\\|** im |",
"example": 193
},
{
"section": "Tables",
"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>",
"markdown": "| abc | def |\n| --- | --- |\n| bar | baz |\n> bar",
"example": 194
},
{
"section": "Tables",
"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>",
"markdown": "| abc | def |\n| --- | --- |\n| bar | baz |\nbar\n\nbar",
"example": 195
},
{
"section": "Tables",
"html": "<p>| abc | def |\n| --- |\n| bar |</p>",
"markdown": "| abc | def |\n| --- |\n| bar |",
"example": 196
},
{
"section": "Tables",
"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>",
"markdown": "| abc | def |\n| --- | --- |\n| bar |\n| bar | baz | boo |",
"example": 197
},
{
"section": "Tables",
"html": "<table>\n<thead>\n<tr>\n<th>abc</th>\n<th>def</th>\n</tr>\n</thead></table>",
"markdown": "| abc | def |\n| --- | --- |",
"example": 197
},
{
"section": "Task list items",
"html": "<ul>\n<li><input disabled=\"\" type=\"checkbox\"> foo</li>\n<li><input checked=\"\" disabled=\"\" type=\"checkbox\"> bar</li>\n</ul>",
"markdown": "- [ ] foo\n- [x] bar",
"example": 272
},
{
"section": "Task list items",
"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>",
"markdown": "- [x] foo\n - [ ] bar\n - [x] baz\n- [ ] bim",
"example": 273
},
{
"section": "Strikethrough",
"html": "<p><del>Hi</del> Hello, world!</p>",
"markdown": "~Hi~ Hello, world!",
"example": 469
},
{
"section": "Strikethrough",
"html": "<p>This <del>text</del> is <del>curious</del>.</p>",
"markdown": "This ~text~~~~ is ~~~~curious~.",
"example": 470
},
{
"section": "Strikethrough",
"html": "<p>This ~~has a</p>\n<p>new paragraph~~.</p>",
"markdown": "This ~~has a\n\nnew paragraph~~.",
"example": 471
},
{
"section": "Autolinks",
"html": "<p><a href=\"http://www.commonmark.org\">www.commonmark.org</a></p>",
"markdown": "www.commonmark.org",
"example": 597
},
{
"section": "Autolinks",
"html": "<p>Visit <a href=\"http://www.commonmark.org/help\">www.commonmark.org/help</a> for more information.</p>",
"markdown": "Visit www.commonmark.org/help for more information.",
"example": 598
},
{
"section": "Autolinks",
"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>",
"markdown": "Visit www.commonmark.org.\n\nVisit www.commonmark.org/a.b.",
"example": 599
},
{
"section": "Autolinks",
"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>",
"markdown": "www.google.com/search?q=Markup+(business)\n\n(www.google.com/search?q=Markup+(business))",
"example": 600
},
{
"section": "Autolinks",
"html": "<p><a href=\"http://www.google.com/search?q=(business))+ok\">www.google.com/search?q=(business))+ok</a></p>",
"markdown": "www.google.com/search?q=(business))+ok",
"example": 601
},
{
"section": "Autolinks",
"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>",
"markdown": "www.google.com/search?q=commonmark&hl=en\n\nwww.google.com/search?q=commonmark&hl;",
"example": 602
},
{
"section": "Autolinks",
"html": "<p><a href=\"http://www.commonmark.org/he\">www.commonmark.org/he</a>&lt;lp</p>",
"markdown": "www.commonmark.org/he<lp",
"example": 603
},
{
"section": "Autolinks",
"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>",
"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.",
"example": 604
},
{
"section": "Autolinks",
"html": "<p><a href=\"mailto:foo@bar.baz\">foo@bar.baz</a></p>",
"markdown": "foo@bar.baz",
"example": 605
},
{
"section": "Autolinks",
"html": "<p>hello@mail+xyz.example isn't valid, but <a href=\"mailto:hello+xyz@mail.example\">hello+xyz@mail.example</a> is.</p>",
"markdown": "hello@mail+xyz.example isn't valid, but hello+xyz@mail.example is.",
"example": 606
},
{
"section": "Autolinks",
"html": "<p><a href=\"mailto:a.b-c_d@a.b\">a.b-c_d@a.b</a></p>\n<p><a href=\"mailto:a.b-c_d@a.b\">a.b-c_d@a.b</a>.</p>\n<p>a.b-c_d@a.b-</p>\n<p>a.b-c_d@a.b_</p>",
"markdown": "a.b-c_d@a.b\n\na.b-c_d@a.b.\n\na.b-c_d@a.b-\n\na.b-c_d@a.b_",
"example": 607
},
{
"section": "Disallowed Raw HTML",
"html": "<p><strong> &lt;title> &lt;style> <em></p>\n<blockquote>\n &lt;xmp> is disallowed. &lt;XMP> is also disallowed.\n</blockquote>",
"markdown": "<strong> <title> <style> <em>\n\n<blockquote>\n <xmp> is disallowed. <XMP> is also disallowed.\n</blockquote>",
"example": 629
}
]