mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add validation of applyFixes via result snapshots.
This commit is contained in:
parent
b77a56255f
commit
52939a6d7e
15 changed files with 450 additions and 3 deletions
30
test/detailed-results-MD001-MD010.md.fixed
Normal file
30
test/detailed-results-MD001-MD010.md.fixed
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
## One
|
||||||
|
|
||||||
|
#### Two
|
||||||
|
|
||||||
|
### Three ###
|
||||||
|
|
||||||
|
* Alpha
|
||||||
|
* Bravo
|
||||||
|
|
||||||
|
- Charlie
|
||||||
|
|
||||||
|
* Delta
|
||||||
|
* Echo
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text text
|
||||||
|
|
||||||
|
1. One
|
||||||
|
2. Two
|
||||||
|
3. Three
|
||||||
|
4. Four
|
||||||
|
5. Five
|
||||||
|
6. Six
|
||||||
|
7. Seven
|
||||||
|
8. Eight
|
||||||
|
9. Nine
|
||||||
|
10. Ten
|
||||||
|
11. Eleven
|
||||||
|
12. Twelve
|
||||||
23
test/detailed-results-MD011-MD021.md.fixed
Normal file
23
test/detailed-results-MD011-MD021.md.fixed
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Top level heading
|
||||||
|
|
||||||
|
<!-- markdownlint-disable MD003 -->
|
||||||
|
|
||||||
|
A [reversed](link) example.
|
||||||
|
|
||||||
|
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
|
||||||
|
|
||||||
|
## 123456789 123456789 123456789 123456789 123456789 123456789
|
||||||
|
|
||||||
|
$ command with no output
|
||||||
|
|
||||||
|
## No space A
|
||||||
|
|
||||||
|
## Multiple spaces B
|
||||||
|
|
||||||
|
## No space C ####No space C ##
|
||||||
|
|
||||||
|
## No space D #### No space D##
|
||||||
|
|
||||||
|
## Multiple spaces E #### Multiple spaces E ##
|
||||||
|
|
||||||
|
## Multiple spaces F #### Multiple spaces F ##
|
||||||
19
test/detailed-results-MD022-MD030.md.fixed
Normal file
19
test/detailed-results-MD022-MD030.md.fixed
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
## Another heading
|
||||||
|
|
||||||
|
> Multiple spaces
|
||||||
|
> Blank line above
|
||||||
|
|
||||||
|
1. Alpha
|
||||||
|
3. Beta
|
||||||
|
|
||||||
|
> > Multiple spaces, multiple blockquotes
|
||||||
|
> >
|
||||||
|
> > > Multiple spaces, multiple blockquotes
|
||||||
|
> > >
|
||||||
|
> > > Multiple spaces, multiple blockquotes
|
||||||
13
test/detailed-results-MD030-warning-message.md.fixed
Normal file
13
test/detailed-results-MD030-warning-message.md.fixed
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
1.
|
||||||
|
|
||||||
|
- a
|
||||||
|
|
||||||
|
1. a
|
||||||
|
|
||||||
|
- a
|
||||||
|
|
||||||
|
1. a
|
||||||
66
test/detailed-results-MD031-MD040.md.fixed
Normal file
66
test/detailed-results-MD031-MD040.md.fixed
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
```js
|
||||||
|
debugger;
|
||||||
|
```
|
||||||
|
|
||||||
|
* List
|
||||||
|
|
||||||
|
Inline<hr/>HTML
|
||||||
|
|
||||||
|
Bare <https://example.com> link
|
||||||
|
|
||||||
|
---
|
||||||
|
***
|
||||||
|
|
||||||
|
*Emphasis*
|
||||||
|
|
||||||
|
Space *inside* emphasis
|
||||||
|
|
||||||
|
Space `insidecode span
|
||||||
|
|
||||||
|
Space [inside](link) text
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
||||||
|
space ``insideode
|
||||||
|
space `inside` of `codeelements
|
||||||
|
`space` inside `of` code `elements
|
||||||
|
space ``inside`` of ``codelements
|
||||||
|
``` embedded backtick
|
||||||
|
embedded backtick```
|
||||||
|
|
||||||
|
some *space* in *some* emphasis
|
||||||
|
some *space* in *some* emphasis
|
||||||
|
some *space* in **some** emphasis
|
||||||
|
some _space_ in _some_ emphasis
|
||||||
|
some __space__ in __some__ emphasis
|
||||||
|
|
||||||
|
Text
|
||||||
|
text `code
|
||||||
|
span
|
||||||
|
span` text
|
||||||
|
text.
|
||||||
|
|
||||||
|
Text
|
||||||
|
text `code
|
||||||
|
code
|
||||||
|
span` text
|
||||||
|
text.
|
||||||
|
|
||||||
|
* List
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Text
|
||||||
|
text ```code
|
||||||
|
span code
|
||||||
|
code
|
||||||
|
span code
|
||||||
|
span code``` text
|
||||||
|
text
|
||||||
|
text text ````code
|
||||||
|
span code
|
||||||
|
span
|
||||||
|
span code
|
||||||
|
span```` text
|
||||||
|
text.
|
||||||
27
test/detailed-results-MD041-MD050.md.fixed
Normal file
27
test/detailed-results-MD041-MD050.md.fixed
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
Not a heading
|
||||||
|
|
||||||
|
An [empty]() link
|
||||||
|
|
||||||
|
An [empty](#) link with fragment
|
||||||
|
|
||||||
|
An [empty](<>) link with angle brackets
|
||||||
|
|
||||||
|
This is a test file for the markdownlint package.
|
||||||
|
|
||||||
|
This is a paragraph
|
||||||
|
about markdownlint
|
||||||
|
that capitalizes the
|
||||||
|
name wrong twice:
|
||||||
|
markdownlint.
|
||||||
|
|
||||||
|
A [normal](link) and an [empty one]() and a [fragment](#one).
|
||||||
|
|
||||||
|
An image without alternate text 
|
||||||
|
|
||||||
|
```text
|
||||||
|
Fenced code
|
||||||
|
```
|
||||||
|
|
||||||
|
Indented code
|
||||||
|
|
||||||
|
Missing newline character
|
||||||
26
test/detailed-results-blanks-around-headings-0-2.md.fixed
Normal file
26
test/detailed-results-blanks-around-headings-0-2.md.fixed
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Blanks Around Headings
|
||||||
|
|
||||||
|
|
||||||
|
## Apple
|
||||||
|
|
||||||
|
|
||||||
|
Text
|
||||||
|
## Banana
|
||||||
|
|
||||||
|
|
||||||
|
Text
|
||||||
|
## Cherry
|
||||||
|
|
||||||
|
|
||||||
|
Text
|
||||||
|
## Durian ##
|
||||||
|
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
---
|
||||||
|
Elderberry
|
||||||
|
----------
|
||||||
|
|
||||||
|
Text
|
||||||
|
## Fig
|
||||||
30
test/detailed-results-blanks-around-headings-3-0.md.fixed
Normal file
30
test/detailed-results-blanks-around-headings-3-0.md.fixed
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Blanks Around Headings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Apple
|
||||||
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Banana
|
||||||
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Cherry
|
||||||
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Durian ##
|
||||||
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
Elderberry
|
||||||
|
----------
|
||||||
|
Text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Fig
|
||||||
26
test/detailed-results-blanks-around-headings.md.fixed
Normal file
26
test/detailed-results-blanks-around-headings.md.fixed
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Blanks Around Headings
|
||||||
|
|
||||||
|
## Apple
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
## Banana
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
## Cherry
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
## Durian ##
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Elderberry
|
||||||
|
----------
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
## Fig
|
||||||
6
test/detailed-results-front-matter.md.fixed
Normal file
6
test/detailed-results-front-matter.md.fixed
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
front: matter
|
||||||
|
---
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text
|
||||||
107
test/detailed-results-html-tags.md.fixed
Normal file
107
test/detailed-results-html-tags.md.fixed
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
# Detailed HTML Results
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<em>Block block</em>
|
||||||
|
|
||||||
|
Text <em>inline inline</em> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<strong>Block block</strong>
|
||||||
|
|
||||||
|
Text <strong>inline inline</strong> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Block
|
||||||
|
block <em>block</em> block
|
||||||
|
block
|
||||||
|
block <strong>block</strong> block
|
||||||
|
block
|
||||||
|
block <em>block</em> block <strong>block</strong> block
|
||||||
|
block <strong>block</strong> block <em>block</em> block
|
||||||
|
</p>
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<strong><em>Block</em> block</strong>
|
||||||
|
|
||||||
|
Text <strong><em>inline</em> inline</strong> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<em><strong>Block</strong> block</em>
|
||||||
|
|
||||||
|
Text <em><strong>inline</strong> inline</em> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text <em>inline</em> text <strong>inline</strong> text <em>inline</em> text
|
||||||
|
|
||||||
|
Text <strong>inline</strong> text <em>inline</em> text <strong>inline</strong> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
\<not>Block block\</not>
|
||||||
|
|
||||||
|
\\<problem>Block block\\</problem>
|
||||||
|
|
||||||
|
<not\>Block block</not\>
|
||||||
|
|
||||||
|
Text \<not>inline inline\</not> text
|
||||||
|
|
||||||
|
Text \\<problem>inline inline\\</problem> text
|
||||||
|
|
||||||
|
Text <not\>inline inline</not\> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
> Text <em>inline inline</em> text
|
||||||
|
> text <strong>inline inline</strong> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text <em>inline inline</em> text
|
||||||
|
text <strong>inline inline</strong> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
```html
|
||||||
|
Text <em>inline inline</em> text
|
||||||
|
text <strong>inline inline</strong> text
|
||||||
|
```
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
`<em>`
|
||||||
|
|
||||||
|
Text ``<em>`` text
|
||||||
|
|
||||||
|
Text `<em>` text ``<em>`` text ```<em>``` text
|
||||||
|
|
||||||
|
Text `<em>` text <em>inline</em> text
|
||||||
|
|
||||||
|
Text ``text <em> text`` text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
Text <a href="#anchor">inline</a> text
|
||||||
|
text <img src="src.png"/> text
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<name@example.com> is an email autolink.
|
||||||
|
|
||||||
|
Another email autolink: <first+last@ex.exa-mple.com>.
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
<foo-bar-baz> is an HTML element.
|
||||||
|
|
||||||
|
But <foo.bar.baz> is not an autolink or HTML element.
|
||||||
|
And neither is <foo_bar>.
|
||||||
|
Nor <123abc>.
|
||||||
|
|
||||||
|
Text
|
||||||
26
test/detailed-results-links.md.fixed
Normal file
26
test/detailed-results-links.md.fixed
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
# Detailed Link Results
|
||||||
|
|
||||||
|
Text <https://example.com/> text
|
||||||
|
|
||||||
|
Text <https://example.com/brackets> text <https://example.com/bare> text
|
||||||
|
|
||||||
|
Text <https://example.com/bare> text <https://example.com/brackets> text
|
||||||
|
|
||||||
|
Text `code https://example.com/code code` text <https://example.com/> text
|
||||||
|
|
||||||
|
> Text <https://example.com/brackets> text <https://example.com/bare> text
|
||||||
|
|
||||||
|
Text <https://example.com/dir>
|
||||||
|
text <https://example.com/file.txt>
|
||||||
|
text <https://example.com/dir/dir>
|
||||||
|
text <https://example.com/dir/dir/file?query=param>
|
||||||
|
|
||||||
|
```text
|
||||||
|
Code https://example.com/code?type=fence code
|
||||||
|
```
|
||||||
|
|
||||||
|
Code https://example.com/code?type=indent code
|
||||||
|
|
||||||
|
Text <https://example.com/same> more text <https://example.com/same> still more text <https://example.com/same> done
|
||||||
|
|
||||||
|
Text <https://example.com/same> more \* text https://example.com/same more \[ text <https://example.com/same> done
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Ordered list examples
|
||||||
|
|
||||||
|
9. Item
|
||||||
19
test/detailed-results-ordered-list-item-prefix-zero.md.fixed
Normal file
19
test/detailed-results-ordered-list-item-prefix-zero.md.fixed
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Ordered list examples
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
0. Item
|
||||||
|
0. Item
|
||||||
|
0. Item
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
1. Item
|
||||||
|
1. Item
|
||||||
|
1. Item
|
||||||
|
|
||||||
|
text
|
||||||
|
|
||||||
|
1. Item
|
||||||
|
2. Item
|
||||||
|
3. Item
|
||||||
|
|
@ -35,9 +35,10 @@ function promisify(func, ...args) {
|
||||||
|
|
||||||
function createTestForFile(file) {
|
function createTestForFile(file) {
|
||||||
return function testForFile(test) {
|
return function testForFile(test) {
|
||||||
test.expect(2);
|
|
||||||
const detailedResults = /[/\\]detailed-results-/.test(file);
|
const detailedResults = /[/\\]detailed-results-/.test(file);
|
||||||
|
test.expect(detailedResults ? 3 : 2);
|
||||||
const resultsFile = file.replace(/\.md$/, ".results.json");
|
const resultsFile = file.replace(/\.md$/, ".results.json");
|
||||||
|
const fixedFile = file.replace(/\.md$/, ".md.fixed");
|
||||||
const configFile = file.replace(/\.md$/, ".json");
|
const configFile = file.replace(/\.md$/, ".json");
|
||||||
let mergedConfig = null;
|
let mergedConfig = null;
|
||||||
const actualPromise = promisify(fs.stat, configFile)
|
const actualPromise = promisify(fs.stat, configFile)
|
||||||
|
|
@ -62,9 +63,34 @@ function createTestForFile(file) {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function convertResultVersion2To0(resultVersion2) {
|
function diffFixedFiles(resultVersion2or3) {
|
||||||
|
return detailedResults ?
|
||||||
|
Promise.all([
|
||||||
|
promisify(markdownlint, {
|
||||||
|
"files": [ file ],
|
||||||
|
"config": mergedConfig,
|
||||||
|
"resultVersion": 3
|
||||||
|
}),
|
||||||
|
promisify(fs.readFile, file, helpers.utf8Encoding),
|
||||||
|
promisify(fs.readFile, fixedFile, helpers.utf8Encoding)
|
||||||
|
])
|
||||||
|
.then(function validateApplyFixes(fulfillments) {
|
||||||
|
const [ resultVersion3, content, expected ] = fulfillments;
|
||||||
|
const errors = resultVersion3[file];
|
||||||
|
const actual = helpers.applyFixes(content, errors);
|
||||||
|
// Uncomment the following line to update *.md.fixed files
|
||||||
|
// fs.writeFileSync(fixedFile, actual, helpers.utf8Encoding);
|
||||||
|
test.equal(actual, expected,
|
||||||
|
"Unexpected output from applyFixes.");
|
||||||
|
return resultVersion2or3;
|
||||||
|
}) :
|
||||||
|
resultVersion2or3;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
function convertResultVersion2To0(resultVersion2or3) {
|
||||||
const result0 = {};
|
const result0 = {};
|
||||||
const result2or3 = resultVersion2[file];
|
const result2or3 = resultVersion2or3[file];
|
||||||
result2or3.forEach(function forResult(result) {
|
result2or3.forEach(function forResult(result) {
|
||||||
const ruleName = result.ruleNames[0];
|
const ruleName = result.ruleNames[0];
|
||||||
const lineNumbers = result0[ruleName] || [];
|
const lineNumbers = result0[ruleName] || [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue