Select Git revision
pipe.mjs 3.75 KiB
"use strict";
import {expect} from "chai"
import {Pipe} from "../../../source/data/pipe.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";
import {Embed} from "../../../source/i18n/providers/embed.mjs";
describe('Pipe', function () {
before(function (done) {
let promises = []
if (!globalThis['crypto']) {
promises.push(import("@peculiar/webcrypto").then(m => {
globalThis['crypto'] = new m.Crypto();
return true;
}))
}
Promise.all(promises).then(() => {
done()
});
});
describe('run different pipes', function () {
[
['path:b | if:x:\\ ', {a: true}, ' '], // '\\ '.length ↦ 2
['path:a | if:x:\\ ', {a: true}, 'x'],
['nop', 'abcdefghijklmnop', 'abcdefghijklmnop'],
].forEach(function (data) {
let a = data.shift()
let b = data.shift()
let c = data.shift()
it('Pipe.run(' + JSON.stringify(a) + ').run(' + JSON.stringify(b) + ') should return ' + JSON.stringify(c), function () {
let t = new Pipe(a);
const r = t.run(b);
expect(r).to.be.eql(c);
});
});
});
describe('new Pipe should create new Instance', function () {
it('should return Instance', function () {
expect(new Pipe('')).to.be.instanceOf(Pipe);
});
it('should return Instance', function () {
expect(new Pipe('index:a|toupper |prefix:a').run({a: "test"})).to.be.equal('aTEST');
});
[
['index:a|toupper |prefix:a', {a: "test"}, 'aTEST'],
['path:a.b.c.d | toupper | prefix:Hello\\ ', {
a: {
b: {
c: {
d: "world"
}
}
}