Peter Stuifzand
70f1b62646
All checks were successful
continuous-integration/drone/push Build is passing
Use the markdown parser to handle links and checkboxes instead of internal javascript. Also add catch clauses to the promises in the editor.
118 lines
3.6 KiB
JavaScript
118 lines
3.6 KiB
JavaScript
/*
|
|
* Wiki - A wiki with editor
|
|
* Copyright (c) 2021 Peter Stuifzand
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import assert from 'assert'
|
|
import {linkParser} from '../src/wikilinks2'
|
|
|
|
describe('linkParser', function () {
|
|
it('parse', function () {
|
|
let state = {src: '', pos: 0, tokens: []};
|
|
state.__proto__.push = function (id, s, x) {
|
|
let token = {id, s, x};
|
|
this.tokens.push(token)
|
|
return token
|
|
}
|
|
assert.deepStrictEqual(linkParser('test', state), false);
|
|
assert.deepStrictEqual(state, {
|
|
src: '',
|
|
pos: 0,
|
|
tokens: []
|
|
})
|
|
})
|
|
|
|
it('parse 2', function () {
|
|
let state = {src: '[[Link]]', pos: 0, tokens: []};
|
|
state.__proto__.push = function (id, s, x) {
|
|
let token = {id, s, x};
|
|
this.tokens.push(token)
|
|
return token
|
|
}
|
|
assert.deepStrictEqual(linkParser('test', state), true);
|
|
assert.deepStrictEqual(state, {
|
|
src: '[[Link]]',
|
|
pos: 8,
|
|
tokens: [{
|
|
id: 'test',
|
|
s: '',
|
|
x: 0,
|
|
meta: {match:'Link', tag: false}
|
|
}]
|
|
})
|
|
})
|
|
|
|
it('parse 3', function () {
|
|
let state = {src: '1234[[Link]]', pos: 4, tokens: []};
|
|
state.__proto__.push = function (id, s, x) {
|
|
let token = {id, s, x};
|
|
this.tokens.push(token)
|
|
return token
|
|
}
|
|
assert.deepStrictEqual(linkParser('test', state), true);
|
|
assert.deepStrictEqual(state, {
|
|
src: '1234[[Link]]',
|
|
pos: 12,
|
|
tokens: [{
|
|
id: 'test',
|
|
s: '',
|
|
x: 0,
|
|
meta: {match:'Link', tag: false}
|
|
}]
|
|
})
|
|
})
|
|
|
|
it('parse 4', function () {
|
|
let state = {src: '1234#[[TODO]]', pos: 4, tokens: []};
|
|
state.__proto__.push = function (id, s, x) {
|
|
let token = {id, s, x};
|
|
this.tokens.push(token)
|
|
return token
|
|
}
|
|
assert.deepStrictEqual(linkParser('test', state), true);
|
|
assert.deepStrictEqual(state, {
|
|
src: '1234#[[TODO]]',
|
|
pos: 13,
|
|
tokens: [{
|
|
id: 'test',
|
|
s: '',
|
|
x: 0,
|
|
meta: {match:'TODO', tag: true}
|
|
}]
|
|
})
|
|
})
|
|
|
|
it('parse text and two links', function () {
|
|
let state = {src: '1234 [[Link]] [[Link2]]', pos: 5, tokens: []};
|
|
state.__proto__.push = function (id, s, x) {
|
|
let token = {id, s, x};
|
|
this.tokens.push(token)
|
|
return token
|
|
}
|
|
assert.deepStrictEqual(linkParser('test', state), true);
|
|
assert.deepStrictEqual(state, {
|
|
src: '1234 [[Link]] [[Link2]]',
|
|
pos: 13,
|
|
tokens: [{
|
|
id: 'test',
|
|
s: '',
|
|
x: 0,
|
|
meta: {match:'Link', tag: false}
|
|
}]
|
|
})
|
|
})
|
|
})
|