-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: create tests for textlint-rule-allowed-uris.js
and fix typo in tests/utils/getDefinitionNodeUriType.spec.js
- Loading branch information
1 parent
b441e4e
commit 8aab2cf
Showing
3 changed files
with
330 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
/** | ||
* `testCases` for `textlint-rule-allowed-uris.spec.js` | ||
*/ | ||
module.exports = [ | ||
/* Totally empty */ | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [], | ||
}, | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
disallowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
disallowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [], | ||
}, | ||
|
||
/* Pass empty array */ | ||
{ | ||
options: { | ||
allowed: { | ||
links: [], // Act like an whitelist. i.e. Empty array allows nothing. Every `links` will be detected. | ||
// images: [], | ||
}, | ||
disallowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [7, 9, 13, 15, 19, 21, 23, 25, 31, 37, 43, 47, 86, 101, 103, 105], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
images: [], // Act like an whitelist. i.e. Empty array allows nothing. Every `images` will be detected. | ||
}, | ||
disallowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [53, 59, 65, 71, 75, 77, 79, 86, 105], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
links: [], // Act like an whitelist. i.e. Empty array allows nothing. Every `links` will be detected. | ||
images: [], // Act like an whitelist. i.e. Empty array allows nothing. Every `images` will be detected. | ||
}, | ||
disallowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [ | ||
7, 9, 13, 15, 19, 21, 23, 25, 31, 37, 43, 47, 53, 59, 65, 71, 75, 77, 79, 86, 86, | ||
101, 103, 105, 105, | ||
], // `86` and `105` are same line number, but detected twice. one for `links` and the other for `images` | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
disallowed: { | ||
links: [], // Act like a blacklist. i.e. Empty array allows everything. No `links` will be detected. | ||
// images: [], | ||
}, | ||
}, | ||
lines: [], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
disallowed: { | ||
// links: [], | ||
images: [], // Act like a blacklist. i.e. Empty array allows everything. No `images` will be detected. | ||
}, | ||
}, | ||
lines: [], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
// images: [], | ||
}, | ||
disallowed: { | ||
links: [], // Act like a blacklist. i.e. Empty array allows everything. No `images` will be detected. | ||
images: [], // Act like a blacklist. i.e. Empty array allows everything. No `images` will be detected. | ||
}, | ||
}, | ||
lines: [], | ||
}, | ||
|
||
/* Pass values */ | ||
// `allowed.links` | ||
{ | ||
options: { | ||
allowed: { | ||
links: [/google/], | ||
// images: [], | ||
}, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [9, 15, 21, 23, 25, 86, 101, 103], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
links: [/google/, /gmail/], | ||
// images: [], | ||
}, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [21, 23, 25, 86, 101, 103], | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
links: [/google/, /gmail/, /README.md/], | ||
// images: [], | ||
}, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [21, 23, 86, 103], | ||
}, | ||
// `allowed.images` | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
images: [/wiki/], | ||
}, | ||
// disallowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
}, | ||
lines: [], | ||
}, | ||
// `disallowed.links` | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
disallowed: { | ||
links: [/google/], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [7, 13, 19, 31, 37, 43, 47, 105], | ||
}, | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
disallowed: { | ||
links: [/google/, /gmail/], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [7, 9, 13, 15, 19, 31, 37, 43, 47, 105], | ||
}, | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
disallowed: { | ||
links: [/google/, /gmail/, /README.md/], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [7, 9, 13, 15, 19, 25, 31, 37, 43, 47, 101, 105], | ||
}, | ||
// `disallowed.images` | ||
{ | ||
options: { | ||
// allowed: { | ||
// links: [], | ||
// images: [], | ||
// }, | ||
disallowed: { | ||
// links: [], | ||
images: [/wiki/], | ||
}, | ||
}, | ||
lines: [53, 59, 65, 71, 75, 77, 79, 86, 105], | ||
}, | ||
|
||
/* Pass same values to `allowed` and `disallowed` */ | ||
{ | ||
options: { | ||
allowed: { | ||
links: [/google/], | ||
// images: [], | ||
}, | ||
disallowed: { | ||
links: [/google/], | ||
// images: [], | ||
}, | ||
}, | ||
lines: [7, 9, 13, 15, 19, 21, 23, 25, 31, 37, 43, 47, 86, 101, 103, 105], // Every `links` will be detected. | ||
}, | ||
{ | ||
options: { | ||
allowed: { | ||
// links: [], | ||
images: [/wiki/], | ||
}, | ||
disallowed: { | ||
// links: [], | ||
images: [/wiki/], | ||
}, | ||
}, | ||
lines: [53, 59, 65, 71, 75, 77, 79, 86, 105], // Every `images` will be detected. | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const TextLintTester = require('textlint-tester').default; | ||
const allowedUris = require('../src/textlint-rule-allowed-uris'); | ||
const testCases = require('./textlint-rule-allowed-uris.data'); | ||
|
||
const tester = new TextLintTester(); | ||
const testCasesMarkdown = fs.readFileSync( | ||
path.resolve(__dirname, 'textlint-rule-allowed-uris.data.md'), | ||
'utf-8', | ||
); | ||
|
||
/** | ||
* Tests for the `textlint-rule-allowed-uris.js` | ||
*/ | ||
describe('textlint-rule-allowed-uris', () => { | ||
testCases.forEach(({ options, lines }) => { | ||
/* Initialization */ | ||
const testConfig = { | ||
rules: [ | ||
{ | ||
ruleId: 'textlint-rule-allowed-uris', | ||
rule: allowedUris, | ||
options, | ||
}, | ||
], | ||
}; | ||
const invalid = [ | ||
{ | ||
text: testCasesMarkdown, | ||
errors: lines.map(line => ({ line })), | ||
}, | ||
]; | ||
|
||
/* Test */ | ||
tester.run( | ||
` | ||
allowed links: ${options?.allowed?.links?.join(' or ')} | ||
allowed images: ${options?.allowed?.images?.join(' or ')} | ||
disallowed links: ${options?.disallowed?.links?.join(' or ')} | ||
disallowed images: ${options?.disallowed?.links?.join(' or ')} | ||
lines: ${lines.join(', ')} | ||
`, | ||
testConfig, | ||
{ | ||
invalid, | ||
}, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters