Add validation of applyFixes via result snapshots.

This commit is contained in:
David Anson 2019-09-16 21:48:34 -07:00
parent b77a56255f
commit 52939a6d7e
15 changed files with 450 additions and 3 deletions

View 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

View 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 ##

View 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

View file

@ -0,0 +1,13 @@
#
-
1.
- a
1. a
- a
1. a

View 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.

View 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 ![](image.jpg)
```text
Fenced code
```
Indented code
Missing newline character

View file

@ -0,0 +1,26 @@
# Blanks Around Headings
## Apple
Text
## Banana
Text
## Cherry
Text
## Durian ##
Text
---
Elderberry
----------
Text
## Fig

View file

@ -0,0 +1,30 @@
# Blanks Around Headings
## Apple
Text
## Banana
Text
## Cherry
Text
## Durian ##
Text
Elderberry
----------
Text
## Fig

View file

@ -0,0 +1,26 @@
# Blanks Around Headings
## Apple
Text
## Banana
Text
## Cherry
Text
## Durian ##
Text
---
Elderberry
----------
Text
## Fig

View file

@ -0,0 +1,6 @@
---
front: matter
---
Text
Text

View 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

View 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

View file

@ -0,0 +1,3 @@
# Ordered list examples
9. Item

View 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

View file

@ -35,9 +35,10 @@ function promisify(func, ...args) {
function createTestForFile(file) {
return function testForFile(test) {
test.expect(2);
const detailedResults = /[/\\]detailed-results-/.test(file);
test.expect(detailedResults ? 3 : 2);
const resultsFile = file.replace(/\.md$/, ".results.json");
const fixedFile = file.replace(/\.md$/, ".md.fixed");
const configFile = file.replace(/\.md$/, ".json");
let mergedConfig = null;
const actualPromise = promisify(fs.stat, configFile)
@ -62,9 +63,34 @@ function createTestForFile(file) {
});
})
.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 result2or3 = resultVersion2[file];
const result2or3 = resultVersion2or3[file];
result2or3.forEach(function forResult(result) {
const ruleName = result.ruleNames[0];
const lineNumbers = result0[ruleName] || [];