diff --git a/package.json b/package.json index 0a5f34317..22e53048e 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "test:coverage": "jest --coverage --silent --runInBand", "test:dev": "jest --verbose --watch", "test:basic": "jest tests/markdown/basic.test.js --verbose", + "test:variables": "jest tests/markdown/variables.test.js --verbose", "test:mustache-syntax": "jest '.*(mustache-syntax).*' --verbose --noStackTrace", "test:mustache-syntax:inline": "jest '.*(mustache-syntax).*' -t '^Inline:.*' --verbose --noStackTrace", "test:mustache-syntax:block": "jest '.*(mustache-syntax).*' -t '^Block:.*' --verbose --noStackTrace", diff --git a/tests/markdown/variables.test.js b/tests/markdown/variables.test.js new file mode 100644 index 000000000..04d874d90 --- /dev/null +++ b/tests/markdown/variables.test.js @@ -0,0 +1,80 @@ +/* eslint-disable max-lines */ + +const dedent = require('dedent-tabs').default; +const Markdown = require('naturalcrit/markdown.js'); + +// Marked.js adds line returns after closing tags on some default tokens. +// This removes those line returns for comparison sake. +String.prototype.trimReturns = function(){ + return this.replace(/\r?\n|\r/g, '').trim(); +}; + +// Adding `.failing()` method to `describe` or `it` will make failing tests "pass" as long as they continue to fail. +// Remove the `.failing()` method once you have fixed the issue. + +describe('Block-level variables', ()=>{ + it('Handles variable assignment and recall with simple text', function() { + const source = dedent` + [var]: string + + $[var] + `; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
string
'); + }); + + it('Handles variable assignment and recall with multiline string', function() { + const source = dedent` + [var]: string + across multiple + lines + + $[var]`; + const rendered = Markdown.render(source).replace(/\s/g,' ').trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('string across multiple lines
'); + }); + + it('Handles variable assignment and recall with tables', function() { + const source = dedent` + [var]: + ##### Title + | H1 | H2 | + |:---|:--:| + | A | B | + | C | D | + + $[var]`; + const rendered = Markdown.render(source).replace(/\s/g,' ').trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(dedent` +| H1 | +H2 | +
|---|---|
| A | +B | +
| C | +D | +