From f85a8cca7b7fef35925aa98aafcebe87ba6cfb7c Mon Sep 17 00:00:00 2001 From: Josh Bruce Date: Sun, 15 Apr 2018 13:08:01 -0400 Subject: [PATCH] Test for #1218 & "marked" spec --- package.json | 1 + test/specs/marked/marked-spec.js | 49 ++++++++++++++++++++++++++++++++ test/specs/marked/marked.json | 8 ++++++ 3 files changed, 58 insertions(+) create mode 100644 test/specs/marked/marked-spec.js create mode 100644 test/specs/marked/marked.json diff --git a/package.json b/package.json index 5ebeef7ef5..17bdaec3bc 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/specs/marked/marked-spec.js b/test/specs/marked/marked-spec.js new file mode 100644 index 0000000000..783693efb2 --- /dev/null +++ b/test/specs/marked/marked-spec.js @@ -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); + }); +}); diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json new file mode 100644 index 0000000000..eedb65a83a --- /dev/null +++ b/test/specs/marked/marked.json @@ -0,0 +1,8 @@ +[ + { + "section": "Code spans", + "markdown": "`someone@example.com`", + "html": "

someone@exmaple.com

\n", + "example": 1 + } +]