mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-26 10:26:15 -04:00
Added more tests.
This commit is contained in:
parent
28e04bdf71
commit
7f05e2b399
8 changed files with 27 additions and 826 deletions
38
src/tests/backend-new/specs/admin_utils.ts
Normal file
38
src/tests/backend-new/specs/admin_utils.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
import {strict as assert} from "assert";
|
||||
import {cleanComments, minify} from "admin/src/utils/utils";
|
||||
import {describe, it, expect, beforeAll} from "vitest";
|
||||
import fs from 'fs';
|
||||
const fsp = fs.promises;
|
||||
let template:string;
|
||||
|
||||
describe(__filename, function () {
|
||||
beforeAll(async function () {
|
||||
template = await fsp.readFile('../settings.json.template', 'utf8')
|
||||
});
|
||||
describe('adminUtils', function () {
|
||||
it('cleanComments function empty', async function () {
|
||||
expect(cleanComments("")).to.equal("");
|
||||
});
|
||||
it('cleanComments function HelloWorld no comment', async function () {
|
||||
expect(cleanComments("HelloWorld")).to.equal("HelloWorld");
|
||||
});
|
||||
it('cleanComments function HelloWorld with comment', async function () {
|
||||
expect(cleanComments("Hello/*abc*/World/*def*/")).to.equal("HelloWorld");
|
||||
});
|
||||
it('cleanComments function HelloWorld with comment and multiline', async function () {
|
||||
expect(cleanComments("Hello \n/*abc\nxyz*/World/*def*/")).to.equal("Hello\nWorld");
|
||||
});
|
||||
it('cleanComments function HelloWorld with multiple line breaks', async function () {
|
||||
expect(cleanComments(" \nHello \n \n \nWorld/*def*/")).to.equal("Hello\nWorld");
|
||||
});
|
||||
it('cleanComments function same after minified', async function () {
|
||||
expect(minify(cleanComments(template)!)).to.equal(minify(template));
|
||||
});
|
||||
it('minified results are smaller', async function () {
|
||||
expect(minify(template).length < template.length).to.equal(true);
|
||||
});
|
||||
});
|
||||
});
|
55
src/tests/backend-new/specs/easysync-inverseRandom.ts
Normal file
55
src/tests/backend-new/specs/easysync-inverseRandom.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
import AttributePool from '../../../static/js/AttributePool';
|
||||
import {checkRep, inverse, makeAttribution, mutateAttributionLines, mutateTextLines, splitAttributionLines} from '../../../static/js/Changeset';
|
||||
import {randomMultiline, randomTestChangeset, poolOrArray} from '../easysync-helper.js';
|
||||
import {expect, describe, it} from 'vitest'
|
||||
|
||||
describe('easysync-inverseRandom', function () {
|
||||
describe('inverse random', function () {
|
||||
const testInverseRandom = (randomSeed: number) => {
|
||||
it(`testInverseRandom#${randomSeed}`, async function () {
|
||||
const p = poolOrArray(['apple,', 'apple,true', 'banana,', 'banana,true']);
|
||||
|
||||
const startText = `${randomMultiline(10, 20)}\n`;
|
||||
const alines =
|
||||
splitAttributionLines(makeAttribution(startText), startText);
|
||||
const lines = startText.slice(0, -1).split('\n').map((s) => `${s}\n`);
|
||||
|
||||
const stylifier = randomTestChangeset(startText, true)[0];
|
||||
|
||||
mutateAttributionLines(stylifier, alines, p);
|
||||
mutateTextLines(stylifier, lines);
|
||||
|
||||
const changeset = randomTestChangeset(lines.join(''), true)[0];
|
||||
const inverseChangeset = inverse(changeset, lines, alines, p);
|
||||
|
||||
const origLines = lines.slice();
|
||||
const origALines = alines.slice();
|
||||
|
||||
mutateTextLines(changeset, lines);
|
||||
mutateAttributionLines(changeset, alines, p);
|
||||
mutateTextLines(inverseChangeset, lines);
|
||||
mutateAttributionLines(inverseChangeset, alines, p);
|
||||
expect(lines).to.eql(origLines);
|
||||
expect(alines).to.eql(origALines);
|
||||
});
|
||||
};
|
||||
|
||||
for (let i = 0; i < 30; i++) testInverseRandom(i);
|
||||
});
|
||||
|
||||
describe('inverse', function () {
|
||||
const testInverse = (testId: number, cs: string, lines: string | RegExpMatchArray | null, alines: string[] | { get: (idx: number) => string; }, pool: string[] | AttributePool, correctOutput: string) => {
|
||||
it(`testInverse#${testId}`, async function () {
|
||||
pool = poolOrArray(pool);
|
||||
const str = inverse(checkRep(cs), lines, alines, pool as AttributePool);
|
||||
expect(str).to.equal(correctOutput);
|
||||
});
|
||||
};
|
||||
|
||||
// take "FFFFTTTTT" and apply "-FT--FFTT", the inverse of which is "--F--TT--"
|
||||
testInverse(1, 'Z:9>0=1*0=1*1=1=2*0=2*1|1=2$', null,
|
||||
['+4*1+5'], ['bold,', 'bold,true'], 'Z:9>0=2*0=1=2*1=2$');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue