mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-28 03:16:16 -04:00
migrate more
This commit is contained in:
parent
2fb729b5e4
commit
876d7db39a
3 changed files with 153 additions and 104 deletions
109
tests/backend/specs/easysync/attributionlinemutations.js
Normal file
109
tests/backend/specs/easysync/attributionlinemutations.js
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||||
|
var AttributePool = require("ep_etherpad-lite/static/js/AttributePool");
|
||||||
|
var helper = require("./helper.js")
|
||||||
|
var assert = helper.assert;
|
||||||
|
var literal = helper.literal;
|
||||||
|
var assertEqualStrings = helper.assertEqualStrings;
|
||||||
|
var assertEqualArrays = helper.assertEqualArrays;
|
||||||
|
|
||||||
|
describe("attribution line mutations",function(){
|
||||||
|
it("turns 123\\n 456\\n 789\\n into 123\\n 4<b>5</b>6\\n 789\\n",function(done){
|
||||||
|
runMutateAttributionTest(1, ["bold,true"], "Z:c>0|1=4=1*0=1$", ["|1+4", "|1+4", "|1+4"], ["|1+4", "+1*0+1|1+2", "|1+4"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("makes a document bold",function(done){
|
||||||
|
runMutateAttributionTest(2, ["bold,true"], "Z:c>0*0|3=c$", ["|1+4", "|1+4", "|1+4"], ["*0|1+4", "*0|1+4", "*0|1+4"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("clears bold on document",function(done){
|
||||||
|
runMutateAttributionTest(3, ["bold,", "bold,true"], "Z:c>0*0|3=c$", ["*1+1+1*1+1|1+1", "+1*1+1|1+2", "*1+1+1*1+1|1+1"], ["|1+4", "|1+4", "|1+4"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
// if any attribution string with a '?' is parsed it will cause an error.
|
||||||
|
it("adds a character on line 3 of a document with 5 blank lines, and make sure the optimization that skips purely-kept lines is working",function(done){
|
||||||
|
runMutateAttributionTest(4, ['foo,bar', 'line,1', 'line,2', 'line,3', 'line,4', 'line,5'], "Z:5>1|2=2+1$x", ["?*1|1+1", "?*2|1+1", "*3|1+1", "?*4|1+1", "?*5|1+1"], ["?*1|1+1", "?*2|1+1", "+1*3|1+1", "?*4|1+1", "?*5|1+1"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on runMutationTest#1",function(done){
|
||||||
|
runMutateAttributionTest(5, testPoolWithChars, "Z:11>7-2*t+1*u+1|2=b|2+a=2*b+1*o+1*t+1*0|1+1*b+1*u+1=3|1-3-6$" + "tucream\npie\nbot\nbu", ["*a+1*p+2*l+1*e+1*0|1+1", "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", "*c+1*a+1*b+2*a+1*g+1*e+1*0|1+1", "*d+1*u+1*f+2*l+1*e+1*0|1+1", "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"], ["*t+1*u+1*p+1*l+1*e+1*0|1+1", "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", "|1+6", "|1+4", "*c+1*a+1*b+1*o+1*t+1*0|1+1", "*b+1*u+1*b+2*a+1*0|1+1", "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on runMutationTest#3",function(done){
|
||||||
|
runMutateAttributionTest(6, testPoolWithChars, "Z:11<f|1-6|2=f=6|1-1-8$", ["*a|1+6", "*b|1+7", "*c|1+8", "*d|1+7", "*e|1+9"], ["*b|1+7", "*c|1+8", "*d+6*e|1+1"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on runMutationTest#4",function(done){
|
||||||
|
runMutateAttributionTest(7, testPoolWithChars, "Z:3>7=1|4+7$\n2\n3\n4\n", ["*1+1*5|1+2"], ["*1+1|1+1", "|1+2", "|1+2", "|1+2", "*5|1+2"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on runMutationTest#5",function(done){
|
||||||
|
runMutateAttributionTest(8, testPoolWithChars, "Z:a<7=1|4-7$", ["*1|1+2", "*2|1+2", "*3|1+2", "*4|1+2", "*5|1+2"], ["*1+1*5|1+2"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on runMutationTest#6",function(done){
|
||||||
|
runMutateAttributionTest(9, testPoolWithChars, "Z:k<7*0+1*10|2=8|2-8$0", ["*1+1*2+1*3+1|1+1", "*a+1*b+1*c+1|1+1", "*d+1*e+1*f+1|1+1", "*g+1*h+1*i+1|1+1", "?*x+1*y+1*z+1|1+1"], ["*0+1|1+4", "|1+4", "?*x+1*y+1*z+1|1+1"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on ?",function(done){
|
||||||
|
runMutateAttributionTest(10, testPoolWithChars, "Z:6>4=1+1=1+1|1=1+1=1*0+1$abcd", ["|1+3", "|1+3"], ["|1+5", "+2*0+1|1+2"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
|
||||||
|
it("based on ?",function(done){
|
||||||
|
runMutateAttributionTest(11, testPoolWithChars, "Z:s>1|1=4=6|1+1$\n", ["*0|1+4", "*0|1+8", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"], ["*0|1+4", "*0+6|1+1", "*0|1+2", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"]);
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
function runMutateAttributionTest(testId, attribs, cs, alines, outCorrect) {
|
||||||
|
var p = poolOrArray(attribs);
|
||||||
|
var alines2 = Array.prototype.slice.call(alines);
|
||||||
|
// result is never used
|
||||||
|
var result = Changeset.mutateAttributionLines(
|
||||||
|
Changeset.checkRep(cs), alines2, p);
|
||||||
|
assertEqualArrays(outCorrect, alines2);
|
||||||
|
|
||||||
|
|
||||||
|
function removeQuestionMarks(a) {
|
||||||
|
return a.replace(/\?/g, '');
|
||||||
|
}
|
||||||
|
var inMerged = Changeset.joinAttributionLines(alines.map(removeQuestionMarks));
|
||||||
|
var correctMerged = Changeset.joinAttributionLines(outCorrect.map(removeQuestionMarks));
|
||||||
|
var mergedResult = Changeset.applyToAttribution(cs, inMerged, p);
|
||||||
|
assertEqualStrings(correctMerged, mergedResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testPoolWithChars = (function () {
|
||||||
|
var p = new AttributePool();
|
||||||
|
p.putAttrib(['char', 'newline']);
|
||||||
|
for (var i = 1; i < 36; i++) {
|
||||||
|
p.putAttrib(['char', Changeset.numToString(i)]);
|
||||||
|
}
|
||||||
|
p.putAttrib(['char', '']);
|
||||||
|
return p;
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
function poolOrArray(attribs) {
|
||||||
|
if (attribs.getAttrib) {
|
||||||
|
return attribs; // it's already an attrib pool
|
||||||
|
} else {
|
||||||
|
// assume it's an array of attrib strings to be split and added
|
||||||
|
var p = new AttributePool();
|
||||||
|
attribs.forEach(function (kv) {
|
||||||
|
p.putAttrib(kv.split(','));
|
||||||
|
});
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||||
var AttributePool = require("ep_etherpad-lite/static/js/AttributePool");
|
var AttributePool = require("ep_etherpad-lite/static/js/AttributePool");
|
||||||
var helper = require("./helper.js")
|
var helper = require("./helper.js")
|
||||||
|
|
||||||
var assert = helper.assert;
|
var assert = helper.assert;
|
||||||
var literal = helper.literal;
|
var literal = helper.literal;
|
||||||
var assertEqualStrings = helper.assertEqualStrings;
|
var assertEqualStrings = helper.assertEqualStrings;
|
||||||
|
@ -95,110 +94,7 @@ describe("applyToAttribution",function(){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("textLinesMutator",function(){
|
|
||||||
it("hasMore indicates remaining characters",function(done){
|
|
||||||
var lines = ["1\n", "2\n", "3\n", "4\n"];
|
|
||||||
var mu;
|
|
||||||
|
|
||||||
mu = Changeset.textLinesMutator(lines);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.skip(8, 4);
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
mu.close();
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
|
|
||||||
// still 1,2,3,4
|
|
||||||
mu = Changeset.textLinesMutator(lines);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.remove(2, 1);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.skip(2, 1);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.skip(2, 1);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.skip(2, 1);
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
mu.insert("5\n", 1);
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
mu.close();
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
|
|
||||||
// 2,3,4,5 now
|
|
||||||
mu = Changeset.textLinesMutator(lines);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.remove(6, 3);
|
|
||||||
assert(mu.hasMore() + ' == true');
|
|
||||||
mu.remove(2, 1);
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
mu.insert("hello\n", 1);
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
mu.close();
|
|
||||||
assert(mu.hasMore() + ' == false');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function runMutateAttributionTest(testId, attribs, cs, alines, outCorrect) {
|
|
||||||
var p = poolOrArray(attribs);
|
|
||||||
var alines2 = Array.prototype.slice.call(alines);
|
|
||||||
// result is never used
|
|
||||||
var result = Changeset.mutateAttributionLines(
|
|
||||||
Changeset.checkRep(cs), alines2, p);
|
|
||||||
assertEqualArrays(outCorrect, alines2);
|
|
||||||
|
|
||||||
|
|
||||||
function removeQuestionMarks(a) {
|
|
||||||
return a.replace(/\?/g, '');
|
|
||||||
}
|
|
||||||
var inMerged = Changeset.joinAttributionLines(alines.map(removeQuestionMarks));
|
|
||||||
var correctMerged = Changeset.joinAttributionLines(outCorrect.map(removeQuestionMarks));
|
|
||||||
var mergedResult = Changeset.applyToAttribution(cs, inMerged, p);
|
|
||||||
assertEqualStrings(correctMerged, mergedResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
// turn 123\n 456\n 789\n into 123\n 4<b>5</b>6\n 789\n
|
|
||||||
runMutateAttributionTest(1, ["bold,true"], "Z:c>0|1=4=1*0=1$", ["|1+4", "|1+4", "|1+4"], ["|1+4", "+1*0+1|1+2", "|1+4"]);
|
|
||||||
|
|
||||||
// make a document bold
|
|
||||||
runMutateAttributionTest(2, ["bold,true"], "Z:c>0*0|3=c$", ["|1+4", "|1+4", "|1+4"], ["*0|1+4", "*0|1+4", "*0|1+4"]);
|
|
||||||
|
|
||||||
// clear bold on document
|
|
||||||
runMutateAttributionTest(3, ["bold,", "bold,true"], "Z:c>0*0|3=c$", ["*1+1+1*1+1|1+1", "+1*1+1|1+2", "*1+1+1*1+1|1+1"], ["|1+4", "|1+4", "|1+4"]);
|
|
||||||
|
|
||||||
// add a character on line 3 of a document with 5 blank lines, and make sure
|
|
||||||
// the optimization that skips purely-kept lines is working; if any attribution string
|
|
||||||
// with a '?' is parsed it will cause an error.
|
|
||||||
runMutateAttributionTest(4, ['foo,bar', 'line,1', 'line,2', 'line,3', 'line,4', 'line,5'], "Z:5>1|2=2+1$x", ["?*1|1+1", "?*2|1+1", "*3|1+1", "?*4|1+1", "?*5|1+1"], ["?*1|1+1", "?*2|1+1", "+1*3|1+1", "?*4|1+1", "?*5|1+1"]);
|
|
||||||
|
|
||||||
var testPoolWithChars = (function () {
|
|
||||||
var p = new AttributePool();
|
|
||||||
p.putAttrib(['char', 'newline']);
|
|
||||||
for (var i = 1; i < 36; i++) {
|
|
||||||
p.putAttrib(['char', Changeset.numToString(i)]);
|
|
||||||
}
|
|
||||||
p.putAttrib(['char', '']);
|
|
||||||
return p;
|
|
||||||
})();
|
|
||||||
|
|
||||||
// based on runMutationTest#1
|
|
||||||
runMutateAttributionTest(5, testPoolWithChars, "Z:11>7-2*t+1*u+1|2=b|2+a=2*b+1*o+1*t+1*0|1+1*b+1*u+1=3|1-3-6$" + "tucream\npie\nbot\nbu", ["*a+1*p+2*l+1*e+1*0|1+1", "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", "*c+1*a+1*b+2*a+1*g+1*e+1*0|1+1", "*d+1*u+1*f+2*l+1*e+1*0|1+1", "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"], ["*t+1*u+1*p+1*l+1*e+1*0|1+1", "*b+1*a+1*n+1*a+1*n+1*a+1*0|1+1", "|1+6", "|1+4", "*c+1*a+1*b+1*o+1*t+1*0|1+1", "*b+1*u+1*b+2*a+1*0|1+1", "*e+1*g+2*p+1*l+1*a+1*n+1*t+1*0|1+1"]);
|
|
||||||
|
|
||||||
// based on runMutationTest#3
|
|
||||||
runMutateAttributionTest(6, testPoolWithChars, "Z:11<f|1-6|2=f=6|1-1-8$", ["*a|1+6", "*b|1+7", "*c|1+8", "*d|1+7", "*e|1+9"], ["*b|1+7", "*c|1+8", "*d+6*e|1+1"]);
|
|
||||||
|
|
||||||
// based on runMutationTest#4
|
|
||||||
runMutateAttributionTest(7, testPoolWithChars, "Z:3>7=1|4+7$\n2\n3\n4\n", ["*1+1*5|1+2"], ["*1+1|1+1", "|1+2", "|1+2", "|1+2", "*5|1+2"]);
|
|
||||||
|
|
||||||
// based on runMutationTest#5
|
|
||||||
runMutateAttributionTest(8, testPoolWithChars, "Z:a<7=1|4-7$", ["*1|1+2", "*2|1+2", "*3|1+2", "*4|1+2", "*5|1+2"], ["*1+1*5|1+2"]);
|
|
||||||
|
|
||||||
// based on runMutationTest#6
|
|
||||||
runMutateAttributionTest(9, testPoolWithChars, "Z:k<7*0+1*10|2=8|2-8$0", ["*1+1*2+1*3+1|1+1", "*a+1*b+1*c+1|1+1", "*d+1*e+1*f+1|1+1", "*g+1*h+1*i+1|1+1", "?*x+1*y+1*z+1|1+1"], ["*0+1|1+4", "|1+4", "?*x+1*y+1*z+1|1+1"]);
|
|
||||||
|
|
||||||
runMutateAttributionTest(10, testPoolWithChars, "Z:6>4=1+1=1+1|1=1+1=1*0+1$abcd", ["|1+3", "|1+3"], ["|1+5", "+2*0+1|1+2"]);
|
|
||||||
|
|
||||||
|
|
||||||
runMutateAttributionTest(11, testPoolWithChars, "Z:s>1|1=4=6|1+1$\n", ["*0|1+4", "*0|1+8", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"], ["*0|1+4", "*0+6|1+1", "*0|1+2", "*0+5|1+1", "*0|1+1", "*0|1+5", "*0|1+1", "*0|1+1", "*0|1+1", "|1+1"]);
|
|
||||||
|
|
||||||
function randomInlineString(len, rand) {
|
function randomInlineString(len, rand) {
|
||||||
var assem = Changeset.stringAssembler();
|
var assem = Changeset.stringAssembler();
|
||||||
|
|
|
@ -2,6 +2,7 @@ var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||||
var helper = require("./helper.js")
|
var helper = require("./helper.js")
|
||||||
var assertEqualStrings = helper.assertEqualStrings;
|
var assertEqualStrings = helper.assertEqualStrings;
|
||||||
var assertEqualArrays = helper.assertEqualArrays;
|
var assertEqualArrays = helper.assertEqualArrays;
|
||||||
|
var assert = helper.assert;
|
||||||
|
|
||||||
describe("text line mutations",function(){
|
describe("text line mutations",function(){
|
||||||
it("applies mutations to an array of lines #1",function(done){
|
it("applies mutations to an array of lines #1",function(done){
|
||||||
|
@ -179,6 +180,49 @@ describe("text line mutations",function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("textLinesMutator",function(){
|
||||||
|
it("hasMore indicates remaining characters",function(done){
|
||||||
|
var lines = ["1\n", "2\n", "3\n", "4\n"];
|
||||||
|
var mu;
|
||||||
|
|
||||||
|
mu = Changeset.textLinesMutator(lines);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.skip(8, 4);
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
mu.close();
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
|
||||||
|
// still 1,2,3,4
|
||||||
|
mu = Changeset.textLinesMutator(lines);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.remove(2, 1);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.skip(2, 1);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.skip(2, 1);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.skip(2, 1);
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
mu.insert("5\n", 1);
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
mu.close();
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
|
||||||
|
// 2,3,4,5 now
|
||||||
|
mu = Changeset.textLinesMutator(lines);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.remove(6, 3);
|
||||||
|
assert(mu.hasMore() + ' == true');
|
||||||
|
mu.remove(2, 1);
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
mu.insert("hello\n", 1);
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
mu.close();
|
||||||
|
assert(mu.hasMore() + ' == false');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function runMutationTest(origLines, muts) {
|
function runMutationTest(origLines, muts) {
|
||||||
var lines1 = origLines.slice();
|
var lines1 = origLines.slice();
|
||||||
var mu = Changeset.textLinesMutator(lines1);
|
var mu = Changeset.textLinesMutator(lines1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue