Skip to content

Commit

Permalink
Test for markedjs#1218 & "marked" spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Bruce committed Apr 15, 2018
1 parent e3a00f8 commit f85a8cc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"test:specs": "npm test -- test/specs/**/*-spec.js",
"test:cm": "npm test -- test/specs/commonmark/**/*-spec.js",
"test:gfm": "npm test -- test/specs/gfm/**/*-spec.js",
"test:marked": "npm test -- test/specs/marked/**/*-spec.js",
"test:old": "node test",
"test:lint": "eslint bin/marked .",
"bench": "node test --bench",
Expand Down
49 changes: 49 additions & 0 deletions test/specs/marked/marked-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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('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) {
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 Code spans', function() {
var section = 'Code spans';

// var shouldPassButFails = [];
var shouldPassButFails = [1];

var willNotBeAttemptedByCoreTeam = [];

var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam);

markedSpec.forEach(function(spec) {
messenger.test(spec, section, ignore);
});
});
8 changes: 8 additions & 0 deletions test/specs/marked/marked.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"section": "Code spans",
"markdown": "`[email protected]`",
"html": "<p><code>[email protected]</code></p>\n",
"example": 1
}
]

0 comments on commit f85a8cc

Please sign in to comment.