mirror of
https://github.com/luxfi/pics.git
synced 2026-07-27 05:11:31 +00:00
no-template-curly-in-string (+find and fix minor bug in redirect) curly no-multiple-empty-lines
42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
const linkmatch = require('./linkmatch.js');
|
|
/* eslint-disable no-useless-escape */
|
|
const linkRegex = /\[(?<label>[^\[][^\]]*?)\]\((?<url>(?:/[^\s<>\[\]{}|\\^)]+|https?\://[^\s<>\[\]{}|\\^)]+))\)|(?<urlOnly>https?\://[^\s<>\[\]{}|\\^]+)/g;
|
|
const Permission = require('../../../permission/permission.js');
|
|
const ROOT = new Permission();
|
|
ROOT.setAll(Permission.allPermissions);
|
|
const NO_PERMISSION = new Permission();
|
|
|
|
describe('link markdown', () => {
|
|
|
|
const rootCases = [
|
|
{ in: 'http://something.com', out: 'href=' },
|
|
{ in: 'https://something.com', out: 'href=' },
|
|
{ in: '[test](http://something.com)', out: '>test</a>' },
|
|
{ in: '[test](https://something.com)', out: '>test</a>' },
|
|
{ in: 'http://', out: 'http://' },
|
|
{ in: 'https://', out: 'https://' },
|
|
];
|
|
|
|
for(let i in rootCases) {
|
|
test(`should contain ${rootCases[i].out} for an input of ${rootCases[i].in}`, () => {
|
|
expect(rootCases[i].in.replace(linkRegex, linkmatch.bind(null, ROOT))).toContain(rootCases[i].out);
|
|
});
|
|
}
|
|
|
|
const cases = [
|
|
{ in: 'http://something.com', out: 'href=' },
|
|
{ in: 'https://something.com', out: 'href=' },
|
|
{ in: '[http://something.com](test)', out: '>http://something.com</a>' },
|
|
{ in: '[https://something.com](test)', out: '>https://something.com</a>' },
|
|
{ in: 'http://', out: 'http://' },
|
|
{ in: 'https://', out: 'https://' },
|
|
];
|
|
|
|
for(let i in cases) {
|
|
test(`should contain ${cases[i].out} for an input of ${cases[i].in}`, () => {
|
|
expect(cases[i].in.replace(linkRegex, linkmatch.bind(null, NO_PERMISSION))).toContain(cases[i].out);
|
|
});
|
|
}
|
|
|
|
});
|